use of javax.ws.rs.DefaultValue in project mod-inventory-storage by folio-org.
the class ItemStorageAPI method putItemStorageItemsByItemId.
@Validate
@Override
public void putItemStorageItemsByItemId(@PathParam("itemId") @NotNull String itemId, @QueryParam("lang") @DefaultValue("en") @Pattern(regexp = "[a-zA-Z]{2}") String lang, Item entity, java.util.Map<String, String> okapiHeaders, io.vertx.core.Handler<io.vertx.core.AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
String tenantId = okapiHeaders.get(TENANT_HEADER);
try {
PostgresClient postgresClient = PostgresClient.getInstance(vertxContext.owner(), TenantTool.calculateTenantId(tenantId));
vertxContext.runOnContext(v -> {
try {
getMaterialType(vertxContext.owner(), tenantId, entity, replyHandler -> {
int res = replyHandler.result();
if (res == 0) {
String message = "Can not add " + entity.getMaterialTypeId() + ". Material type not found";
log.error(message);
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(PutItemStorageItemsByItemIdResponse.withPlainBadRequest(message)));
} else if (res == -1) {
asyncResultHandler.handle(Future.succeededFuture(ItemStorageResource.PostItemStorageItemsResponse.withPlainInternalServerError("")));
} else {
try {
String[] fieldList = { "*" };
String query = String.format("id==%s", itemId);
CQLWrapper cql = getCQL(query, 1, 0);
log.info(String.format("SQL generated from CQL: %s", cql.toString()));
postgresClient.get(getTableName(query), Item.class, fieldList, cql, true, false, reply -> {
if (reply.succeeded()) {
List<Item> itemList = (List<Item>) reply.result().getResults();
if (itemList.size() == 1) {
try {
postgresClient.update("item", entity, entity.getId(), update -> {
try {
if (update.succeeded()) {
OutStream stream = new OutStream();
stream.setData(entity);
asyncResultHandler.handle(Future.succeededFuture(PutItemStorageItemsByItemIdResponse.withNoContent()));
} else {
String message = PgExceptionUtil.badRequestMessage(update.cause());
if (message != null) {
asyncResultHandler.handle(Future.succeededFuture(PutItemStorageItemsByItemIdResponse.withPlainBadRequest(message)));
} else {
asyncResultHandler.handle(Future.succeededFuture(PutItemStorageItemsByItemIdResponse.withPlainInternalServerError(update.cause().getMessage())));
}
}
} catch (Exception e) {
asyncResultHandler.handle(Future.succeededFuture(PostItemStorageItemsResponse.withPlainInternalServerError(e.getMessage())));
}
});
} catch (Exception e) {
asyncResultHandler.handle(Future.succeededFuture(PutItemStorageItemsByItemIdResponse.withPlainInternalServerError(e.getMessage())));
}
} else {
try {
postgresClient.save("item", entity.getId(), entity, save -> {
try {
if (save.succeeded()) {
OutStream stream = new OutStream();
stream.setData(entity);
asyncResultHandler.handle(Future.succeededFuture(PutItemStorageItemsByItemIdResponse.withNoContent()));
} else {
asyncResultHandler.handle(Future.succeededFuture(PutItemStorageItemsByItemIdResponse.withPlainInternalServerError(save.cause().getMessage())));
}
} catch (Exception e) {
asyncResultHandler.handle(Future.succeededFuture(PostItemStorageItemsResponse.withPlainInternalServerError(e.getMessage())));
}
});
} catch (Exception e) {
asyncResultHandler.handle(Future.succeededFuture(PutItemStorageItemsByItemIdResponse.withPlainInternalServerError(e.getMessage())));
}
}
} else {
asyncResultHandler.handle(Future.succeededFuture(PutItemStorageItemsByItemIdResponse.withPlainInternalServerError(reply.cause().getMessage())));
}
});
} catch (Exception e) {
asyncResultHandler.handle(Future.succeededFuture(ItemStorageResource.PostItemStorageItemsResponse.withPlainInternalServerError(e.getMessage())));
}
}
});
} catch (Exception e) {
asyncResultHandler.handle(Future.succeededFuture(ItemStorageResource.PostItemStorageItemsResponse.withPlainInternalServerError(e.getMessage())));
}
});
} catch (Exception e) {
asyncResultHandler.handle(Future.succeededFuture(ItemStorageResource.PostItemStorageItemsResponse.withPlainInternalServerError(e.getMessage())));
}
}
use of javax.ws.rs.DefaultValue in project mod-inventory-storage by folio-org.
the class ItemStorageAPI method postItemStorageItems.
@Validate
@Override
public void postItemStorageItems(@DefaultValue("en") @Pattern(regexp = "[a-zA-Z]{2}") String lang, Item entity, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
String tenantId = okapiHeaders.get(TENANT_HEADER);
try {
PostgresClient postgresClient = PostgresClient.getInstance(vertxContext.owner(), TenantTool.calculateTenantId(tenantId));
if (entity.getId() == null) {
entity.setId(UUID.randomUUID().toString());
}
vertxContext.runOnContext(v -> {
try {
/**
*This should be replaced with a foreign key / cache since a lookup into the MT table
* every time an item is inserted is wasteful and slows down the insert process
*/
getMaterialType(vertxContext.owner(), tenantId, entity, replyHandler -> {
int res = replyHandler.result();
if (res == 0) {
String message = "Can not add " + entity.getMaterialTypeId() + ". Material type not found";
log.error(message);
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(ItemStorageResource.PostItemStorageItemsResponse.withPlainBadRequest(message)));
return;
} else if (res == -1) {
asyncResultHandler.handle(Future.succeededFuture(ItemStorageResource.PostItemStorageItemsResponse.withPlainInternalServerError("")));
return;
} else {
Future<Location> temporaryLocationFuture;
if (entity.getTemporaryLocationId() != null) {
temporaryLocationFuture = getShelfLocation(vertxContext.owner(), tenantId, entity.getTemporaryLocationId());
} else {
temporaryLocationFuture = Future.succeededFuture();
}
temporaryLocationFuture.setHandler(compRes -> {
if (compRes.failed()) {
String message = "Attempting to specify non-existent location";
log.error(message);
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(ItemStorageResource.PostItemStorageItemsResponse.withPlainBadRequest(message)));
} else {
try {
postgresClient.save("item", entity.getId(), entity, reply -> {
try {
if (reply.succeeded()) {
OutStream stream = new OutStream();
stream.setData(entity);
asyncResultHandler.handle(Future.succeededFuture(ItemStorageResource.PostItemStorageItemsResponse.withJsonCreated(reply.result(), stream)));
} else {
String message = PgExceptionUtil.badRequestMessage(reply.cause());
if (message != null) {
asyncResultHandler.handle(Future.succeededFuture(ItemStorageResource.PostItemStorageItemsResponse.withPlainBadRequest(message)));
} else {
asyncResultHandler.handle(Future.succeededFuture(ItemStorageResource.PostItemStorageItemsResponse.withPlainInternalServerError(reply.cause().getMessage())));
}
}
} catch (Exception e) {
asyncResultHandler.handle(Future.succeededFuture(ItemStorageResource.PostItemStorageItemsResponse.withPlainInternalServerError(e.getMessage())));
}
});
} catch (Exception e) {
asyncResultHandler.handle(Future.succeededFuture(ItemStorageResource.PostItemStorageItemsResponse.withPlainInternalServerError(e.getMessage())));
}
}
});
}
});
} catch (Exception e) {
asyncResultHandler.handle(Future.succeededFuture(ItemStorageResource.PostItemStorageItemsResponse.withPlainInternalServerError(e.getMessage())));
}
});
} catch (Exception e) {
asyncResultHandler.handle(Future.succeededFuture(ItemStorageResource.PostItemStorageItemsResponse.withPlainInternalServerError(e.getMessage())));
}
}
use of javax.ws.rs.DefaultValue in project mica2 by obiba.
the class StudyStatesResource method listCollectionStudyStates.
@GET
@Path("/study-states")
@Timed
public List<Mica.StudySummaryDto> listCollectionStudyStates(@QueryParam("query") String query, @QueryParam("from") @DefaultValue("0") Integer from, @QueryParam("limit") Integer limit, @QueryParam("sort") @DefaultValue("id") String sort, @QueryParam("order") @DefaultValue("asc") String order, @QueryParam("type") String type, @QueryParam("exclude") List<String> excludes, @QueryParam("filter") @DefaultValue("ALL") String filter, @Context HttpServletResponse response) {
Stream<? extends EntityState> result;
long totalCount;
EntityStateFilter entityStateFilter = EntityStateFilter.valueOf(filter);
List<String> filteredIds = Strings.isNullOrEmpty(type) ? studyService.getIdsByStateFilter(entityStateFilter) : getStudyServiceByType(type).getIdsByStateFilter(entityStateFilter);
Searcher.IdFilter accessibleIdFilter = AccessibleIdFilterBuilder.newBuilder().aclService(subjectAclService).resources(getPermissionResources(type)).ids(filteredIds).build();
String ids = excludes.stream().map(s -> "id:" + s).collect(Collectors.joining(" "));
if (!Strings.isNullOrEmpty(ids)) {
if (Strings.isNullOrEmpty(query))
query = String.format("NOT(%s)", ids);
else
query += String.format(" AND NOT(%s)", ids);
}
if (limit == null)
limit = MAX_LIMIT;
if (limit < 0)
throw new IllegalArgumentException("limit cannot be negative");
DocumentService.Documents<Study> studyDocuments = draftStudyService.find(from, limit, sort, order, null, query, null, null, accessibleIdFilter);
totalCount = studyDocuments.getTotal();
response.addHeader("X-Total-Count", Long.toString(totalCount));
return studyDocuments.getList().stream().map(study -> dtos.asDto(study, studyService.getEntityState(study.getId()))).collect(toList());
}
use of javax.ws.rs.DefaultValue in project mica2 by obiba.
the class DraftProjectsResource method list.
@GET
@Path("/projects")
@Timed
public Mica.ProjectsDto list(@QueryParam("query") String query, @QueryParam("from") @DefaultValue("0") Integer from, @QueryParam("limit") Integer limit, @QueryParam("sort") @DefaultValue("id") String sort, @QueryParam("order") @DefaultValue("asc") String order, @QueryParam("filter") @DefaultValue("ALL") String filter, @Context HttpServletResponse response) {
EntityStateFilter entityStateFilter = EntityStateFilter.valueOf(filter);
List<String> filteredIds = projectService.getIdsByStateFilter(entityStateFilter);
Searcher.IdFilter accessibleIdFilter = AccessibleIdFilterBuilder.newBuilder().aclService(subjectAclService).resources(Lists.newArrayList("/draft/project")).ids(filteredIds).build();
if (limit == null)
limit = MAX_LIMIT;
if (limit < 0)
throw new IllegalArgumentException("limit cannot be negative");
DocumentService.Documents<Project> projectDocuments = draftProjectService.find(from, limit, sort, order, null, query, null, null, accessibleIdFilter);
long totalCount = projectDocuments.getTotal();
List<Mica.ProjectDto> result = projectDocuments.getList().stream().map(n -> dtos.asDto(n, true)).collect(toList());
Mica.ProjectsDto.Builder builder = Mica.ProjectsDto.newBuilder();
builder.setFrom(from).setLimit(limit).setTotal(Long.valueOf(totalCount).intValue());
builder.addAllProjects(result);
if (subjectAclService.isPermitted("/draft/project", "ADD")) {
builder.addActions("ADD");
}
return builder.build();
}
use of javax.ws.rs.DefaultValue in project mica2 by obiba.
the class DraftNetworksResource method list.
@GET
@Path("/networks")
@Timed
public List<Mica.NetworkSummaryDto> list(@QueryParam("study") String studyId, @QueryParam("query") String query, @QueryParam("from") @DefaultValue("0") Integer from, @QueryParam("limit") Integer limit, @QueryParam("sort") @DefaultValue("id") String sort, @QueryParam("order") @DefaultValue("asc") String order, @QueryParam("exclude") List<String> excludes, @QueryParam("filter") @DefaultValue("ALL") String filter, @Context HttpServletResponse response) {
Stream<Network> result;
long totalCount;
EntityStateFilter entityStateFilter = EntityStateFilter.valueOf(filter);
List<String> filteredIds = networkService.getIdsByStateFilter(entityStateFilter);
Searcher.IdFilter accessibleIdFilter = AccessibleIdFilterBuilder.newBuilder().aclService(subjectAclService).resources(Lists.newArrayList("/draft/network")).ids(filteredIds).build();
if (limit == null)
limit = MAX_LIMIT;
if (limit < 0)
throw new IllegalArgumentException("limit cannot be negative");
String ids = excludes.stream().map(s -> "id:" + s).collect(Collectors.joining(" "));
if (!Strings.isNullOrEmpty(ids)) {
if (Strings.isNullOrEmpty(query))
query = String.format("NOT(%s)", ids);
else
query += String.format(" AND NOT(%s)", ids);
}
DocumentService.Documents<Network> networkDocuments = draftNetworkService.find(from, limit, sort, order, studyId, query, null, null, accessibleIdFilter);
totalCount = networkDocuments.getTotal();
response.addHeader("X-Total-Count", Long.toString(totalCount));
return networkDocuments.getList().stream().map(network -> dtos.asSummaryDto(network, true)).collect(toList());
}
Aggregations