mirror of
https://github.com/foomo/contentserver.git
synced 2025-10-16 12:25:44 +00:00
added public interface to load a node as an object
This commit is contained in:
parent
d31f10ef33
commit
74cee00dc0
@ -31,7 +31,7 @@ func (repo *Repo) ResolveContent(state string, URI string) (resolved bool, resol
|
||||
parts := strings.Split(URI, content.PATH_SEPARATOR)
|
||||
log.Debug("repo.ResolveContent: " + URI)
|
||||
for i := len(parts); i > -1; i-- {
|
||||
testURI := strings.Join(parts[0:i], content.PATH_SEPARATOR)
|
||||
testURI := strings.Join(parts[0:i], content.PATH_SEPARATOR)
|
||||
testURIKey := uriKeyForState(state, testURI)
|
||||
log.Debug(" testing" + testURIKey)
|
||||
if repoNode, ok := repo.URIDirectory[testURIKey]; ok {
|
||||
@ -175,7 +175,7 @@ func (repo *Repo) GetRepo() *content.RepoNode {
|
||||
}
|
||||
|
||||
func uriKeyForState(state string, uri string) string {
|
||||
return state + "-" + uri;
|
||||
return state + "-" + uri
|
||||
}
|
||||
|
||||
func builDirectory(dirNode *content.RepoNode, directory map[string]*content.RepoNode, uRIDirectory map[string]*content.RepoNode) {
|
||||
@ -210,6 +210,23 @@ func wireAliases(directory map[string]*content.RepoNode) {
|
||||
}
|
||||
}
|
||||
|
||||
func (repo *Repo) Load(newNode *content.RepoNode) {
|
||||
newNode.WireParents()
|
||||
|
||||
newDirectory := make(map[string]*content.RepoNode)
|
||||
newURIDirectory := make(map[string]*content.RepoNode)
|
||||
|
||||
builDirectory(newNode, newDirectory, newURIDirectory)
|
||||
wireAliases(newDirectory)
|
||||
|
||||
// some more validation anyone?
|
||||
// invalid destination ids
|
||||
|
||||
repo.Node = newNode
|
||||
repo.Directory = newDirectory
|
||||
repo.URIDirectory = newURIDirectory
|
||||
}
|
||||
|
||||
func (repo *Repo) Update() *responses.Update {
|
||||
updateResponse := responses.NewUpdate()
|
||||
|
||||
@ -221,22 +238,7 @@ func (repo *Repo) Update() *responses.Update {
|
||||
startTimeOwn := time.Now()
|
||||
updateResponse.Success = ok
|
||||
if ok {
|
||||
|
||||
newNode.WireParents()
|
||||
|
||||
newDirectory := make(map[string]*content.RepoNode)
|
||||
newURIDirectory := make(map[string]*content.RepoNode)
|
||||
|
||||
builDirectory(newNode, newDirectory, newURIDirectory)
|
||||
wireAliases(newDirectory)
|
||||
|
||||
// some more validation anyone?
|
||||
// invalid destination ids
|
||||
|
||||
repo.Node = newNode
|
||||
repo.Directory = newDirectory
|
||||
repo.URIDirectory = newURIDirectory
|
||||
|
||||
repo.Load(newNode)
|
||||
updateResponse.Stats.NumberOfNodes = len(repo.Directory)
|
||||
updateResponse.Stats.NumberOfURIs = len(repo.URIDirectory)
|
||||
} else {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user