50 lines
1.5 KiB
Java
50 lines
1.5 KiB
Java
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";
|
|
|
|
@POST
|
|
@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();
|
|
}
|
|
|
|
}
|