This commit is contained in:
Fabio Sinibaldi 2019-01-25 17:53:50 +00:00
parent c060f291ce
commit 0626f2a0c4
22 changed files with 136 additions and 38 deletions

View File

@ -121,7 +121,7 @@ public class PerformanceManagerImpl implements PerformanceManager{
String tablename=(analysisType.getId()+"_"+schema.getRelatedDescription()).toLowerCase().replaceAll(" ", "_");
ImportedTable table=new ImportedTable(
tablename, schema,

View File

@ -11,6 +11,8 @@ import org.gcube.application.perform.service.engine.model.anagraphic.Batch;
import org.gcube.application.perform.service.engine.model.anagraphic.Farm;
import org.gcube.application.perform.service.engine.model.importer.ImportRoutineDescriptor;
import org.gcube.application.perform.service.engine.model.importer.ImportStatus;
import org.gcube.application.perform.service.engine.utils.CommonUtils;
import org.gcube.application.perform.service.engine.utils.ScopeUtils;
public class Queries {
@ -147,6 +149,11 @@ public class Queries {
toReturn.setSourceVersion(rs.getString(ImportRoutine.SOURCE_VERSION));
toReturn.setStartTime(rs.getTimestamp(ImportRoutine.START).toInstant());
toReturn.setStatus(ImportStatus.valueOf(rs.getString(ImportRoutine.STATUS)));
try {
toReturn.setSubmitterIdentity(ScopeUtils.getClientId(CommonUtils.decryptString(rs.getString(ImportRoutine.CALLER))));
}catch(Throwable t) {
}
return toReturn;
}

View File

@ -17,6 +17,7 @@ public class SchemaDefinition {
private static final String CSV="csv";
private static final String ENABLE_ANALYSIS="enable_analysis";
private static final String REPORT_FIELDS="report_fields";
private static final String REPORT_LABELS="report_labels";
public String getRelatedDescription() {
return relatedDescription;
@ -69,6 +70,10 @@ public class SchemaDefinition {
return toReportFields;
}
public ArrayList<String> getToReportLabels() {
return toReportLabels;
}
public SchemaDefinition(AnalysisType relatedAnalysis, Properties props) {
super();
this.relatedDescription = props.getProperty(DESCRIPTION);
@ -87,7 +92,11 @@ public class SchemaDefinition {
toReportFields.add(field);
}
if(props.containsKey(REPORT_LABELS)) {
String labelList=props.getProperty(REPORT_LABELS);
for(String label: labelList.split(","))
toReportLabels.add(label);
}
}
@ -106,7 +115,7 @@ public class SchemaDefinition {
private ArrayList<String> toReportFields=new ArrayList<>();
private ArrayList<String> toReportLabels=new ArrayList<>();
private String areaField="area";
private String periodField="period";

View File

@ -11,10 +11,13 @@ public class ImportRoutineDescriptor {
}
public ImportRoutineDescriptor(Long id, Long farmId, String batch_type, String sourceUrl, String sourceVersion,
Instant startTime, Instant endTime, ImportStatus status, String lock, String caller, String computationId,
String computationUrl, String computationOperator, String computationOperatorName,
String computationRequest) {
String computationRequest, String submitterIdentity) {
super();
this.id = id;
this.farmId = farmId;
@ -31,9 +34,13 @@ public class ImportRoutineDescriptor {
this.computationOperator = computationOperator;
this.computationOperatorName = computationOperatorName;
this.computationRequest = computationRequest;
this.submitterIdentity = submitterIdentity;
}
private Long id;
private Long farmId;
private String batch_type;
@ -53,7 +60,13 @@ public class ImportRoutineDescriptor {
private String computationOperatorName;
private String computationRequest;
private String submitterIdentity;
public String getSubmitterIdentity() {
return submitterIdentity;
}
public void setSubmitterIdentity(String submitterIdentity) {
this.submitterIdentity = submitterIdentity;
}
public Long getId() {
@ -155,8 +168,10 @@ public class ImportRoutineDescriptor {
+ ", endTime=" + endTime + ", status=" + status + ", lock=" + lock + ", caller=" + caller
+ ", computationId=" + computationId + ", computationUrl=" + computationUrl + ", computationOperator="
+ computationOperator + ", computationOperatorName=" + computationOperatorName + ", computationRequest="
+ computationRequest + "]";
+ computationRequest + ", submitterIdentity=" + submitterIdentity + "]";
}
}

View File

@ -60,12 +60,14 @@ public class ImportedTable {
private SchemaDefinition schema;
public ImportedTable(String tablename, SchemaDefinition schema, ArrayList<DBField> csvFieldsDefinition) {
public ImportedTable(String tablename, SchemaDefinition schema, ArrayList<DBField> csvFieldsDefinition) throws InternalException {
super();
this.schema=schema;
this.tablename=tablename;
// init
// check schema
csvFields=new ArrayList<>();
labels=new HashMap<>();
@ -75,10 +77,27 @@ public class ImportedTable {
labels.put(field.getFieldName(), new DBField(field.getType(),escaped));
}
check(schema.getAssociationUUIDField());
check(schema.getBatchUUIDField());
check(schema.getCompanyUUIDField());
check(schema.getFarmUUIDField());
// check(schema.getAreaField());
// check(schema.getPeriodField());
// check(schema.getQuarterField());
// check(schema.getSpeciesField());
for(String f:schema.getToReportFields())
check(f);
insertQuery=prepareInsertionQuery();
}
private void check(String field) throws InternalException {
if(field!=null)
if(!labels.containsKey(field)) throw new InternalException("Incoherent schema definition for table "+tablename+". Field "+field+" not found in csv.");
}
private DBField getRoutineIdField() {
return new DBField(Types.BIGINT,schema.getRoutineIdFieldName());
}
@ -222,10 +241,14 @@ public class ImportedTable {
}
}
exportQuery.setMapping(schema.getAssociationUUIDField(), associationMapping);
exportQuery.setMapping(schema.getCompanyUUIDField(), companyMapping);
exportQuery.setMapping(schema.getFarmUUIDField(), farmMapping);
exportQuery.setMapping(schema.getBatchUUIDField(), batchMapping);
if(schema.getAssociationUUIDField()!=null)
exportQuery.setMapping(schema.getAssociationUUIDField(), associationMapping);
if(schema.getCompanyUUIDField()!=null)
exportQuery.setMapping(schema.getCompanyUUIDField(), companyMapping);
if(schema.getFarmUUIDField()!=null)
exportQuery.setMapping(schema.getFarmUUIDField(), farmMapping);
if(schema.getBatchUUIDField()!=null)
exportQuery.setMapping(schema.getBatchUUIDField(), batchMapping);
log.trace("Performing actual query towards {} ",tablename);
@ -256,7 +279,8 @@ public class ImportedTable {
toReturn.put(this.schema.getRelatedDescription()+"_internal", putIntoStorage(csvRs, personalLabels.toArray(new String[personalLabels.size()])));
toReturn.put(this.schema.getRelatedDescription()+"_internal", putIntoStorage(csvRs,
schema.getToReportLabels().toArray(new String[schema.getToReportLabels().size()])));
}

View File

@ -2,6 +2,7 @@ package org.gcube.application.perform.service.engine.utils;
import static org.gcube.common.authorization.client.Constants.authorizationService;
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
import org.gcube.common.authorization.library.AuthorizationEntry;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
@ -52,5 +53,8 @@ public class ScopeUtils {
}
public static String getClientId(String token) throws ObjectNotFound, Exception {
AuthorizationEntry entry = authorizationService().get(token);
return entry.getClientInfo().getId();
}
}

View File

@ -1,4 +1,7 @@
description=AnnualTable
farm=farm_id
farm=farmid
routine=internal_routine_id
csv=csv/KPIs_annual.csv
csv=csv/KPIs_annual.csv
enable_analysis=true
report_fields=farmid,area
report_labels=FARM,AREA

View File

@ -1,4 +1,7 @@
description=AntibioticsTable
farm=farm_id
farm=farmid
routine=internal_routine_id
csv=csv/KPIs_antibiotics.csv
csv=csv/KPIs_antibiotics.csv
enable_analysis=true
report_fields=farmid,area
report_labels=FARM,AREA

View File

@ -1,4 +1,7 @@
description=AntiparasiticTable
farm=farm_id
farm=farmid
routine=internal_routine_id
csv=csv/KPIs_antiparasitic.csv
csv=csv/KPIs_antiparasitic.csv
enable_analysis=true
report_fields=farmid,area
report_labels=FARM,AREA

View File

@ -1,9 +1,10 @@
description=BatchesTable
farm=farm_id
company=company_id
association=producer_association_id
association=producer_association_affiliation
batch=aggregated_batch_id
routine=internal_routine_id
csv=csv/Grow_out_Aggregated_Batch_Data_Entry_KPI.csv
enable_analysis=true
report_fields=aggregated_batch_id
report_fields=aggregated_batch_id,farm_id,area
report_labels=BATCH,FARM,AREA

View File

@ -1,4 +1,7 @@
description=LethalIncidentsTable
farm=farm_id
farm=farmid
routine=internal_routine_id
csv=csv/KPIs_lethalincidents.csv
csv=csv/KPIs_lethalincidents.csv
enable_analysis=true
report_fields=farmid,area
report_labels=FARM,AREA

View File

@ -1,4 +1,7 @@
description=AnnualTable
farm=farm_id
farm=farmid
routine=internal_routine_id
csv=csv/KPIs_annual.csv
csv=csv/KPIs_annual.csv
enable_analysis=true
report_fields=farmid,area
report_labels=FARM,AREA

View File

@ -1,4 +1,7 @@
description=AntibioticsTable
farm=farm_id
farm=farmid
routine=internal_routine_id
csv=csv/KPIs_antibiotics.csv
csv=csv/KPIs_antibiotics.csv
enable_analysis=true
report_fields=farmid,area
report_labels=FARM,AREA

View File

@ -1,4 +1,7 @@
description=AntiparasiticTable
farm=farm_id
farm=farmid
routine=internal_routine_id
csv=csv/KPIs_antiparasitic.csv
csv=csv/KPIs_antiparasitic.csv
enable_analysis=true
report_fields=farmid,area
report_labels=FARM,AREA

View File

@ -1,4 +1,7 @@
description=LethalIncidentsTable
farm=farm_id
farm=farmid
routine=internal_routine_id
csv=csv/KPIs_lethalincidents.csv
csv=csv/KPIs_lethalincidents.csv
enable_analysis=true
report_fields=farmid,area
report_labels=FARM,AREA

View File

@ -5,4 +5,6 @@ association=producer_association_affiliation
batch=batch_id
routine=internal_routine_id
csv=csv/Grow_out_Individual_Batch_Data_Entry_KPI.csv
enable_analysis=true
enable_analysis=true
report_fields=batch_id,farm_id,area
report_labels=BATCH,FARM,AREA

View File

@ -5,4 +5,6 @@ association=producer_association_affiliation
batch=batch_id
routine=internal_routine_id
csv=csv/Grow_out_Individual_Batch_Data_Entry_KPI_CLOSED_BATCHES.csv
enable_analysis=true
enable_analysis=true
report_fields=batch_id,farm_id,area
report_labels=BATCH,FARM,AREA

View File

@ -5,4 +5,6 @@ association=producer_association_affiliation
batch=aggregated_batches_id
routine=internal_routine_id
csv=csv/Hatchery_Aggregated_Batch_Data_Entry_KPI.csv
enable_analysis=true
enable_analysis=true
report_fields=aggregated_batches_id,farm_id
report_labels=BATCH,FARM

View File

@ -4,4 +4,6 @@ company=company_id
batch=batch_id
routine=internal_routine_id
csv=csv/Hatchery_ Individual_Batch_Data_Entry_KPI.csv
enable_analysis=true
enable_analysis=true
report_fields=batch_id,farm_id
report_labels=BATCH,FARM

View File

@ -4,4 +4,6 @@ company=company_id
batch=batch_id
routine=internal_routine_id
csv=csv/Hatchery_ Individual_Batch_Data_Entry_KPI_CLOSED_BATCHES.csv
enable_analysis=true
enable_analysis=true
report_fields=batch_id,farm_id
report_labels=BATCH,FARM

View File

@ -4,4 +4,6 @@ company=company_id
batch=batch_id
routine=internal_routine_id
csv=csv/Pre-grow_Batch_Data_Entry_KPI.csv
enable_analysis=true
enable_analysis=true
report_fields=batch_id,farm_id
report_labels=BATCH,FARM

View File

@ -4,4 +4,6 @@ company=company_id
batch=batch_id
routine=internal_routine_id
csv=csv/Pre-grow_Batch_Data_Entry_KPI_CLOSED_BATCHES.csv
enable_analysis=true
enable_analysis=true
report_fields=batch_id,farm_id
report_labels=BATCH,FARM