func mapToResponseFormat(ann *annotation) { ann.Thing.ID = mapper.IDURL(ann.Thing.ID) // We expect only ONE provenance - provenance value is considered valid even if the AgentRole is not specified. See: v1 - isClassifiedBy for idx := range ann.Provenances { if ann.Provenances[idx].AgentRole != "" { ann.Provenances[idx].AgentRole = mapper.IDURL(ann.Provenances[idx].AgentRole) } } }
// Read - reads a content given a UUID func (pcd service) Read(uuid string) (interface{}, bool, error) { results := []struct { content }{} query := &neoism.CypherQuery{ Statement: `MATCH (n:Content {uuid:{uuid}}) OPTIONAL MATCH (n)-[rel:IS_CLASSIFIED_BY]->(b:Thing) WHERE rel.lifecycle IS NULL OR rel.lifecycle = "content" WITH n,collect({id:b.uuid}) as brands return n.uuid as uuid, n.title as title, n.publishedDate as publishedDate, brands`, Parameters: map[string]interface{}{ "uuid": uuid, }, Result: &results, } err := pcd.conn.CypherBatch([]*neoism.CypherQuery{query}) if err != nil { return content{}, false, err } if len(results) == 0 { return content{}, false, nil } result := results[0] if len(result.Brands) == 1 && (result.Brands[0].Id == "") { result.Brands = []brand{} } var brands []brand for _, brand := range result.Brands { brand.Id = mapper.IDURL(brand.Id) brands = append(brands, brand) } contentItem := content{ UUID: result.UUID, Title: result.Title, PublishedDate: result.PublishedDate, Brands: brands, } return contentItem, true, nil }
func neoReadStructToOrganisation(neo neoReadStruct, env string) Organisation { //TODO find out why we only get two memberships here compared to 17 off PROD graphDB... also, performance of e.g. Barclays public := Organisation{} public.Thing = &Thing{} public.ID = mapper.IDURL(neo.O.ID) public.APIURL = mapper.APIURL(neo.O.ID, neo.O.Types, env) public.Types = mapper.TypeURIs(neo.O.Types) public.PrefLabel = neo.O.PrefLabel if len(neo.O.Labels) > 0 { public.Labels = &neo.O.Labels } if neo.Lei.LegalEntityIdentifier != "" { public.LegalEntityIdentifier = neo.Lei.LegalEntityIdentifier } if neo.Ind.ID != "" { public.IndustryClassification = &IndustryClassification{} public.IndustryClassification.Thing = &Thing{} public.IndustryClassification.ID = mapper.IDURL(neo.Ind.ID) public.IndustryClassification.APIURL = mapper.APIURL(neo.Ind.ID, neo.Ind.Types, env) public.IndustryClassification.PrefLabel = neo.Ind.PrefLabel } if neo.Fi.ID != "" { public.FinancialInstrument = &FinancialInstrument{} public.FinancialInstrument.Thing = &Thing{} public.FinancialInstrument.ID = mapper.IDURL(neo.Fi.ID) public.FinancialInstrument.APIURL = mapper.APIURL(neo.Fi.ID, neo.Fi.Types, env) public.FinancialInstrument.Types = mapper.TypeURIs(neo.Fi.Types) public.FinancialInstrument.PrefLabel = neo.Fi.PrefLabel public.FinancialInstrument.Figi = neo.Fi.FIGI } if neo.Parent.ID != "" { public.Parent = &Parent{} public.Parent.Thing = &Thing{} public.Parent.ID = mapper.IDURL(neo.Parent.ID) public.Parent.APIURL = mapper.APIURL(neo.Parent.ID, neo.Parent.Types, env) public.Parent.Types = mapper.TypeURIs(neo.Parent.Types) public.Parent.PrefLabel = neo.Parent.PrefLabel } if len(neo.Sub) == 1 && neo.Sub[0].ID == "" { public.Subsidiaries = make([]Subsidiary, 0, 0) } else { public.Subsidiaries = make([]Subsidiary, len(neo.Sub)) for idx, neoSub := range neo.Sub { subsidiary := Subsidiary{} subsidiary.Thing = &Thing{} subsidiary.ID = mapper.IDURL(neoSub.ID) subsidiary.APIURL = mapper.APIURL(neoSub.ID, neoSub.Types, env) subsidiary.Types = mapper.TypeURIs(neoSub.Types) subsidiary.PrefLabel = neoSub.PrefLabel public.Subsidiaries[idx] = subsidiary } } if len(neo.PM) == 1 && (neo.PM[0].M.ID == "") { public.Memberships = make([]Membership, 0, 0) } else { public.Memberships = make([]Membership, len(neo.PM)) for mIdx, neoMem := range neo.PM { membership := Membership{} membership.Title = neoMem.M.PrefLabel membership.Person = Person{} membership.Person.Thing = &Thing{} membership.Person.ID = mapper.IDURL(neoMem.P.ID) membership.Person.APIURL = mapper.APIURL(neoMem.P.ID, neoMem.P.Types, env) membership.Person.Types = mapper.TypeURIs(neoMem.P.Types) membership.Person.PrefLabel = neoMem.P.PrefLabel if a, b := changeEvent(neoMem.M.ChangeEvents); a == true { membership.ChangeEvents = b } public.Memberships[mIdx] = membership } } log.Debugf("neoReadStructToOrganisation neo: %+v result: %+v", neo, public) return public }