Skip to content

Commit

Permalink
address code quality issues
Browse files Browse the repository at this point in the history
  • Loading branch information
GordeaS authored and GordeaS committed Mar 28, 2024
1 parent 6cbd2ae commit e3cb59d
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package eu.europeana.entitymanagement.definitions;

// Collection field names
/**
* Collection of field names for entity record class
*/
public class EntityRecordFields {

private EntityRecordFields() {
// private constructor to prevent instantiation
}

public static final String CLASS = "objectClass";
public static final String ENTITY = "entity";
public static final String ENTITY_ID = "entityId";
Expand All @@ -17,4 +15,9 @@ private EntityRecordFields() {
public static final String ENTITY_AGGREGATED_VIA = "entity.aggregatedVia";
public static final String ENTITY_EXACT_MATCH = "entity.exactMatch";
public static final String ENTITY_TYPE = "entity.type";

private EntityRecordFields() {
// private constructor to prevent instantiation
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -97,25 +97,45 @@ public Organization() {

public Organization(Organization copy) {
super(copy);
if (copy.getDescription() != null) this.description = new HashMap<>(copy.getDescription());
if (copy.getAcronym() != null) this.acronym = new HashMap<>(copy.getAcronym());
if (copy.getDescription() != null) {
this.description = new HashMap<>(copy.getDescription());
}
if (copy.getAcronym() != null) {
this.acronym = new HashMap<>(copy.getAcronym());
}
this.logo = copy.getLogo();
this.homepage = copy.getHomepage();
if (copy.getPhone() != null) this.phone = new ArrayList<>(copy.getPhone());
if (copy.getMbox() != null) this.mbox = new ArrayList<>(copy.getMbox());
if (copy.getPhone() != null) {
this.phone = new ArrayList<>(copy.getPhone());
}
if (copy.getMbox() != null) {
this.mbox = new ArrayList<>(copy.getMbox());
}
//because the europeanaRoleRef is a reference to the object we keep it the same (therefore also for europeanaRole)
this.europeanaRoleRefs = copy.getEuropeanaRoleRefs();
if(copy.getEuropeanaRoleIds()!=null) this.europeanaRoleIds=new ArrayList<>(copy.getEuropeanaRoleIds());
if(copy.getEuropeanaRoleIds()!=null) {
this.europeanaRoleIds=new ArrayList<>(copy.getEuropeanaRoleIds());
}
//because the countryRef is a reference to the object we keep it the same (therefore also for country)
this.countryRef=copy.getCountryRef();
this.countryId = copy.getCountryId();
this.country = copy.getCountry();

if (copy.getAddress() != null) this.hasAddress = new Address(copy.getAddress());
if (copy.sameAs != null) this.sameAs = (new ArrayList<>(copy.sameAs));
if (copy.getLanguage() != null) this.language = (new ArrayList<>(copy.getLanguage()));
if (copy.getAggregatesFrom() != null) this.aggregatesFrom = (new ArrayList<>(copy.getAggregatesFrom()));
if (copy.getAggregatedVia() != null) this.aggregatedVia = (new ArrayList<>(copy.getAggregatedVia()));
if (copy.getAddress() != null) {
this.hasAddress = new Address(copy.getAddress());
}
if (copy.sameAs != null) {
this.sameAs = (new ArrayList<>(copy.sameAs));
}
if (copy.getLanguage() != null) {
this.language = (new ArrayList<>(copy.getLanguage()));
}
if (copy.getAggregatesFrom() != null) {
this.aggregatesFrom = (new ArrayList<>(copy.getAggregatesFrom()));
}
if (copy.getAggregatedVia() != null) {
this.aggregatedVia = (new ArrayList<>(copy.getAggregatedVia()));
}
}

@JsonGetter(DESCRIPTION)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import static eu.europeana.entitymanagement.web.xml.model.XmlConstants.NAMESPACE_DC;
import static eu.europeana.entitymanagement.web.xml.model.XmlConstants.NAMESPACE_EDM;
import static eu.europeana.entitymanagement.web.xml.model.XmlConstants.NAMESPACE_FOAF;
import static eu.europeana.entitymanagement.web.xml.model.XmlConstants.NAMESPACE_OWL;
import static eu.europeana.entitymanagement.web.xml.model.XmlConstants.NAMESPACE_VCARD;
import static eu.europeana.entitymanagement.web.xml.model.XmlConstants.PREF_LABEL;
import static eu.europeana.entitymanagement.web.xml.model.XmlConstants.XML_ACRONYM;
Expand Down Expand Up @@ -67,13 +68,13 @@
})
public class XmlOrganizationImpl extends XmlBaseEntityImpl<Organization> {

@XmlElement(namespace = XmlConstants.NAMESPACE_OWL, name = XmlConstants.XML_SAME_AS)
@XmlElement(namespace = NAMESPACE_OWL, name = XML_SAME_AS)
private List<LabelledResource> sameAs = new ArrayList<>();

@XmlElement(namespace = XmlConstants.NAMESPACE_EDM, name = XmlConstants.XML_AGGREGATES_FROM)
@XmlElement(namespace = NAMESPACE_EDM, name = XML_AGGREGATES_FROM)
private List<LabelledResource> aggregatesFrom = new ArrayList<>();

@XmlElement(namespace = XmlConstants.NAMESPACE_EDM, name = XmlConstants.XML_AGGREGATED_VIA)
@XmlElement(namespace = NAMESPACE_EDM, name = XML_AGGREGATED_VIA)
private List<LabelledResource> aggregatedVia = new ArrayList<>();

@XmlElement(namespace = NAMESPACE_EDM, name = XML_ACRONYM)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ public List<EntityRecord> findEntitiesByCoreference(
return findEntityRecords(filters.toArray(Filter[]::new), true, null);
}

/**
* Returns a list of organizations from which the given aggregator identified by the entityId aggregates from
* @param entityId the id of the organization (aggregator)
* @return the list of organization ids from which the provided organization aggregated from
*/
public List<String> findAggregatesFrom(String entityId) {
List<EntityRecord> entityRecords =
getDataStore()
Expand All @@ -201,9 +206,14 @@ public List<String> findAggregatesFrom(String entityId) {
.iterator(new FindOptions().projection().include(ENTITY_ID))
.toList();

return entityRecords.stream().map(entityRecord -> entityRecord.getEntityId()).toList();
return entityRecords.stream().map(EntityRecord::getEntityId).toList();
}

/**
* Find entities by their ids or coreferences
* @param uris entities to search for
* @return list of records retrieved from database
*/
public List<EntityRecord> findByEntityIdsOrCoreference(List<String> uris) {
// Get all EntityRecords that have the given uris as their entityId or in the sameAs/exactMatch field
List<Filter> filters = new ArrayList<>();
Expand All @@ -215,6 +225,11 @@ public List<EntityRecord> findByEntityIdsOrCoreference(List<String> uris) {
}


/**
* save a list of entity records
* @param entityRecords records to be saved into the database
* @return the records retrieved after saving
*/
public List<EntityRecord> saveBulk(List<EntityRecord> entityRecords) {
return getDataStore().save(entityRecords);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang.StringUtils;
Expand Down

0 comments on commit e3cb59d

Please sign in to comment.