git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-publishing/gCat-Feeder-Suite@178687 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
711b099a2f
commit
f2bd178877
|
@ -72,6 +72,16 @@
|
|||
<groupId>org.glassfish.jersey.containers</groupId>
|
||||
<artifactId>jersey-container-servlet</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- Persistence -->
|
||||
<dependency>
|
||||
<groupId>org.eclipse.persistence</groupId>
|
||||
<artifactId>eclipselink</artifactId>
|
||||
<version>2.6.6</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- test -->
|
||||
<dependency>
|
||||
|
@ -96,7 +106,14 @@
|
|||
<artifactId>jersey-weld2-se</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<version>1.3.170</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
package org.gcube.data.publishing.gCatFeeder.service.engine;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
||||
public interface ConnectionManager {
|
||||
|
||||
|
||||
public Connection getConnection();
|
||||
|
||||
}
|
|
@ -2,8 +2,8 @@ package org.gcube.data.publishing.gCatFeeder.service.engine;
|
|||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.gcube.data.publishing.gCatFeeder.service.engine.impl.persistence.DBQueryDescriptor;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.ExecutionDescriptor;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.ExecutionDescriptorFilter;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.ExecutionRequest;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.fault.CollectorNotFound;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.fault.DescriptorNotFound;
|
||||
|
@ -13,8 +13,8 @@ import org.gcube.data.publishing.gCatFeeder.service.model.fault.PersistenceError
|
|||
|
||||
public interface FeederEngine {
|
||||
|
||||
public Collection<ExecutionDescriptor> get(ExecutionDescriptorFilter filter) throws PersistenceError, InvalidRequest;
|
||||
public ExecutionDescriptor getById(String id) throws PersistenceError, ElementNotFound, InvalidRequest;
|
||||
public Collection<ExecutionDescriptor> get(DBQueryDescriptor filter) throws PersistenceError, InvalidRequest;
|
||||
public ExecutionDescriptor getById(Long id) throws PersistenceError, ElementNotFound, InvalidRequest;
|
||||
public ExecutionDescriptor submit(ExecutionRequest req) throws InternalError, CollectorNotFound, DescriptorNotFound, PersistenceError, InvalidRequest;
|
||||
|
||||
|
||||
|
|
|
@ -2,8 +2,8 @@ package org.gcube.data.publishing.gCatFeeder.service.engine;
|
|||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.gcube.data.publishing.gCatFeeder.service.engine.impl.persistence.DBQueryDescriptor;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.ExecutionDescriptor;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.ExecutionDescriptorFilter;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.ExecutionRequest;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.fault.ElementNotFound;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.fault.InvalidRequest;
|
||||
|
@ -12,12 +12,11 @@ import org.gcube.data.publishing.gCatFeeder.service.model.fault.PersistenceError
|
|||
public interface PersistenceManager {
|
||||
|
||||
public ExecutionDescriptor create(ExecutionRequest request) throws PersistenceError,InvalidRequest;
|
||||
public ExecutionDescriptor getById(String id)throws PersistenceError,ElementNotFound,InvalidRequest;
|
||||
public Collection<ExecutionDescriptor> get(ExecutionDescriptorFilter filter)throws PersistenceError,InvalidRequest;
|
||||
public Collection<ExecutionDescriptor> get(DBQueryDescriptor filter)throws PersistenceError,InvalidRequest;
|
||||
|
||||
|
||||
// DIRECT QUERIES
|
||||
public boolean update(ExecutionDescriptor toUpdate)throws PersistenceError,ElementNotFound;
|
||||
public boolean update(ExecutionDescriptor toUpdate)throws PersistenceError,ElementNotFound,InvalidRequest;
|
||||
|
||||
/**
|
||||
* Updates status only if current status value is PENDING
|
||||
|
@ -27,6 +26,7 @@ public interface PersistenceManager {
|
|||
* @throws PersistenceError
|
||||
* @throws ElementNotFound
|
||||
*/
|
||||
public boolean acquire(String id)throws PersistenceError,ElementNotFound;
|
||||
public boolean acquire(Long id)throws PersistenceError,ElementNotFound,InvalidRequest;
|
||||
public ExecutionDescriptor getById(Long id) throws PersistenceError, ElementNotFound, InvalidRequest;
|
||||
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package org.gcube.data.publishing.gCatFeeder.service.engine.impl;
|
|||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.gcube.data.publishing.gCatFeeder.service.engine.CatalogueControllersManager;
|
||||
|
@ -11,8 +10,8 @@ import org.gcube.data.publishing.gCatFeeder.service.engine.CollectorsManager;
|
|||
import org.gcube.data.publishing.gCatFeeder.service.engine.ExecutionManager;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.engine.FeederEngine;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.engine.PersistenceManager;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.engine.impl.persistence.DBQueryDescriptor;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.ExecutionDescriptor;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.ExecutionDescriptorFilter;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.ExecutionRequest;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.fault.CollectorNotFound;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.fault.DescriptorNotFound;
|
||||
|
@ -44,12 +43,12 @@ public class FeederEngineImpl implements FeederEngine {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Collection<ExecutionDescriptor> get(ExecutionDescriptorFilter filter) throws PersistenceError, InvalidRequest {
|
||||
public Collection<ExecutionDescriptor> get(DBQueryDescriptor filter) throws PersistenceError, InvalidRequest {
|
||||
return persistence.get(filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExecutionDescriptor getById(String id) throws PersistenceError, ElementNotFound, InvalidRequest {
|
||||
public ExecutionDescriptor getById(Long id) throws PersistenceError, ElementNotFound, InvalidRequest {
|
||||
return persistence.getById(id);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,46 +1,181 @@
|
|||
package org.gcube.data.publishing.gCatFeeder.service.engine.impl;
|
||||
|
||||
import static org.gcube.data.publishing.gCatFeeder.service.engine.impl.persistence.DBField.ExecutionDescriptor.ID;
|
||||
import static org.gcube.data.publishing.gCatFeeder.service.engine.impl.persistence.DBField.ExecutionDescriptor.fields;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.gcube.data.publishing.gCatFeeder.service.engine.ConnectionManager;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.engine.PersistenceManager;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.engine.impl.persistence.DBQueryDescriptor;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.engine.impl.persistence.Queries;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.ExecutionDescriptor;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.ExecutionDescriptorFilter;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.ExecutionRequest;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.fault.ElementNotFound;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.fault.InvalidRequest;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.fault.PersistenceError;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class PersistenceManagerImpl implements PersistenceManager {
|
||||
|
||||
|
||||
private static final Logger log= LoggerFactory.getLogger(PersistenceManagerImpl.class);
|
||||
|
||||
@Inject
|
||||
ConnectionManager connections;
|
||||
|
||||
|
||||
@Override
|
||||
public ExecutionDescriptor create(ExecutionRequest request) throws PersistenceError, InvalidRequest {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
Connection conn=null;
|
||||
try {
|
||||
log.debug("Looking for execution similar to request {} ",request);
|
||||
conn=connections.getConnection();
|
||||
DBQueryDescriptor queryDescriptor=Queries.translateObject(request);
|
||||
PreparedStatement ps=Queries.GET_SIMILAR.get(conn, queryDescriptor);
|
||||
ResultSet rs=ps.executeQuery();
|
||||
if(rs.next()) {
|
||||
log.debug("Found similar, returning it..");
|
||||
// FOUND SIMILAR OPTION
|
||||
return Queries.translateRow(rs);
|
||||
}else {
|
||||
log.debug("Inserting request ..");
|
||||
// PREPARE REQUEST
|
||||
|
||||
PreparedStatement psInsert=Queries.INSERT_NEW.prepare(conn, Statement.RETURN_GENERATED_KEYS);
|
||||
psInsert.executeUpdate();
|
||||
ResultSet rsId=psInsert.getGeneratedKeys();
|
||||
rsId.next();
|
||||
Long generatedId=rsId.getLong(ID);
|
||||
|
||||
DBQueryDescriptor getQuery=new DBQueryDescriptor(fields.get(ID), generatedId);
|
||||
PreparedStatement psGet=Queries.GET_BY_ID.get(conn, getQuery);
|
||||
rs=psGet.executeQuery();
|
||||
rs.next();
|
||||
ExecutionDescriptor toReturn= Queries.translateRow(rs);
|
||||
conn.commit();
|
||||
return toReturn;
|
||||
}
|
||||
}catch(InvalidRequest e) {
|
||||
throw e;
|
||||
}catch(Throwable t) {
|
||||
throw new PersistenceError(t);
|
||||
}finally {
|
||||
try {
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
throw new PersistenceError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExecutionDescriptor getById(String id) throws PersistenceError, ElementNotFound, InvalidRequest {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
public ExecutionDescriptor getById(Long id) throws PersistenceError, ElementNotFound, InvalidRequest {
|
||||
Connection conn=null;
|
||||
try {
|
||||
log.debug("Querying by ID {} ",id);
|
||||
conn=connections.getConnection();
|
||||
DBQueryDescriptor getQuery=new DBQueryDescriptor(fields.get(ID), id);
|
||||
PreparedStatement psGet=Queries.GET_BY_ID.get(conn, getQuery);
|
||||
ResultSet rs=psGet.executeQuery();
|
||||
if(rs.next())
|
||||
return Queries.translateRow(rs);
|
||||
else throw new ElementNotFound("Unable to locate Element with ID "+id);
|
||||
}catch(InvalidRequest e) {
|
||||
throw e;
|
||||
}catch(Throwable t) {
|
||||
throw new PersistenceError(t);
|
||||
}finally {
|
||||
try {
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
throw new PersistenceError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ExecutionDescriptor> get(ExecutionDescriptorFilter filter)
|
||||
public Collection<ExecutionDescriptor> get(DBQueryDescriptor filter)
|
||||
throws PersistenceError, InvalidRequest {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
Connection conn=null;
|
||||
try {
|
||||
log.debug("Looking for execution according to filter {} ",filter);
|
||||
conn=connections.getConnection();
|
||||
ArrayList<ExecutionDescriptor> toReturn=new ArrayList<>();
|
||||
PreparedStatement psGet=Queries.GET_ALL.get(conn, filter);
|
||||
ResultSet rs=psGet.executeQuery();
|
||||
while(rs.next())
|
||||
toReturn.add(Queries.translateRow(rs));
|
||||
return toReturn;
|
||||
}catch(InvalidRequest e) {
|
||||
throw e;
|
||||
}catch(Throwable t) {
|
||||
throw new PersistenceError(t);
|
||||
}finally {
|
||||
try {
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
throw new PersistenceError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update(ExecutionDescriptor toUpdate) throws PersistenceError, ElementNotFound {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
public boolean update(ExecutionDescriptor toUpdate) throws PersistenceError, ElementNotFound,InvalidRequest {
|
||||
Connection conn=null;
|
||||
try {
|
||||
log.debug("Updateing {} ",toUpdate);
|
||||
conn=connections.getConnection();
|
||||
PreparedStatement ps=Queries.UPDATE.get(conn, Queries.translateObject(toUpdate));
|
||||
int result=ps.executeUpdate();
|
||||
conn.commit();
|
||||
return result>0;
|
||||
}catch(InvalidRequest e) {
|
||||
throw e;
|
||||
}catch(Throwable t) {
|
||||
throw new PersistenceError(t);
|
||||
}finally {
|
||||
try {
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
throw new PersistenceError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acquire(String id) throws PersistenceError, ElementNotFound {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
public boolean acquire(Long id) throws PersistenceError, ElementNotFound,InvalidRequest {
|
||||
Connection conn=null;
|
||||
try {
|
||||
log.debug("Acquiring {} ",id);
|
||||
conn=connections.getConnection();
|
||||
PreparedStatement ps=Queries.ACQUIRE.get(conn, new DBQueryDescriptor(fields.get(ID), id));
|
||||
int result=ps.executeUpdate();
|
||||
conn.commit();
|
||||
return result>0;
|
||||
}catch(InvalidRequest e) {
|
||||
throw e;
|
||||
}catch(Throwable t) {
|
||||
throw new PersistenceError(t);
|
||||
}finally {
|
||||
try {
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
throw new PersistenceError(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
package org.gcube.data.publishing.gCatFeeder.service.engine.impl.persistence;
|
||||
|
||||
import java.sql.Types;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class DBField {
|
||||
|
||||
public static final class ExecutionDescriptor{
|
||||
public static final String TABLE="executions";
|
||||
|
||||
public static final Map<String,DBField> fields=new HashMap<>();
|
||||
|
||||
public static final String ID="id";
|
||||
public static final String START="start_time";
|
||||
public static final String END="end_time";
|
||||
public static final String STATUS="status";
|
||||
public static final String CALLER="caller";
|
||||
|
||||
static {
|
||||
fields.put(ID, new DBField(Types.BIGINT,ID));
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public DBField(int type, String fieldName) {
|
||||
super();
|
||||
this.type = type;
|
||||
this.fieldName = fieldName;
|
||||
}
|
||||
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getFieldName() {
|
||||
return fieldName;
|
||||
}
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
private int type;
|
||||
private String fieldName;
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((fieldName == null) ? 0 : fieldName.hashCode());
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
DBField other = (DBField) obj;
|
||||
if (fieldName == null) {
|
||||
if (other.fieldName != null)
|
||||
return false;
|
||||
} else if (!fieldName.equals(other.fieldName))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DBField ["+fieldName+"]";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package org.gcube.data.publishing.gCatFeeder.service.engine.impl.persistence;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class DBQueryDescriptor {
|
||||
|
||||
private Map<DBField,Object> condition;
|
||||
|
||||
public DBQueryDescriptor() {
|
||||
condition=new HashMap<DBField,Object>();
|
||||
}
|
||||
|
||||
public Map<DBField, Object> getCondition() {
|
||||
return condition;
|
||||
}
|
||||
|
||||
|
||||
public DBQueryDescriptor(Map<DBField, Object> condition) {
|
||||
super();
|
||||
this.condition = condition;
|
||||
}
|
||||
|
||||
public DBQueryDescriptor(DBField field, Object value) {
|
||||
this();
|
||||
add(field,value);
|
||||
}
|
||||
|
||||
|
||||
public String toString() {
|
||||
StringBuilder builder=new StringBuilder();
|
||||
for(Entry<DBField,Object> entry : condition.entrySet()) {
|
||||
builder.append(String.format("%1$s = %2$s AND ", entry.getKey().getFieldName(),entry.getValue()));
|
||||
}
|
||||
return builder.substring(0,builder.lastIndexOf(" AND ")).toString();
|
||||
}
|
||||
|
||||
public DBQueryDescriptor add(DBField field,Object obj) {
|
||||
condition.put(field, obj);
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package org.gcube.data.publishing.gCatFeeder.service.engine.impl.persistence;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.ExecutionDescriptor;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.ExecutionRequest;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.fault.InvalidRequest;
|
||||
|
||||
public class Queries {
|
||||
|
||||
public static final Query GET_BY_ID;
|
||||
|
||||
public static final Query UPDATE;
|
||||
|
||||
public static final Query ACQUIRE;
|
||||
|
||||
public static final Query GET_ALL;
|
||||
|
||||
public static final Query GET_SIMILAR;
|
||||
|
||||
|
||||
public static final Query INSERT_NEW;
|
||||
|
||||
public static final ExecutionDescriptor translateRow(ResultSet row) {
|
||||
|
||||
}
|
||||
|
||||
public static final DBQueryDescriptor translateObject(ExecutionDescriptor descriptor) throws InvalidRequest{
|
||||
|
||||
}
|
||||
|
||||
public static final DBQueryDescriptor translateObject(ExecutionRequest request) throws InvalidRequest{
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
package org.gcube.data.publishing.gCatFeeder.service.engine.impl.persistence;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.gcube.common.clients.exceptions.InvalidRequestException;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.fault.InvalidRequest;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class Query {
|
||||
|
||||
protected static final Logger log= LoggerFactory.getLogger(Query.class);
|
||||
|
||||
protected final String query;
|
||||
protected final ArrayList<DBField> psFields;
|
||||
|
||||
public Query(String query,DBField[] fields) {
|
||||
this.query=query;
|
||||
this.psFields=fields!=null?new ArrayList<>(Arrays.asList(fields)):null;
|
||||
}
|
||||
|
||||
|
||||
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, InvalidRequest {
|
||||
PreparedStatement ps=prepare(conn);
|
||||
return fill(ps,desc);
|
||||
}
|
||||
|
||||
public PreparedStatement fill(PreparedStatement ps,DBQueryDescriptor desc) throws SQLException, InvalidRequest{
|
||||
log.debug("Setting VALUES {} for Query {} ",desc,getQuery());
|
||||
ArrayList<DBField> fields=getPSFields();
|
||||
for(int i=0;i<fields.size();i++) {
|
||||
DBField field=fields.get(i);
|
||||
if(!desc.getCondition().containsKey(field))
|
||||
throw new InvalidRequestException("Missing field "+field);
|
||||
else {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -2,9 +2,10 @@ package org.gcube.data.publishing.gCatFeeder.service.model;
|
|||
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
public class ExecutionDescriptor {
|
||||
|
||||
private String id;
|
||||
private Long id;
|
||||
private Set<String> collectors;
|
||||
private Set<String> catalogues;
|
||||
|
||||
|
@ -17,10 +18,12 @@ public class ExecutionDescriptor {
|
|||
private String reportUrl;
|
||||
|
||||
|
||||
public String getId() {
|
||||
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(String id) {
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
public Set<String> getCollectors() {
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
package org.gcube.data.publishing.gCatFeeder.service.model;
|
||||
|
||||
public class ExecutionDescriptorFilter {
|
||||
|
||||
}
|
|
@ -18,8 +18,8 @@ import javax.ws.rs.core.UriInfo;
|
|||
import org.gcube.data.publishing.gCatFeeder.service.GCatFeederManager;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.ServiceConstants;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.engine.FeederEngine;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.engine.impl.persistence.DBQueryDescriptor;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.ExecutionDescriptor;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.ExecutionDescriptorFilter;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.ExecutionRequest;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.fault.ElementNotFound;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.fault.InvalidRequest;
|
||||
|
@ -80,7 +80,7 @@ public class Executions {
|
|||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response getAll() {
|
||||
try {
|
||||
ExecutionDescriptorFilter filter=new ExecutionDescriptorFilter();
|
||||
DBQueryDescriptor filter=new DBQueryDescriptor();
|
||||
Collection<ExecutionDescriptor> toReturn=engine.get(filter);
|
||||
GenericEntity<Collection<ExecutionDescriptor>> entity=new GenericEntity<Collection<ExecutionDescriptor>>(toReturn) {};
|
||||
return Response.ok(entity).build();
|
||||
|
@ -100,7 +100,7 @@ public class Executions {
|
|||
@GET
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Path("{"+ServiceConstants.Executions.EXECUTION_ID_PARAMETER+"}")
|
||||
public ExecutionDescriptor get(@PathParam(ServiceConstants.Executions.EXECUTION_ID_PARAMETER) String executionId) {
|
||||
public ExecutionDescriptor get(@PathParam(ServiceConstants.Executions.EXECUTION_ID_PARAMETER) Long executionId) {
|
||||
try {
|
||||
return engine.getById(executionId);
|
||||
} catch (PersistenceError e) {
|
||||
|
|
|
@ -3,7 +3,6 @@ package org.gcube.data.publishing.gCatFeeder.service;
|
|||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import javax.ws.rs.core.Application;
|
||||
|
||||
|
@ -27,40 +26,9 @@ import org.junit.Before;
|
|||
|
||||
public class BaseTest extends JerseyTest{
|
||||
|
||||
@Inject
|
||||
ExecutionManager executions;
|
||||
|
||||
|
||||
@Inject
|
||||
CollectorsManager collectors;
|
||||
|
||||
@Inject
|
||||
CatalogueControllersManager controllers;
|
||||
|
||||
|
||||
@Before
|
||||
public void init() throws IOException, SQLException{
|
||||
// // basic init
|
||||
// try {
|
||||
// collectors.init();
|
||||
// controllers.init();
|
||||
// } catch (InternalError e) {
|
||||
// throw new RuntimeException("Initialization Error",e);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// // scope init
|
||||
// try {
|
||||
// collectors.initInScope();
|
||||
// controllers.initInScope();
|
||||
// } catch (InternalError ex) {
|
||||
// throw new RuntimeException("Initialization Error",ex);
|
||||
// }
|
||||
//
|
||||
// executions.load();
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ import javax.ws.rs.client.WebTarget;
|
|||
import javax.ws.rs.core.Response;
|
||||
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.ExecutionDescriptor;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.ExecutionStatus;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ExecutionsTest extends BaseTest {
|
||||
|
@ -32,10 +31,10 @@ public class ExecutionsTest extends BaseTest {
|
|||
// System.out.println(resp.getStatus() + " : "+ resp.readEntity(String.class));
|
||||
|
||||
ExecutionDescriptor desc=resp.readEntity(ExecutionDescriptor.class);
|
||||
String id=desc.getId();
|
||||
Long id=desc.getId();
|
||||
|
||||
WebTarget pollTarget=
|
||||
target(ServiceConstants.Executions.PATH).path(id);
|
||||
target(ServiceConstants.Executions.PATH).path(id+"");
|
||||
|
||||
boolean end=false;
|
||||
do {
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
package org.gcube.data.publishing.gCatFeeder.service.mockups;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.gcube.data.publishing.gCatFeeder.service.engine.Infrastructure;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.engine.PersistenceManager;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.engine.impl.persistence.DBQueryDescriptor;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.ExecutionDescriptor;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.ExecutionDescriptorFilter;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.ExecutionRequest;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.ExecutionStatus;
|
||||
import org.gcube.data.publishing.gCatFeeder.service.model.fault.ElementNotFound;
|
||||
|
@ -20,6 +19,8 @@ import org.gcube.data.publishing.gCatFeeder.service.model.fault.PersistenceError
|
|||
|
||||
public class PersistenceManagerMock implements PersistenceManager {
|
||||
|
||||
private static AtomicLong idCounter=new AtomicLong(Long.MIN_VALUE);
|
||||
|
||||
@Inject
|
||||
private Infrastructure infrastructure;
|
||||
|
||||
|
@ -30,16 +31,16 @@ public class PersistenceManagerMock implements PersistenceManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ExecutionDescriptor getById(String id) throws PersistenceError, ElementNotFound{
|
||||
public ExecutionDescriptor getById(Long id) throws PersistenceError, ElementNotFound{
|
||||
if(theMap.containsKey(id))
|
||||
return theMap.get(id);
|
||||
else throw new ElementNotFound("Unable to find request with id "+id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ExecutionDescriptor> get(ExecutionDescriptorFilter filter)
|
||||
public Collection<ExecutionDescriptor> get(DBQueryDescriptor filter)
|
||||
throws PersistenceError, InvalidRequest {
|
||||
return Collections.emptyList();
|
||||
return theMap.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -52,7 +53,7 @@ public class PersistenceManagerMock implements PersistenceManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean acquire(String id) throws PersistenceError, ElementNotFound {
|
||||
public boolean acquire(Long id) throws PersistenceError, ElementNotFound {
|
||||
ExecutionDescriptor desc=getById(id);
|
||||
if(desc.getStatus().equals(ExecutionStatus.PENDING))
|
||||
desc.setStatus(ExecutionStatus.RUNNING);
|
||||
|
@ -61,7 +62,7 @@ public class PersistenceManagerMock implements PersistenceManager {
|
|||
|
||||
// Actual persistence in map
|
||||
|
||||
private ConcurrentHashMap<String,ExecutionDescriptor> theMap=new ConcurrentHashMap<>();
|
||||
private ConcurrentHashMap<Long,ExecutionDescriptor> theMap=new ConcurrentHashMap<>();
|
||||
|
||||
private ExecutionDescriptor getEquivalent(ExecutionRequest req) {
|
||||
ExecutionDescriptor toReturn=new ExecutionDescriptor();
|
||||
|
@ -72,7 +73,7 @@ public class PersistenceManagerMock implements PersistenceManager {
|
|||
toReturn.setCatalogues(req.getToInvokeControllers());
|
||||
toReturn.setCollectors(req.getToInvokeCollectors());
|
||||
|
||||
toReturn.setId(UUID.randomUUID().toString());
|
||||
toReturn.setId(idCounter.incrementAndGet());
|
||||
|
||||
toReturn.setStatus(ExecutionStatus.PENDING);
|
||||
theMap.put(toReturn.getId(), toReturn);
|
||||
|
|
Loading…
Reference in New Issue