code changed to match the new hierarchy structure as well as tags and groups reported in ticket #7059

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/grsf-publisher-ws@142563 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2017-02-15 14:11:45 +00:00
parent 7f608a504f
commit b0b56dc1a1
12 changed files with 82 additions and 50 deletions

View File

@ -18,11 +18,7 @@
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@ -0,0 +1,2 @@
eclipse.preferences.version=1
filesCopiedToWebInfLib=

View File

@ -12,5 +12,11 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface Group {
/**
* Define a REGEX condition to be checked before the record
* is actually added to the group.
*/
String condition() default "";
}

View File

@ -27,6 +27,7 @@ public class Common extends Base{
@JsonProperty("data_owner")
@CustomField(key="Data owner")
@Tag
private String dataOwner;
@JsonProperty("database_sources")
@ -49,12 +50,13 @@ public class Common extends Base{
@JsonProperty("traceability_flag")
@CustomField(key="Traceability Flag")
@Group(condition="true") // record is added to group if Traceability Flag is true
private Boolean traceabilityFlag;
@JsonProperty("status")
@CustomField(key="Status")
@Group
@Tag
// @Tag
private Status status;
@JsonProperty("reporting_year")
@ -64,8 +66,8 @@ public class Common extends Base{
// automatically compiled
@JsonProperty("product_type")
@CustomField(key=PRODUCT_TYPE_KEY)
@Tag
@Group
//@Tag
//@Group
private String productType;
// automatically compiled

View File

@ -40,6 +40,7 @@ public class FisheryRecord extends Common{
@JsonProperty("fishing_area")
@CustomField(key="Fishing area")
@Tag
private List<String> fishingArea;
@JsonProperty("exploited_stocks")
@ -53,10 +54,11 @@ public class FisheryRecord extends Common{
@JsonProperty("jurisdiction_area")
@CustomField(key="Jurisdiction Area")
@Tag
private List<String> jurisdictionArea;
@JsonProperty("production_system_type")
@Group
//@Group
@Tag
@CustomField(key="Production system type")
private List<Production_System_Type> productionSystemType;
@ -77,7 +79,7 @@ public class FisheryRecord extends Common{
@JsonProperty("catches_or_landings")
@CustomField(key="Catches or landings")
@Tag
//@Tag
@TimeSeries
@Valid
private List<TimeSeriesBean<String, String>> catchesOrLandings;

View File

@ -41,6 +41,7 @@ public class StockRecord extends Common{
@JsonProperty("assessment_distribution_area")
@CustomField(key="Assessment distribution area")
@Tag
private List<String> area;
@JsonProperty("exploiting_fishery")
@ -61,7 +62,7 @@ public class StockRecord extends Common{
@JsonProperty("standard_exploitation_rate")
@CustomField(key="Standard Exploitation Rate")
@Tag
//@Tag
@TimeSeries
@Valid
private List<TimeSeriesBean<Exploitation_Rate, Void>> exploitationRateStandard;
@ -74,7 +75,7 @@ public class StockRecord extends Common{
@JsonProperty("standard_abundance_level")
@CustomField(key="Standard Abundance Level")
@Tag
//@Tag
@TimeSeries
@Valid
private List<TimeSeriesBean<Abundance_Level, Void>> abundanceLevelStandard;
@ -93,9 +94,10 @@ public class StockRecord extends Common{
@CustomField(key="Scientific advice")
private String scientificAdvice;
@JsonProperty("reporting_entity")
@CustomField(key="Reporting entity")
private String reportingEntity;
@JsonProperty("assessor")
@CustomField(key="Assessor")
@Tag
private String assessor;
@JsonProperty("stock_uri")
@CustomField(key="Stock Uri")
@ -103,6 +105,7 @@ public class StockRecord extends Common{
@JsonProperty("water_area")
@CustomField(key="Water Area")
@Tag
private List<String> waterArea;
@JsonProperty("type")
@ -151,7 +154,7 @@ public class StockRecord extends Common{
List<TimeSeriesBean<Abundance_Level, Void>> abundanceLevelStandard,
List<TimeSeriesBean<String, String>> abundanceLevel,
String narrativeStateAndTrend, String scientificAdvice,
String reportingEntity, Long reportingYear, String stockUri,
String assessor, Long reportingYear, String stockUri,
List<String> waterArea, Stock_Type type) {
super();
this.stockName = stockName;
@ -168,7 +171,7 @@ public class StockRecord extends Common{
this.abundanceLevel = abundanceLevel;
this.narrativeStateAndTrend = narrativeStateAndTrend;
this.scientificAdvice = scientificAdvice;
this.reportingEntity = reportingEntity;
this.assessor = assessor;
this.stockUri = stockUri;
this.waterArea = waterArea;
this.type = type;
@ -305,12 +308,12 @@ public class StockRecord extends Common{
this.scientificAdvice = scientificAdvice;
}
public String getReportingEntity() {
return reportingEntity;
public String getAssessor() {
return assessor;
}
public void setReportingEntity(String reportingEntity) {
this.reportingEntity = reportingEntity;
public void setAssessor(String assessor) {
this.assessor = assessor;
}
public List<TimeSeriesBean<String, String>> getExploitationRate() {
@ -336,7 +339,7 @@ public class StockRecord extends Common{
+ ", abundanceLevel=" + abundanceLevel
+ ", narrativeStateAndTrend=" + narrativeStateAndTrend
+ ", scientificAdvice=" + scientificAdvice
+ ", reportingEntity=" + reportingEntity + ", stockUri="
+ ", assessor=" + assessor + ", stockUri="
+ stockUri + ", waterArea=" + waterArea + ", type=" + type
+ "]";
}

View File

@ -195,6 +195,7 @@ public class CommonServiceUtils {
*/
private static void getGroupsByField(Field field, Class<?> current, Base record, Set<String> groups, Sources source){
if(field.isAnnotationPresent(Group.class)){
String conditionToCheck = field.getAnnotation(Group.class).condition();
try{
Object f = new PropertyDescriptor(field.getName(), current).getReadMethod().invoke(record);
if(f != null){
@ -206,36 +207,45 @@ public class CommonServiceUtils {
// else add all the available elements
for (int i = 0; i < asList.size(); i++) {
String groupName = HelperMethods.getGroupNameOnCkan(source.toString().toLowerCase() + "-" + asList.get(i).toString().trim());
logger.debug(groupName);
groups.add(groupName);
boolean match = conditionToCheck.equals("") ? true : asList.get(i).toString().trim().matches(conditionToCheck);
if(match){
String groupName = HelperMethods.getGroupNameOnCkan(source.toString().toLowerCase() + "-" + asList.get(i).toString().trim());
logger.debug(groupName);
groups.add(groupName);
}
}
}
}else{
// also convert to the group name that should be on ckan
String groupName = HelperMethods.getGroupNameOnCkan(source.toString().toLowerCase() + "-" + f.toString().trim());
groups.add(groupName);
boolean match = conditionToCheck.equals("") ? true : f.toString().trim().matches(conditionToCheck);
if(match){
String groupName = HelperMethods.getGroupNameOnCkan(source.toString().toLowerCase() + "-" + f.toString().trim());
groups.add(groupName);
}
}
}
// check if the field is an enumerator, and the enum class is also annotated with @Group
if(field.getType().isEnum() && field.getType().isAnnotationPresent(Group.class)){
logger.info("Class " + field.getClass().getSimpleName() + " has annotation @Group");
// extract the name from the enum class and add it to the groups
// also convert to the group name that should be on ckan
String groupName = HelperMethods.getGroupNameOnCkan(source.toString().toLowerCase() + "-" + field.getType().getSimpleName());
groups.add(groupName);
}
// // check if the field is an enumerator, and the enum class is also annotated with @Group
// if(field.getType().isEnum() && field.getType().isAnnotationPresent(Group.class)){
//
// logger.info("Class " + field.getClass().getSimpleName() + " has annotation @Group");
//
// // extract the name from the enum class and add it to the groups
// // also convert to the group name that should be on ckan
// String groupName = HelperMethods.getGroupNameOnCkan(source.toString().toLowerCase() + "-" + field.getType().getSimpleName());
// groups.add(groupName);
//
// }
}catch(Exception e){
logger.error("Failed to read value for field " + field.getName() + " skipping", e);
}
}
// add the record among the source group (check for grsf-group)
groups.add(source.equals(Sources.GRSF) ? "grsf-group" : source.getOrigName());
}
/**
@ -298,7 +308,6 @@ public class CommonServiceUtils {
* @param record
* @param username
* @param tags
* @param groups
* @param resources
* @return
*/

View File

@ -63,7 +63,7 @@ public class GrsfPublisherFisheryService {
// Logger
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(GrsfPublisherFisheryService.class);
private static final String PRODUCT_URL_FIELD_KEY = "Product URL";
private static final String RECORD_URL_FIELD_KEY = "Record URL";
@GET
@Path("hello")
@ -246,7 +246,7 @@ public class GrsfPublisherFisheryService {
// add the "Product URL" to the field
Map<String, List<String>> addField = new HashMap<String, List<String>>();
addField.put(PRODUCT_URL_FIELD_KEY, Arrays.asList(productUrl));
addField.put(RECORD_URL_FIELD_KEY, Arrays.asList(productUrl));
catalogue.patchProductCustomFields(id, apiKey, addField);
if(!groups.isEmpty()){
@ -440,8 +440,8 @@ public class GrsfPublisherFisheryService {
// retrieve the product url
Map<String, String> customFields = dataset.getExtrasAsHashMap();
if(customFields.containsKey(PRODUCT_URL_FIELD_KEY))
result.put("url", customFields.get(PRODUCT_URL_FIELD_KEY));
if(customFields.containsKey(RECORD_URL_FIELD_KEY))
result.put("url", customFields.get(RECORD_URL_FIELD_KEY));
else
result.put("url", catalogue.getUnencryptedUrlFromDatasetIdOrName(dataset.getId()));

View File

@ -63,7 +63,7 @@ public class GrsfPublisherStockService {
// Logger
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(GrsfPublisherStockService.class);
private static final String PRODUCT_URL_FIELD_KEY = "Product URL";
private static final String RECORD_URL_FIELD_KEY = "Record URL";
@GET
@Path("hello")
@ -236,7 +236,7 @@ public class GrsfPublisherStockService {
// add the "Product URL" to the field
Map<String, List<String>> addField = new HashMap<String, List<String>>();
addField.put(PRODUCT_URL_FIELD_KEY, Arrays.asList(productUrl));
addField.put(RECORD_URL_FIELD_KEY, Arrays.asList(productUrl));
catalogue.patchProductCustomFields(id, apiKey, addField);
if(!groups.isEmpty()){
@ -431,8 +431,8 @@ public class GrsfPublisherStockService {
// retrieve the product url
Map<String, String> customFields = dataset.getExtrasAsHashMap();
if(customFields.containsKey(PRODUCT_URL_FIELD_KEY))
result.put("url", customFields.get(PRODUCT_URL_FIELD_KEY));
if(customFields.containsKey(RECORD_URL_FIELD_KEY))
result.put("url", customFields.get(RECORD_URL_FIELD_KEY));
else
result.put("url", catalogue.getUnencryptedUrlFromDatasetIdOrName(dataset.getId()));

View File

@ -13,7 +13,8 @@ public enum Status {
Approved("Approved"),
Rejected("Rejected"),
Archived("Archived"),
Hidden("Hidden");
Hidden("Hidden"),
Merged("Merged");
private String origName;

View File

@ -10,8 +10,8 @@ import com.fasterxml.jackson.annotation.JsonValue;
*/
public enum Stock_Type {
Assessment_Unit("Assessment Unit"),// for stock
Resource("Resource"); // for stock
Assessment_Unit("Assessment Unit"),
Resource("Marine Resource");
private String subGroupNameOrig;

View File

@ -527,4 +527,15 @@ public class JTests {
}
}
//@Test
public void testMatch(){
Boolean value = Boolean.TRUE;
String expr = "false";
System.out.println("Check " + value.toString().matches(expr));
}
}