repackaging
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-service@160680 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
84ce8c1853
commit
9c7ccaf84c
|
@ -0,0 +1,23 @@
|
|||
package org.gcube.accounting.service.resources;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
import javax.ws.rs.ext.ExceptionMapper;
|
||||
import javax.ws.rs.ext.Provider;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@Provider
|
||||
public class AccountingServiceExceptionMapper implements ExceptionMapper<Exception> {
|
||||
|
||||
@Override
|
||||
public Response toResponse(Exception exception) {
|
||||
Status status = Status.INTERNAL_SERVER_ERROR;
|
||||
String entity = exception.getMessage();
|
||||
MediaType mediaType = MediaType.TEXT_PLAIN_TYPE;
|
||||
return Response.status(status).entity(entity).type(mediaType).build();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package org.gcube.accounting.service.resources;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
|
||||
import org.gcube.accounting.persistence.AccountingPersistence;
|
||||
import org.gcube.accounting.persistence.AccountingPersistenceFactory;
|
||||
import org.gcube.accounting.service.AccountingResource;
|
||||
import org.gcube.accounting.service.AccountingServiceInitializer;
|
||||
import org.gcube.documentstore.records.DSMapper;
|
||||
import org.gcube.documentstore.records.Record;
|
||||
import org.gcube.smartgears.annotations.ManagedBy;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Alessandro Pieve (alessandro.pieve@isti.cnr.it)
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@ManagedBy(AccountingServiceInitializer.class)
|
||||
@Path(ResourceInsert.INSERT_PATH_PART)
|
||||
public class ResourceInsert {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(ResourceInsert.class);
|
||||
|
||||
public static final String INSERT_PATH_PART = "insert";
|
||||
public static final String RECORD_PATH_PART = "record";
|
||||
|
||||
@POST
|
||||
@Path(RECORD_PATH_PART)
|
||||
@Consumes({MediaType.TEXT_PLAIN, AccountingResource.APPLICATION_JSON_CHARSET_UTF_8})
|
||||
public Response add(String json) throws Exception {
|
||||
|
||||
log.debug("Going to account : {}", json);
|
||||
|
||||
AccountingPersistence accountingPersistence = AccountingPersistenceFactory.getPersistence();
|
||||
|
||||
List<Record> records = DSMapper.unmarshalList(json);
|
||||
for(Record record : records) {
|
||||
accountingPersistence.account(record);
|
||||
}
|
||||
return Response.status(Status.CREATED).build();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package org.gcube.accounting.service.resources;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import org.gcube.accounting.analytics.persistence.AccountingPersistenceQuery;
|
||||
import org.gcube.accounting.analytics.persistence.AccountingPersistenceQueryFactory;
|
||||
import org.gcube.accounting.service.AccountingResource;
|
||||
import org.gcube.accounting.service.AccountingServiceInitializer;
|
||||
import org.gcube.smartgears.annotations.ManagedBy;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Alessandro Pieve (alessandro.pieve@isti.cnr.it)
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@ManagedBy(AccountingServiceInitializer.class)
|
||||
@Path(ResourceQuery.QUERY_PATH_PART)
|
||||
public class ResourceQuery {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(ResourceQuery.class);
|
||||
|
||||
public static final String QUERY_PATH_PART = "query";
|
||||
public static final String RECORD_PATH_PART = "record";
|
||||
|
||||
public static final String TYPE_PATH_PART = "type";
|
||||
public static final String RECORD_ID_PATH_PART = "recordID";
|
||||
|
||||
@GET
|
||||
@Path(RECORD_PATH_PART + "/{" + TYPE_PATH_PART + "}/{" + RECORD_ID_PATH_PART + "}/")
|
||||
@Produces(AccountingResource.APPLICATION_JSON_CHARSET_UTF_8)
|
||||
public Response get(@NotNull @PathParam(TYPE_PATH_PART) String type,
|
||||
@NotNull @PathParam(RECORD_ID_PATH_PART) String recordId) throws Exception {
|
||||
|
||||
log.debug("Requested {} having ID {}", type, recordId);
|
||||
AccountingPersistenceQuery accountingPersistenceQuery = AccountingPersistenceQueryFactory.getInstance();
|
||||
|
||||
String record = accountingPersistenceQuery.getRecord(recordId, type);
|
||||
return Response.status(200).entity(record).type(AccountingResource.APPLICATION_JSON_CHARSET_UTF_8).build();
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
package org.gcube.accounting.service.resources;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
|
||||
import org.gcube.accounting.analytics.persistence.AccountingPersistenceQuery;
|
||||
import org.gcube.accounting.analytics.persistence.AccountingPersistenceQueryFactory;
|
||||
import org.gcube.accounting.persistence.AccountingPersistence;
|
||||
import org.gcube.accounting.persistence.AccountingPersistenceFactory;
|
||||
import org.gcube.accounting.service.AccountingResource;
|
||||
import org.gcube.accounting.service.AccountingServiceInitializer;
|
||||
import org.gcube.smartgears.annotations.ManagedBy;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Alessandro Pieve (alessandro.pieve@isti.cnr.it)
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@ManagedBy(AccountingServiceInitializer.class)
|
||||
@Path(ServiceState.STATE_PATH_PART)
|
||||
public class ServiceState {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ServiceState.class);
|
||||
|
||||
public static final String STATE_PATH_PART = "state";
|
||||
|
||||
public static final String SERVICE = "service";
|
||||
public static final String RUNNING = "running";
|
||||
public static final String CONTEXT = "context";
|
||||
public static final String QUERY_CONNECTION_UP = "queryConnection";
|
||||
public static final String INSERT_CONNECTION_UP = "insertConnection";
|
||||
|
||||
@GET
|
||||
@Path("/")
|
||||
@Produces(AccountingResource.APPLICATION_JSON_CHARSET_UTF_8)
|
||||
public Response getState() throws JSONException {
|
||||
String context = AccountingServiceInitializer.getCurrentContext();
|
||||
logger.debug("Getting Service Status fro context {}", context);
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.append(SERVICE, RUNNING);
|
||||
jsonObject.append(CONTEXT, context);
|
||||
|
||||
Status responseStatus = Status.SERVICE_UNAVAILABLE;
|
||||
|
||||
AccountingPersistence accountingPersistence = AccountingPersistenceFactory.getPersistence();
|
||||
try {
|
||||
jsonObject.append(INSERT_CONNECTION_UP, accountingPersistence.isConnectionActive());
|
||||
} catch(Exception e) {
|
||||
jsonObject.append(INSERT_CONNECTION_UP, false);
|
||||
}
|
||||
|
||||
AccountingPersistenceQuery accountingPersistenceQuery = AccountingPersistenceQueryFactory.getInstance();
|
||||
try {
|
||||
jsonObject.append(QUERY_CONNECTION_UP, accountingPersistenceQuery.isConnectionActive());
|
||||
} catch(Exception e) {
|
||||
jsonObject.append(QUERY_CONNECTION_UP, false);
|
||||
}
|
||||
|
||||
return Response.status(responseStatus).entity(jsonObject.toString()).build();
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue