git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/application/perform-service@176534 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
e0266ddbe0
commit
5a7ecc8f73
|
@ -6,6 +6,7 @@ import org.gcube.application.perform.service.engine.Importer;
|
|||
import org.gcube.application.perform.service.engine.ImporterImpl;
|
||||
import org.gcube.application.perform.service.engine.MappingManager;
|
||||
import org.gcube.application.perform.service.engine.MappingManagerImpl;
|
||||
import org.gcube.application.perform.service.rest.Import;
|
||||
import org.gcube.application.perform.service.rest.Mappings;
|
||||
import org.glassfish.hk2.utilities.binding.AbstractBinder;
|
||||
import org.glassfish.jersey.media.multipart.MultiPartFeature;
|
||||
|
@ -34,7 +35,7 @@ public class PerformService extends ResourceConfig{
|
|||
};
|
||||
register(binder);
|
||||
registerClasses(Mappings.class);
|
||||
|
||||
registerClasses(Import.class);
|
||||
// packages("org.gcube.application.perform.service.rest");
|
||||
register(MultiPartFeature.class);
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ public interface ServiceConstants {
|
|||
public static final String BATCH_TYPE_PARAMETER="batch_type";
|
||||
public static final String FARM_ID_PARAMETER="farmid";
|
||||
public static final String EXCEL_FILE_PARAMETER="source";
|
||||
public static final String EXCEL_FILE_VERSION_PARAMETER="source_version";
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -54,10 +54,15 @@ public class ImporterImpl implements Importer {
|
|||
|
||||
|
||||
private static final String getHostname() {
|
||||
ApplicationContext context=ContextProvider.get();
|
||||
ContainerConfiguration configuration=context.container().configuration();
|
||||
try{
|
||||
ApplicationContext context=ContextProvider.get();
|
||||
ContainerConfiguration configuration=context.container().configuration();
|
||||
|
||||
return configuration.hostname();
|
||||
return configuration.hostname();
|
||||
}catch(Throwable t) {
|
||||
log.warn("UNABLE TO GET HOSTNAME. This should happen only in debug mode.");
|
||||
return "localhost";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -71,7 +76,7 @@ public class ImporterImpl implements Importer {
|
|||
|
||||
|
||||
PreparedStatement psOrphans=Queries.ORPHAN_IMPORTS.prepare(conn);
|
||||
PreparedStatement psAcquire=Queries.ACQUIRE_PS.prepare(conn);
|
||||
PreparedStatement psAcquire=Queries.ACQUIRE_IMPORT_ROUTINE.prepare(conn);
|
||||
// set ps
|
||||
ResultSet rsOrphans=psOrphans.executeQuery();
|
||||
long monitoredCount=0l;
|
||||
|
@ -84,7 +89,7 @@ public class ImporterImpl implements Importer {
|
|||
add(ImportRoutine.fields.get(ImportRoutine.LOCK), hostname).
|
||||
add(ImportRoutine.fields.get(ImportRoutine.ID), id);
|
||||
|
||||
Queries.ACQUIRE_PS.fill(psAcquire, acquireDesc);
|
||||
Queries.ACQUIRE_IMPORT_ROUTINE.fill(psAcquire, acquireDesc);
|
||||
|
||||
if(psAcquire.executeUpdate()>0) {
|
||||
log.debug("Acquired {} ",id);
|
||||
|
@ -158,7 +163,7 @@ public class ImporterImpl implements Importer {
|
|||
add(ImportRoutine.fields.get(ImportRoutine.LOCK), getHostname()).
|
||||
add(ImportRoutine.fields.get(ImportRoutine.SOURCE_URL), request.getSource()).
|
||||
add(ImportRoutine.fields.get(ImportRoutine.SOURCE_VERSION), request.getVersion()).
|
||||
add(ImportRoutine.fields.get(ImportRoutine.START), Instant.now()).
|
||||
add(ImportRoutine.fields.get(ImportRoutine.START), java.sql.Timestamp.from(Instant.now())).
|
||||
add(ImportRoutine.fields.get(ImportRoutine.STATUS),ImportStatus.ACCEPTED.toString());
|
||||
|
||||
|
||||
|
@ -173,7 +178,7 @@ public class ImporterImpl implements Importer {
|
|||
ResultSet rs=ps.getGeneratedKeys();
|
||||
rs.next();
|
||||
|
||||
PreparedStatement psGet=Queries.GET_BY_ID.get(conn,
|
||||
PreparedStatement psGet=Queries.GET_IMPORT_ROUTINE_BY_ID.get(conn,
|
||||
new DBQueryDescriptor().add(ImportRoutine.fields.get(ImportRoutine.ID), rs.getLong(ImportRoutine.ID)));
|
||||
ResultSet rsGet=psGet.executeQuery();
|
||||
rsGet.next();
|
||||
|
@ -184,7 +189,7 @@ public class ImporterImpl implements Importer {
|
|||
DataBaseManager db=DataBaseManager.get(getISQueryDescriptor());
|
||||
Connection conn=db.getConnection();
|
||||
|
||||
PreparedStatement ps=Queries.GET_BY_ID.get(conn,
|
||||
PreparedStatement ps=Queries.GET_IMPORT_ROUTINE_BY_ID.get(conn,
|
||||
new DBQueryDescriptor().add(ImportRoutine.fields.get(ImportRoutine.ID), id));
|
||||
ps.setLong(1, id);
|
||||
ResultSet rs=ps.executeQuery();
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.gcube.application.perform.service.engine;
|
|||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.application.perform.service.engine.model.DBField;
|
||||
|
@ -32,18 +33,57 @@ public class Queries {
|
|||
|
||||
|
||||
// Imports with lock = hostname or lock == null
|
||||
public static final Query ORPHAN_IMPORTS=new Query("SELECT * from imports where ",new DBField[]{});
|
||||
public static final Query ORPHAN_IMPORTS=new Query("SELECT * from "+ImportRoutine.TABLE+" where "+ImportRoutine.LOCK+" = ? OR "+ImportRoutine.LOCK+" IS NULL ",
|
||||
new DBField[]{DBField.ImportRoutine.fields.get(ImportRoutine.LOCK)});
|
||||
// "acquire"
|
||||
// set lock = hostname where ID =? and LOCK is null
|
||||
// Acquired = updated rows == 1
|
||||
public static final Query ACQUIRE_PS=new Query("Update ",new DBField[]{});
|
||||
public static final Query GET_BY_ID=new Query("",new DBField[]{});
|
||||
public static final Query INSERT_ROUTINE=new Query("",new DBField[]{});
|
||||
public static final Query ACQUIRE_IMPORT_ROUTINE=new Query("UPDATE "+ImportRoutine.TABLE+" SET "+ImportRoutine.LOCK+"=? WHERE "+ImportRoutine.FARM_ID+" = ? AND "+ImportRoutine.LOCK+" IS NULL",
|
||||
new DBField[]{DBField.ImportRoutine.fields.get(ImportRoutine.LOCK),DBField.ImportRoutine.fields.get(ImportRoutine.FARM_ID)});
|
||||
|
||||
public static final Query GET_IMPORT_ROUTINE_BY_ID=new Query("SELECT * from "+ImportRoutine.TABLE+" WHERE "+ImportRoutine.ID+" = ?",
|
||||
new DBField[]{DBField.ImportRoutine.fields.get(ImportRoutine.ID)});
|
||||
public static final Query INSERT_ROUTINE=new Query("INSERT INTO "+ImportRoutine.TABLE+"("
|
||||
+ImportRoutine.BATCH_TYPE+","
|
||||
+ImportRoutine.CALLER+","
|
||||
+ImportRoutine.COMPUTATION_ID+","
|
||||
+ImportRoutine.COMPUTATION_OPID+","
|
||||
+ImportRoutine.COMPUTATION_OPNAME+","
|
||||
+ImportRoutine.COMPUTATION_REQ+","
|
||||
+ImportRoutine.COMPUTATION_URL+","
|
||||
// +ImportRoutine.END+","
|
||||
+ImportRoutine.FARM_ID+","
|
||||
+ImportRoutine.LOCK+","
|
||||
+ImportRoutine.SOURCE_URL+","
|
||||
+ImportRoutine.SOURCE_VERSION+","
|
||||
+ImportRoutine.START+","
|
||||
+ImportRoutine.STATUS+") values (?,?,?,?,?,?,?,?,?,?,?,?,?)",
|
||||
new DBField[]{DBField.ImportRoutine.fields.get(ImportRoutine.BATCH_TYPE),
|
||||
DBField.ImportRoutine.fields.get(ImportRoutine.CALLER),
|
||||
DBField.ImportRoutine.fields.get(ImportRoutine.COMPUTATION_ID),
|
||||
DBField.ImportRoutine.fields.get(ImportRoutine.COMPUTATION_OPID),
|
||||
DBField.ImportRoutine.fields.get(ImportRoutine.COMPUTATION_OPNAME),
|
||||
DBField.ImportRoutine.fields.get(ImportRoutine.COMPUTATION_REQ),
|
||||
DBField.ImportRoutine.fields.get(ImportRoutine.COMPUTATION_URL),
|
||||
// DBField.ImportRoutine.fields.get(ImportRoutine.END),
|
||||
DBField.ImportRoutine.fields.get(ImportRoutine.FARM_ID),
|
||||
DBField.ImportRoutine.fields.get(ImportRoutine.LOCK),
|
||||
DBField.ImportRoutine.fields.get(ImportRoutine.SOURCE_URL),
|
||||
DBField.ImportRoutine.fields.get(ImportRoutine.SOURCE_VERSION),
|
||||
DBField.ImportRoutine.fields.get(ImportRoutine.START),
|
||||
DBField.ImportRoutine.fields.get(ImportRoutine.STATUS)});
|
||||
|
||||
public static final Query FILTER_IMPORTS=new Query("",new DBField[]{});
|
||||
public static final Query FILTER_IMPORTS=new Query("SELECT * from "+ImportRoutine.TABLE+" WHERE "+ImportRoutine.FARM_ID+" = ?",
|
||||
new DBField[]{DBField.ImportRoutine.fields.get(ImportRoutine.FARM_ID)});
|
||||
|
||||
|
||||
|
||||
public static final Query UPDATE_IMPORT_STATUS=new Query("UPDATE "+ImportRoutine.TABLE+" SET "+ImportRoutine.STATUS+"= ?, "+ImportRoutine.END+"=? WHERE "+ImportRoutine.ID+"=?",
|
||||
new DBField[]{DBField.ImportRoutine.fields.get(ImportRoutine.STATUS),
|
||||
DBField.ImportRoutine.fields.get(ImportRoutine.END),
|
||||
DBField.ImportRoutine.fields.get(ImportRoutine.ID)});
|
||||
|
||||
|
||||
// LOADERS
|
||||
|
||||
public static Batch rowToBatch(ResultSet rs) throws SQLException {
|
||||
|
@ -78,7 +118,10 @@ public class Queries {
|
|||
toReturn.setComputationOperatorName(rs.getString(ImportRoutine.COMPUTATION_OPNAME));
|
||||
toReturn.setComputationRequest(rs.getString(ImportRoutine.COMPUTATION_REQ));
|
||||
toReturn.setComputationUrl(rs.getString(ImportRoutine.COMPUTATION_URL));
|
||||
toReturn.setEndTime(rs.getTimestamp(ImportRoutine.END).toInstant());
|
||||
|
||||
Timestamp endTime=rs.getTimestamp(ImportRoutine.END);
|
||||
if(endTime!=null)
|
||||
toReturn.setEndTime(endTime.toInstant());
|
||||
toReturn.setFarmId(rs.getLong(ImportRoutine.FARM_ID));
|
||||
toReturn.setId(rs.getLong(ImportRoutine.ID));
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ import java.sql.SQLException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.gcube.application.perform.service.AnagraphicTests;
|
||||
import org.gcube.application.perform.service.engine.model.DBField;
|
||||
import org.gcube.application.perform.service.engine.model.DBQueryDescriptor;
|
||||
import org.gcube.application.perform.service.engine.model.InvalidRequestException;
|
||||
|
@ -17,29 +16,29 @@ import org.slf4j.LoggerFactory;
|
|||
public class Query {
|
||||
|
||||
private static final Logger log= LoggerFactory.getLogger(Query.class);
|
||||
|
||||
|
||||
private final String query;
|
||||
private final ArrayList<DBField> psFields;
|
||||
|
||||
|
||||
public Query(String query,DBField[] fields) {
|
||||
this.query=query;
|
||||
this.psFields=new ArrayList<>(Arrays.asList(fields));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public PreparedStatement prepare(Connection conn, int statementOption) throws SQLException {
|
||||
return conn.prepareStatement(getQuery(),statementOption);
|
||||
}
|
||||
public PreparedStatement prepare(Connection conn) throws SQLException {
|
||||
return conn.prepareStatement(getQuery());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public PreparedStatement get(Connection conn, DBQueryDescriptor desc) throws SQLException, InvalidRequestException {
|
||||
PreparedStatement ps=prepare(conn);
|
||||
return fill(ps,desc);
|
||||
}
|
||||
|
||||
|
||||
public PreparedStatement fill(PreparedStatement ps,DBQueryDescriptor desc) throws SQLException, InvalidRequestException{
|
||||
log.debug("Setting VALUES {} for Query {} ",desc,getQuery());
|
||||
ArrayList<DBField> fields=getPSFields();
|
||||
|
@ -48,21 +47,23 @@ public class Query {
|
|||
if(!desc.getCondition().containsKey(field))
|
||||
throw new InvalidRequestException("Missing field "+field);
|
||||
else {
|
||||
if(field.getType()==Integer.MIN_VALUE) // UUID EXCEPTION
|
||||
Object toSet=desc.getCondition().get(field);
|
||||
if(toSet==null) ps.setNull(i+1, field.getType());
|
||||
else if(field.getType()==Integer.MIN_VALUE) // UUID EXCEPTION
|
||||
ps.setObject(i+1, desc.getCondition().get(field));
|
||||
else ps.setObject(i+1, desc.getCondition().get(field), field.getType());
|
||||
}
|
||||
}
|
||||
return ps;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public String getQuery() {
|
||||
return query;
|
||||
}
|
||||
public ArrayList<DBField> getPSFields(){
|
||||
return psFields;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,14 @@
|
|||
package org.gcube.application.perform.service.engine.dm;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.time.Instant;
|
||||
|
||||
import org.gcube.application.perform.service.engine.DataBaseManager;
|
||||
import org.gcube.application.perform.service.engine.Queries;
|
||||
import org.gcube.application.perform.service.engine.model.DBField;
|
||||
import org.gcube.application.perform.service.engine.model.DBField.ImportRoutine;
|
||||
import org.gcube.application.perform.service.engine.model.DBQueryDescriptor;
|
||||
import org.gcube.application.perform.service.engine.model.ISQueryDescriptor;
|
||||
import org.gcube.application.perform.service.engine.model.importer.ImportRoutineDescriptor;
|
||||
import org.gcube.application.perform.service.engine.model.importer.ImportStatus;
|
||||
|
@ -12,9 +21,6 @@ public class ImporterMonitor implements DMMonitorListener {
|
|||
|
||||
private static final Logger log= LoggerFactory.getLogger(ImporterMonitor.class);
|
||||
|
||||
private static final String UPDATE_ROUTINE="";
|
||||
|
||||
|
||||
public ImporterMonitor(ImportRoutineDescriptor routine, ISQueryDescriptor isQuery) {
|
||||
super();
|
||||
this.routine = routine;
|
||||
|
@ -54,19 +60,29 @@ public class ImporterMonitor implements DMMonitorListener {
|
|||
|
||||
|
||||
private static final void updateStatus(ImportStatus status,ImportRoutineDescriptor routine,ISQueryDescriptor is) {
|
||||
throw new RuntimeException("NEED TO SET PS STMT");
|
||||
// try{
|
||||
// log.debug("Updateing status {} for {} ",status,routine);
|
||||
// DataBaseManager db=DataBaseManager.get(is);
|
||||
// Connection conn=db.getConnection();
|
||||
// conn.setAutoCommit(true);
|
||||
// PreparedStatement psUpdate=conn.prepareStatement(UPDATE_ROUTINE);
|
||||
// //TODO SET PARAMS
|
||||
//
|
||||
// psUpdate.executeUpdate();
|
||||
// }catch(Throwable t) {
|
||||
// log.warn("Unable to update status on database");
|
||||
// }
|
||||
try{
|
||||
log.debug("Updateing status {} for {} ",status,routine);
|
||||
DataBaseManager db=DataBaseManager.get(is);
|
||||
Connection conn=db.getConnection();
|
||||
conn.setAutoCommit(true);
|
||||
|
||||
Instant endTime=null;
|
||||
switch(status) {
|
||||
case CANCELLED:
|
||||
case COMPLETE :
|
||||
case FAILED : endTime=Instant.now();
|
||||
}
|
||||
|
||||
DBQueryDescriptor queryValues=new DBQueryDescriptor().
|
||||
add(DBField.ImportRoutine.fields.get(ImportRoutine.ID), routine.getId()).
|
||||
add(DBField.ImportRoutine.fields.get(ImportRoutine.STATUS), status.toString()).
|
||||
add(DBField.ImportRoutine.fields.get(ImportRoutine.END), endTime);
|
||||
|
||||
PreparedStatement psUpdate=Queries.UPDATE_IMPORT_STATUS.get(conn, queryValues);
|
||||
psUpdate.executeUpdate();
|
||||
}catch(Throwable t) {
|
||||
log.warn("Unable to update status on database");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -46,8 +46,8 @@ public class DBField {
|
|||
fields.put(COMPANY_ID, new DBField(Types.BIGINT,COMPANY_ID));
|
||||
fields.put(ASSOCIATION_ID, new DBField(Types.BIGINT,ASSOCIATION_ID));
|
||||
fields.put(UUID, new DBField(Integer.MIN_VALUE,UUID));
|
||||
fields.put(COMPANY_UUID, new DBField(Types.NVARCHAR,COMPANY_UUID));
|
||||
fields.put(ASSOCIATION_UUID, new DBField(Types.NVARCHAR,ASSOCIATION_UUID));
|
||||
fields.put(COMPANY_UUID, new DBField(Types.VARCHAR,COMPANY_UUID));
|
||||
fields.put(ASSOCIATION_UUID, new DBField(Types.VARCHAR,ASSOCIATION_UUID));
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -81,20 +81,20 @@ public class DBField {
|
|||
static {
|
||||
fields.put(FARM_ID, new DBField(Types.BIGINT,FARM_ID));
|
||||
fields.put(ID, new DBField(Types.BIGINT,ID));
|
||||
fields.put(BATCH_TYPE, new DBField(Types.NVARCHAR,BATCH_TYPE));
|
||||
fields.put(SOURCE_URL, new DBField(Types.NVARCHAR,SOURCE_URL));
|
||||
fields.put(SOURCE_VERSION, new DBField(Types.INTEGER,SOURCE_VERSION));
|
||||
fields.put(BATCH_TYPE, new DBField(Types.VARCHAR,BATCH_TYPE));
|
||||
fields.put(SOURCE_URL, new DBField(Types.VARCHAR,SOURCE_URL));
|
||||
fields.put(SOURCE_VERSION, new DBField(Types.VARCHAR,SOURCE_VERSION));
|
||||
|
||||
fields.put(START, new DBField(Types.TIMESTAMP_WITH_TIMEZONE,START));
|
||||
fields.put(END, new DBField(Types.TIMESTAMP_WITH_TIMEZONE,END));
|
||||
fields.put(STATUS, new DBField(Types.NVARCHAR,STATUS));
|
||||
fields.put(CALLER, new DBField(Types.NVARCHAR,CALLER));
|
||||
fields.put(COMPUTATION_ID, new DBField(Types.NVARCHAR,COMPUTATION_ID));
|
||||
fields.put(COMPUTATION_URL, new DBField(Types.NVARCHAR,COMPUTATION_URL));
|
||||
fields.put(COMPUTATION_OPID, new DBField(Types.NVARCHAR,COMPUTATION_OPID));
|
||||
fields.put(COMPUTATION_OPNAME, new DBField(Types.NVARCHAR,COMPUTATION_OPNAME));
|
||||
fields.put(COMPUTATION_REQ, new DBField(Types.NVARCHAR,COMPUTATION_REQ));
|
||||
fields.put(LOCK, new DBField(Types.NVARCHAR,LOCK));
|
||||
fields.put(START, new DBField(Types.TIMESTAMP,START));
|
||||
fields.put(END, new DBField(Types.TIMESTAMP,END));
|
||||
fields.put(STATUS, new DBField(Types.VARCHAR,STATUS));
|
||||
fields.put(CALLER, new DBField(Types.VARCHAR,CALLER));
|
||||
fields.put(COMPUTATION_ID, new DBField(Types.VARCHAR,COMPUTATION_ID));
|
||||
fields.put(COMPUTATION_URL, new DBField(Types.VARCHAR,COMPUTATION_URL));
|
||||
fields.put(COMPUTATION_OPID, new DBField(Types.VARCHAR,COMPUTATION_OPID));
|
||||
fields.put(COMPUTATION_OPNAME, new DBField(Types.VARCHAR,COMPUTATION_OPNAME));
|
||||
fields.put(COMPUTATION_REQ, new DBField(Types.VARCHAR,COMPUTATION_REQ));
|
||||
fields.put(LOCK, new DBField(Types.VARCHAR,LOCK));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.gcube.application.perform.service.engine.model;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
|
@ -9,7 +10,7 @@ public class DBQueryDescriptor {
|
|||
private Map<DBField,Object> condition;
|
||||
|
||||
public DBQueryDescriptor() {
|
||||
// TODO Auto-generated constructor stub
|
||||
condition=new HashMap<DBField,Object>();
|
||||
}
|
||||
|
||||
public Map<DBField, Object> getCondition() {
|
||||
|
|
|
@ -6,21 +6,31 @@ import javax.inject.Inject;
|
|||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.GenericEntity;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import org.gcube.application.perform.service.PerformServiceManager;
|
||||
import org.gcube.application.perform.service.ServiceConstants;
|
||||
import org.gcube.application.perform.service.engine.Importer;
|
||||
import org.gcube.application.perform.service.engine.model.DBField;
|
||||
import org.gcube.application.perform.service.engine.model.DBQueryDescriptor;
|
||||
import org.gcube.application.perform.service.engine.model.importer.ImportRequest;
|
||||
import org.gcube.application.perform.service.engine.model.importer.ImportRoutineDescriptor;
|
||||
import org.gcube.smartgears.annotations.ManagedBy;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@Path(ServiceConstants.Import.PATH)
|
||||
|
||||
@ManagedBy(PerformServiceManager.class)
|
||||
public class Import {
|
||||
|
||||
private static final Logger log= LoggerFactory.getLogger(Mappings.class);
|
||||
|
||||
@Inject
|
||||
private Importer importer;
|
||||
|
@ -37,9 +47,15 @@ public class Import {
|
|||
@POST
|
||||
public void importExcel(@QueryParam(ServiceConstants.Import.BATCH_TYPE_PARAMETER)String batchType,
|
||||
@QueryParam(ServiceConstants.Import.FARM_ID_PARAMETER)Long farmid,
|
||||
@QueryParam(ServiceConstants.Import.EXCEL_FILE_PARAMETER)String sourceFile) {
|
||||
@QueryParam(ServiceConstants.Import.EXCEL_FILE_PARAMETER)String sourceFile,
|
||||
@QueryParam(ServiceConstants.Import.EXCEL_FILE_VERSION_PARAMETER)String sourceVersion) {
|
||||
try {
|
||||
importer.importExcel(new ImportRequest(sourceFile, sourceVersion, batchType, farmid));
|
||||
}catch(Throwable t) {
|
||||
log.warn("Unexpected Exception on IMPORT ",t);
|
||||
throw new WebApplicationException("Unexpected Exception.", t,Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
throw new WebApplicationException("Not YET Implemented", Response.Status.NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
|
||||
|
@ -50,9 +66,20 @@ public class Import {
|
|||
* @return
|
||||
*/
|
||||
@GET
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Path("{"+ServiceConstants.Import.FARM_ID_PARAMETER+"}")
|
||||
public List<ImportRoutineDescriptor> getAll(){
|
||||
throw new WebApplicationException("Not YET Implemented", Response.Status.NOT_IMPLEMENTED);
|
||||
public Response getAll(@PathParam(ServiceConstants.Import.FARM_ID_PARAMETER) Long farmid){
|
||||
try {
|
||||
List<ImportRoutineDescriptor> toReturn=importer.getDescriptors(
|
||||
new DBQueryDescriptor().
|
||||
add(DBField.ImportRoutine.fields.get(DBField.ImportRoutine.FARM_ID), farmid));
|
||||
|
||||
GenericEntity<List<ImportRoutineDescriptor>> entity=new GenericEntity<List<ImportRoutineDescriptor>>(toReturn) {};
|
||||
return Response.ok(entity).build();
|
||||
}catch(Throwable t) {
|
||||
log.warn("Unexpected Exception ",t);
|
||||
throw new WebApplicationException("Unexpected Exception.", t,Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,38 +1,11 @@
|
|||
package org.gcube.application.perform.service;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import javax.ws.rs.client.WebTarget;
|
||||
import javax.ws.rs.core.Application;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import org.gcube.application.perform.service.engine.utils.ISUtils;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.glassfish.jersey.test.JerseyTest;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class AnagraphicTests extends JerseyTest{
|
||||
|
||||
private static final Logger log= LoggerFactory.getLogger(AnagraphicTests.class);
|
||||
|
||||
@BeforeClass
|
||||
public static void init() throws MalformedURLException {
|
||||
LocalConfiguration.init(Paths.get("src/main/webapp/WEB-INF/config.properties").toUri().toURL());
|
||||
TokenSetter.set("/gcube/preprod/preVRE");
|
||||
ISUtils.setFixedToken(SecurityTokenProvider.instance.get());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Application configure() {
|
||||
|
||||
return new PerformService();
|
||||
}
|
||||
public class AnagraphicTests extends CommonTest{
|
||||
|
||||
|
||||
@Test
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
package org.gcube.application.perform.service;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import javax.ws.rs.core.Application;
|
||||
|
||||
import org.gcube.application.perform.service.engine.utils.ISUtils;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.glassfish.jersey.test.JerseyTest;
|
||||
import org.junit.BeforeClass;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class CommonTest extends JerseyTest{
|
||||
|
||||
private static final Logger log= LoggerFactory.getLogger(AnagraphicTests.class);
|
||||
|
||||
@BeforeClass
|
||||
public static void init() throws MalformedURLException {
|
||||
LocalConfiguration.init(Paths.get("src/main/webapp/WEB-INF/config.properties").toUri().toURL());
|
||||
TokenSetter.set("/gcube/preprod/preVRE");
|
||||
ISUtils.setFixedToken(SecurityTokenProvider.instance.get());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Application configure() {
|
||||
|
||||
return new PerformService();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package org.gcube.application.perform.service;
|
||||
|
||||
import javax.ws.rs.client.WebTarget;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class ImportTests extends CommonTest{
|
||||
|
||||
@Test
|
||||
public void submit() {
|
||||
WebTarget target=
|
||||
target(ServiceConstants.Import.PATH).
|
||||
queryParam(ServiceConstants.Import.BATCH_TYPE_PARAMETER, "pino").
|
||||
queryParam(ServiceConstants.Import.FARM_ID_PARAMETER, 12682549).
|
||||
queryParam(ServiceConstants.Import.EXCEL_FILE_PARAMETER, "gino").
|
||||
queryParam(ServiceConstants.Import.EXCEL_FILE_VERSION_PARAMETER, "gino2.1");
|
||||
|
||||
System.out.println(target.getUri());
|
||||
Response resp=target.request().post(null);
|
||||
System.out.println("Status : "+resp.getStatus() );
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getAll() {
|
||||
WebTarget target=
|
||||
target(ServiceConstants.Import.PATH).
|
||||
path(12682549+"");
|
||||
System.out.println(target.getUri());
|
||||
Response resp=target.request().get();
|
||||
System.out.println(resp.getStatus() + " : "+ resp.readEntity(String.class));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue