Skip to content

Commit

Permalink
address code quality issues #EA-4028
Browse files Browse the repository at this point in the history
  • Loading branch information
gsergiu committed Jan 31, 2025
1 parent 2e12667 commit 7622ef4
Show file tree
Hide file tree
Showing 20 changed files with 314 additions and 287 deletions.
Original file line number Diff line number Diff line change
@@ -1,33 +1,6 @@
package eu.europeana.entitymanagement.definitions.model;

import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.ACRONYM;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.AGGREGATED_VIA;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.AGGREGATES_FROM;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.ALT_LABEL;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.CONTEXT;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.COUNTRY;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.DEPICTION;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.DESCRIPTION;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.EUROPEANA_ROLE;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.FOAF_HOMEPAGE;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.FOAF_LOGO;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.FOAF_MBOX;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.FOAF_PHONE;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.GEOGRAPHIC_SCOPE;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.HAS_ADDRESS;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.HERITAGE_DOMAIN;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.HIDDEN_LABEL;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.ID;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.IDENTIFIER;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.IS_AGGREGATED_BY;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.LANGUAGE;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.PREF_LABEL;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.PROVIDES_AUDIENCE_ENGAGEMENT_ACTIVITY;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.PROVIDES_SUPPORT_FOR_BUILDING_ACTIVITY;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.PROVIDES_SUPPORT_FOR_DATA_ACTIVITY;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.PROVIDES_SUPPORT_FOR_MEDIA_TYPE;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.SAME_AS;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.TYPE;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.*;
import java.util.ArrayList;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonGetter;
Expand Down Expand Up @@ -67,6 +40,9 @@
PROVIDES_SUPPORT_FOR_BUILDING_ACTIVITY,
PROVIDES_AUDIENCE_ENGAGEMENT_ACTIVITY
})
/**
* Class implementing aggregator extension for organizations
*/
public class Aggregator extends Organization {
protected String mbox;
protected String geographicScope;
Expand All @@ -75,12 +51,19 @@ public class Aggregator extends Organization {
protected List<String> providesSupportForDataActivity;
protected List<String> providesCapacityBuildingActivity;
protected List<String> providesAudienceEngagementActivity;


/**
* Public constructor
*/
public Aggregator() {
super();
type=EntityTypes.Aggregator.getEntityType();
}

/**
* Public constructor creating a copy of the provided aggregator
* @param copy
*/
public Aggregator(Aggregator copy) {
super(copy);
this.type=copy.getType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import org.apache.commons.collections.MapUtils;

/**
* Utils for converting the representation of data to solr fields
*/
public class SolrGeneralUtils {

/**
* Hide default constructor
*/
private SolrGeneralUtils() {

}

/**
* This method adds prefixes to the fields in format Map<String, List<String>> languageMap e.g.
* "skos_prefLabel"
Expand All @@ -23,13 +32,11 @@ public static Map<String, List<String>> normalizeStringListMapByAddingPrefix(
return new HashMap<>();
}
Map<String, List<String>> res;
if (!languageMap.keySet().iterator().next().contains(fieldNamePrefix)) {
res =
languageMap.entrySet().stream()
.collect(
Collectors.toMap(entry -> fieldNamePrefix + entry.getKey(), Map.Entry::getValue));
} else {
if (languageMap.keySet().iterator().next().contains(fieldNamePrefix)) {
res = languageMap;
} else {
res = languageMap.entrySet().stream().collect(
Collectors.toMap(entry -> fieldNamePrefix + entry.getKey(), Map.Entry::getValue));
}
return res;
}
Expand All @@ -42,21 +49,19 @@ public static Map<String, List<String>> normalizeStringListMapByAddingPrefix(
* @param languageMap e.g. prefLabel
* @return normalized content in format Map<String, String>
*/
public static Map<String, String> normalizeStringMapByAddingPrefix(
String fieldNamePrefix, Map<String, String> languageMap) {
public static Map<String, String> normalizeStringMapByAddingPrefix(String fieldNamePrefix,
Map<String, String> languageMap) {

if (MapUtils.isEmpty(languageMap)) {
return new HashMap<>();
}

Map<String, String> res;
if (!languageMap.keySet().iterator().next().contains(fieldNamePrefix)) {
res =
languageMap.entrySet().stream()
.collect(
Collectors.toMap(entry -> fieldNamePrefix + entry.getKey(), Map.Entry::getValue));
} else {
if (languageMap.keySet().iterator().next().contains(fieldNamePrefix)) {
res = languageMap;
} else {
res = languageMap.entrySet().stream().collect(
Collectors.toMap(entry -> fieldNamePrefix + entry.getKey(), Map.Entry::getValue));
}
return res;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
/**
* Constants for solr field names
*/
public interface AggregatorSolrFields {
public abstract class AggregatorSolrFields {

String MBOX = "mbox";
String GEOGRAPHIC_SCOPE = "geographicScope";
String HERITAGE_DOMAIN = "heritageDomain";
String PROVIDES_SUPPORT_FOR_MEDIA_TYPE = "providesSupportForMediaType";
String PROVIDES_SUPPORT_FOR_DATA_ACTIVITY = "providesSupportForDataActivity";
String PROVIDES_CAPACITY_BUILDING_ACTIVITY = "providesCapacityBuildingActivity";
String AUDIENCE_ENGAGEMENT_ACTIVITY = "providesAudienceEngagementActivity";
String PARENT_TYPE = "parentType";
public static final String MBOX = "mbox";
public static final String GEOGRAPHIC_SCOPE = "geographicScope";
public static final String HERITAGE_DOMAIN = "heritageDomain";
public static final String PROVIDES_SUPPORT_FOR_MEDIA_TYPE = "providesSupportForMediaType";
public static final String PROVIDES_SUPPORT_FOR_DATA_ACTIVITY = "providesSupportForDataActivity";
public static final String PROVIDES_CAPACITY_BUILDING_ACTIVITY = "providesCapacityBuildingActivity";
public static final String AUDIENCE_ENGAGEMENT_ACTIVITY = "providesAudienceEngagementActivity";
public static final String PARENT_TYPE = "parentType";
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*
* @author StevaneticS
*/
@SuppressWarnings("java:S115")
public enum EntityFieldsTypes {

// General fields
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,20 @@ public enum EntityTypes implements EntityKeyword {
private String httpUri;
private String parentType;

public String getEntityType() {
return entityType;
}

public String getUrlPath() {
return urlPath;
}

EntityTypes(String entityType, String urlPath, String uri, String parentType) {
this.entityType = entityType;
this.urlPath = urlPath;
this.httpUri = uri;
this.parentType = parentType;
}

public String getEntityType() {
return entityType;
}

public String getUrlPath() {
return urlPath;
}
/**
* Check if an array of EntityTypes contains an Entity type
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package eu.europeana.entitymanagement.vocabulary;

public interface WebEntityConstants extends WebEntityFields {
public abstract class WebEntityConstants extends WebEntityFields {

public static final String PATH_PARAM_TYPE = "type";
public static final String PATH_PARAM_NAMESPACE = "namespace";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package eu.europeana.entitymanagement.vocabulary;

public interface WebEntityFields {
public abstract class WebEntityFields {

// LD fields
public static final String CONTEXT = "@context";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
package eu.europeana.entitymanagement.web.xml.model;

import static eu.europeana.entitymanagement.web.xml.model.XmlConstants.*;

import eu.europeana.entitymanagement.definitions.model.Aggregation;
import static eu.europeana.entitymanagement.web.xml.model.XmlConstants.ABOUT;
import static eu.europeana.entitymanagement.web.xml.model.XmlConstants.NAMESPACE_DC_TERMS;
import static eu.europeana.entitymanagement.web.xml.model.XmlConstants.NAMESPACE_ORE;
import static eu.europeana.entitymanagement.web.xml.model.XmlConstants.NAMESPACE_RDF;
import static eu.europeana.entitymanagement.web.xml.model.XmlConstants.XML_AGGREGATES;
import static eu.europeana.entitymanagement.web.xml.model.XmlConstants.XML_CREATED;
import static eu.europeana.entitymanagement.web.xml.model.XmlConstants.XML_MODIFIED;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import eu.europeana.entitymanagement.definitions.model.Aggregation;

/**
* class for xml serialization of aggregations
*/
public class XmlAggregationImpl {

@XmlAttribute(namespace = NAMESPACE_RDF, name = ABOUT)
Expand All @@ -23,6 +31,10 @@ public class XmlAggregationImpl {
@XmlElement(namespace = NAMESPACE_ORE, name = XML_AGGREGATES)
private List<LabelledResource> aggregates;

/**
* Build object for xml serialization from POJO
* @param aggregation the aggregator object to serialize
*/
public XmlAggregationImpl(Aggregation aggregation) {
this.id = aggregation.getId();
this.created = aggregation.getCreated();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@

@XmlRootElement(namespace = NAMESPACE_EDM, name = XML_AGGREGATOR)
@XmlAccessorType(XmlAccessType.FIELD)
/**
* class for xml serialization of Aggregators
*/
@SuppressWarnings("java:S2384")
public class XmlAggregatorImpl extends XmlOrganizationImpl {

@XmlElement(namespace = NAMESPACE_FOAF, name = XML_MBOX)
Expand All @@ -45,27 +49,35 @@ public class XmlAggregatorImpl extends XmlOrganizationImpl {
@XmlElement(namespace = NAMESPACE_EDM, name = XML_PROVIDES_AUDIENCE_ENGAGEMENT_ACTIVITY)
private List<String> providesAudienceEngagementActivity;

/**
* Constructor to convert the POJO for XML serialization
* @param aggregator
*/
public XmlAggregatorImpl(Aggregator aggregator) {
super(aggregator);
this.mbox=aggregator.getMbox();
this.geographicScope=aggregator.getGeographicScope();
if (aggregator.getHeritageDomain() != null) {
this.heritageDomain = new ArrayList<String>(aggregator.getHeritageDomain());
this.heritageDomain = new ArrayList<>(aggregator.getHeritageDomain());
}
if (aggregator.getProvidesSupportForMediaType() != null) {
this.providesSupportForMediaType = new ArrayList<String>(aggregator.getProvidesSupportForMediaType());
this.providesSupportForMediaType = new ArrayList<>(aggregator.getProvidesSupportForMediaType());
}
if (aggregator.getProvidesSupportForDataActivity() != null) {
this.providesSupportForDataActivity = new ArrayList<String>(aggregator.getProvidesSupportForDataActivity());
this.providesSupportForDataActivity = new ArrayList<>(aggregator.getProvidesSupportForDataActivity());
}
if (aggregator.getProvidesCapacityBuildingActivity() != null) {
this.providesCapacityBuildingActivity = new ArrayList<String>(aggregator.getProvidesCapacityBuildingActivity());
this.providesCapacityBuildingActivity = new ArrayList<>(aggregator.getProvidesCapacityBuildingActivity());
}
if (aggregator.getProvidesAudienceEngagementActivity() != null) {
this.providesAudienceEngagementActivity = new ArrayList<String>(aggregator.getProvidesAudienceEngagementActivity());
this.providesAudienceEngagementActivity = new ArrayList<>(aggregator.getProvidesAudienceEngagementActivity());
}
}

public XmlAggregatorImpl() {
// default constructor
}

@Override
public Aggregator toEntityModel() throws EntityModelCreationException {
super.toEntityModel();
Expand All @@ -77,10 +89,7 @@ public Aggregator toEntityModel() throws EntityModelCreationException {
((Aggregator)entity).setProvidesAudienceEngagementActivity(getProvidesAudienceEngagementActivity());
return ((Aggregator)entity);
}

public XmlAggregatorImpl() {
// default constructor
}


@Override
protected EntityTypes getTypeEnum() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
public class VocabularyRepository {

@Autowired
@Qualifier(AppConfigConstants.BEAN_EM_DATA_STORE)
Datastore datastore;

private static final String ID = "id";

private List<Vocabulary> europeanaRoles;

public VocabularyRepository(@Qualifier(AppConfigConstants.BEAN_EM_DATA_STORE) Datastore datastore) {
this.datastore = datastore;
}

public List<Vocabulary> getEuropeanaRoles() {
synchronized(this) {
if(europeanaRoles==null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package eu.europeana.entitymanagement.solr;

import static eu.europeana.entitymanagement.common.vocabulary.AppConfigConstants.BEAN_SOLR_ENTITY_SUGGESTER_FILTER;
import static eu.europeana.entitymanagement.solr.SolrEntityUtils.SOLR_AGENT_SUGGESTER_FILTER;
import static eu.europeana.entitymanagement.solr.SolrEntityUtils.SOLR_CONCEPT_SUGGESTER_FILTER;
import static eu.europeana.entitymanagement.solr.SolrEntityUtils.SOLR_ORGANIZATION_SUGGESTER_FILTER;
import static eu.europeana.entitymanagement.solr.SolrEntityUtils.SOLR_PLACE_SUGGESTER_FILTER;
import static eu.europeana.entitymanagement.solr.SolrEntityUtils.SOLR_TIMESPAN_SUGGESTER_FILTER;
import static eu.europeana.entitymanagement.solr.SolrEntityUtils.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.fasterxml.jackson.databind.ser.FilterProvider;
Expand Down
Loading

0 comments on commit 7622ef4

Please sign in to comment.