Skip to content

Commit

Permalink
Merge pull request #312 from europeana/EA-3643-zoho-country-improve
Browse files Browse the repository at this point in the history
org europeana role xml serialization with rdf:resource
  • Loading branch information
gsergiu authored Mar 6, 2024
2 parents bf7372c + cc2d9fe commit 28a5e2c
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public String getAbout() {
public void setAbout(String about) {
this.about = about;
}

public XmlWebResourceWrapper getDepiction() {
return depiction;
}
Expand Down Expand Up @@ -130,4 +130,5 @@ public boolean hasCoref(String uri) {

return getSameReferenceLinks().stream().anyMatch(e -> uri.equals(e.getResource()));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package eu.europeana.entitymanagement.web.xml.model;

import static eu.europeana.entitymanagement.web.xml.model.XmlConstants.IN_SCHEME;
import static eu.europeana.entitymanagement.web.xml.model.XmlConstants.NAMESPACE_EDM;
import static eu.europeana.entitymanagement.web.xml.model.XmlConstants.NAMESPACE_RDF;
import static eu.europeana.entitymanagement.web.xml.model.XmlConstants.NAMESPACE_SKOS;
import static eu.europeana.entitymanagement.web.xml.model.XmlConstants.PREF_LABEL;
import static eu.europeana.entitymanagement.web.xml.model.XmlConstants.RESOURCE;
import static eu.europeana.entitymanagement.web.xml.model.XmlConstants.XML_CONCEPT;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import eu.europeana.entitymanagement.definitions.model.Vocabulary;

@XmlRootElement(namespace = NAMESPACE_EDM, name = XML_CONCEPT)
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(
propOrder = {
RESOURCE,
PREF_LABEL,
IN_SCHEME
})
public class XmlEdmEuropeanaRole {

@XmlAttribute(namespace = NAMESPACE_RDF, name = XmlConstants.RESOURCE)
private String resource;

@XmlElement(namespace = XmlConstants.NAMESPACE_SKOS, name = PREF_LABEL)
private List<LabelledResource> prefLabel = new ArrayList<>();

@XmlElement(namespace = NAMESPACE_SKOS, name = IN_SCHEME)
private List<LabelledResource> inScheme;

public XmlEdmEuropeanaRole(Vocabulary vocab) {
this.resource=vocab.getId();
this.prefLabel= RdfXmlUtils.convertMapToXmlMultilingualString(vocab.getPrefLabel());
this.inScheme = RdfXmlUtils.convertToRdfResource(vocab.getInScheme());
}

public XmlEdmEuropeanaRole() {
}

public String getResource() {
return resource;
}

public void setResource(String resource) {
this.resource = resource;
}

public List<LabelledResource> getPrefLabel() {
return this.prefLabel;
}

public void setPrefLabel(List<LabelledResource> prefLabel) {
this.prefLabel=prefLabel;
}

public List<LabelledResource> getInScheme() {
return this.inScheme;
}

public void setInScheme(List<LabelledResource> inScheme) {
this.inScheme=inScheme;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public class XmlOrganizationImpl extends XmlBaseEntityImpl<Organization> {
private XmlWebResourceWrapper logo;

@XmlElement(namespace = NAMESPACE_EDM, name = XML_EUROPEANA_ROLE)
private List<XmlConceptImpl> europeanaRole = new ArrayList<>();
private List<XmlEdmEuropeanaRole> europeanaRole = new ArrayList<>();

@XmlElement(namespace = NAMESPACE_EDM, name = XML_COUNTRY)
private XmlEdmCountry country;
Expand Down Expand Up @@ -110,19 +110,16 @@ public XmlOrganizationImpl(Organization organization) {
//set the europeanaRole
List<Vocabulary> orgRole=organization.getEuropeanaRole();
if(orgRole!=null && !orgRole.isEmpty()) {
List<XmlConceptImpl> orgXmlRole= new ArrayList<>();
List<XmlEdmEuropeanaRole> orgXmlRole= new ArrayList<>();
for(Vocabulary vocab : orgRole) {
XmlConceptImpl xmlConcept = new XmlConceptImpl();
xmlConcept.setAbout(vocab.getId());
xmlConcept.setPrefLabel(RdfXmlUtils.convertMapToXmlMultilingualString(vocab.getPrefLabel()));
xmlConcept.setInScheme(RdfXmlUtils.convertToRdfResource(vocab.getInScheme()));
orgXmlRole.add(xmlConcept);
XmlEdmEuropeanaRole xmlRole = new XmlEdmEuropeanaRole(vocab);
orgXmlRole.add(xmlRole);
}
this.europeanaRole=orgXmlRole;
}

if(organization.getCountry() != null) {
this.country = new XmlEdmCountry(organization.getCountry());
this.country=new XmlEdmCountry(organization.getCountry());
}

if (organization.getHomepage() != null) {
Expand Down Expand Up @@ -153,13 +150,12 @@ public Organization toEntityModel() throws EntityModelCreationException {
entity.setLogo(XmlWebResourceWrapper.toWebResource(getLogo()));
//set europeanaRole id (external dereferencers deliver only the ids, not transitive data)
if(getEuropeanaRole()!=null && !getEuropeanaRole().isEmpty()) {
List<String> roleIds = getEuropeanaRole().stream().map(e -> e.getAbout()).toList();
List<String> roleIds = getEuropeanaRole().stream().map(e -> e.getResource()).toList();
entity.setEuropeanaRoleIds(roleIds);
}

//set country id (external dereferencers deliver only the ids, not transitive data)
if(getCountry() != null) {
//we need to extract the countryID as well (xml about holds the entityId)
entity.setCountryId(getCountry().getResource());
}

Expand Down Expand Up @@ -194,7 +190,7 @@ public XmlWebResourceWrapper getLogo() {
return logo;
}

public List<XmlConceptImpl> getEuropeanaRole() {
public List<XmlEdmEuropeanaRole> getEuropeanaRole() {
return europeanaRole;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,9 @@ public void retrieveOrganizationXmlExternalShouldBeSuccessful() throws Exception
.andExpect(
xpath(entityBaseXpath + "/skos:prefLabel", xmlNamespaces).nodeCount(greaterThan(0)))
.andExpect(xpath(entityBaseXpath + "/edm:country/@rdf:resource", xmlNamespaces).exists())
.andExpect(xpath(entityBaseXpath + "/edm:country/skos:prefLabel", xmlNamespaces).doesNotExist());
.andExpect(xpath(entityBaseXpath + "/edm:country/skos:prefLabel", xmlNamespaces).doesNotExist())
.andExpect(xpath(entityBaseXpath + "/edm:europeanaRole/@rdf:resource", xmlNamespaces).exists())
.andExpect(xpath(entityBaseXpath + "/edm:europeanaRole/skos:prefLabel", xmlNamespaces).doesNotExist());
}

@Test
Expand Down

0 comments on commit 28a5e2c

Please sign in to comment.