use of javax.validation.constraints.NotNull 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.validation.constraints.NotNull in project crnk-framework by crnk-project.
the class ValidationMetaProvider method getFilters.
@Override
public Collection<MetaFilter> getFilters() {
return Arrays.asList((MetaFilter) new MetaFilterBase() {
@Override
public void onInitialized(MetaElement element) {
if (element instanceof MetaAttribute) {
MetaAttribute attr = (MetaAttribute) element;
NotNull notNull = attr.getAnnotation(NotNull.class);
if (notNull != null) {
attr.setNullable(false);
}
}
}
});
}
use of javax.validation.constraints.NotNull in project mica2 by obiba.
the class DataAccessRequestService method save.
public DataAccessRequest save(@NotNull DataAccessRequest request) {
DataAccessRequest saved = request;
DataAccessRequest.Status from = null;
Iterable<Attachment> attachmentsToDelete = null;
Iterable<Attachment> attachmentsToSave = null;
if (request.isNew()) {
setAndLogStatus(saved, DataAccessRequest.Status.OPENED);
saved.setId(generateId());
attachmentsToSave = saved.getAttachments();
} else {
saved = dataAccessRequestRepository.findOne(request.getId());
if (saved != null) {
attachmentsToDelete = Sets.difference(Sets.newHashSet(saved.getAttachments()), Sets.newHashSet(request.getAttachments()));
attachmentsToSave = Sets.difference(Sets.newHashSet(request.getAttachments()), Sets.newHashSet(saved.getAttachments()));
from = saved.getStatus();
// validate the status
dataAccessRequestUtilService.checkStatusTransition(saved, request.getStatus());
saved.setStatus(request.getStatus());
if (request.hasStatusChangeHistory())
saved.setStatusChangeHistory(request.getStatusChangeHistory());
// merge beans
BeanUtils.copyProperties(request, saved, "id", "version", "createdBy", "createdDate", "lastModifiedBy", "lastModifiedDate", "statusChangeHistory");
} else {
saved = request;
setAndLogStatus(saved, DataAccessRequest.Status.OPENED);
}
}
schemaFormContentFileService.save(saved, dataAccessRequestRepository.findOne(request.getId()), String.format("/data-access-request/%s", saved.getId()));
if (attachmentsToSave != null)
attachmentsToSave.forEach(a -> {
fileStoreService.save(a.getId());
a.setJustUploaded(false);
attachmentRepository.save(a);
});
saved.setLastModifiedDate(DateTime.now());
dataAccessRequestRepository.saveWithReferences(saved);
if (attachmentsToDelete != null)
attachmentsToDelete.forEach(a -> fileStoreService.delete(a.getId()));
eventBus.post(new DataAccessRequestUpdatedEvent(saved));
sendNotificationEmails(saved, from);
return saved;
}
use of javax.validation.constraints.NotNull in project mica2 by obiba.
the class DataAccessRequestDtos method fromDto.
@NotNull
public DataAccessRequest fromDto(@NotNull Mica.DataAccessRequestDto dto) {
DataAccessRequest.Builder builder = DataAccessRequest.newBuilder();
builder.applicant(dto.getApplicant()).status(dto.getStatus());
if (dto.hasContent())
builder.content(dto.getContent());
DataAccessRequest request = builder.build();
if (dto.hasId())
request.setId(dto.getId());
if (dto.getAttachmentsCount() > 0) {
request.setAttachments(dto.getAttachmentsList().stream().map(attachmentDtos::fromDto).collect(Collectors.toList()));
}
TimestampsDtos.fromDto(dto.getTimestamps(), request);
return request;
}
use of javax.validation.constraints.NotNull in project mica2 by obiba.
the class NetworkDtos method asDtoBuilder.
@NotNull
Mica.NetworkDto.Builder asDtoBuilder(@NotNull Network network, boolean asDraft) {
Mica.NetworkDto.Builder builder = Mica.NetworkDto.newBuilder();
if (network.hasModel())
builder.setContent(JSONUtils.toJSON(network.getModel()));
//
builder.setId(network.getId()).addAllName(//
localizedStringDtos.asDto(network.getName())).addAllDescription(//
localizedStringDtos.asDto(network.getDescription())).addAllAcronym(localizedStringDtos.asDto(network.getAcronym()));
Mica.PermissionsDto permissionsDto = permissionsDtos.asDto(network);
NetworkState networkState = networkService.getEntityState(network.getId());
builder.setPublished(networkState.isPublished());
if (asDraft) {
//
builder.setTimestamps(TimestampsDtos.asDto(network)).setPublished(//
networkState.isPublished()).setExtension(Mica.EntityStateDto.state, entityStateDtos.asDto(networkState).setPermissions(permissionsDto).build());
}
builder.setPermissions(permissionsDto);
List<String> roles = micaConfigService.getConfig().getRoles();
if (network.getMemberships() != null) {
List<Mica.MembershipsDto> memberships = network.getMemberships().entrySet().stream().filter(e -> roles.contains(e.getKey())).map(e -> Mica.MembershipsDto.newBuilder().setRole(e.getKey()).addAllMembers(e.getValue().stream().map(m -> personDtos.asDto(m.getPerson(), asDraft)).collect(toList())).build()).collect(toList());
builder.addAllMemberships(memberships);
}
List<BaseStudy> publishedStudies = publishedStudyService.findByIds(network.getStudyIds());
Set<String> publishedStudyIds = publishedStudies.stream().map(AbstractGitPersistable::getId).collect(Collectors.toSet());
Sets.SetView<String> unpublishedStudyIds = Sets.difference(ImmutableSet.copyOf(network.getStudyIds().stream().filter(sId -> asDraft && subjectAclService.isPermitted("/draft/individual-study", "VIEW", sId) || subjectAclService.isAccessible("/individual-study", sId)).collect(toList())), publishedStudyIds);
if (!publishedStudies.isEmpty()) {
Map<String, Long> datasetVariableCounts = asDraft ? null : datasetVariableService.getCountByStudyIds(Lists.newArrayList(publishedStudyIds));
publishedStudies.forEach(study -> {
builder.addStudyIds(study.getId());
builder.addStudySummaries(studySummaryDtos.asDtoBuilder(study, true, datasetVariableCounts == null ? 0 : datasetVariableCounts.get(study.getId())));
});
}
unpublishedStudyIds.forEach(studyId -> {
try {
builder.addStudySummaries(studySummaryDtos.asDto(studyId));
builder.addStudyIds(studyId);
} catch (NoSuchEntityException e) {
log.warn("Study not found in network {}: {}", network.getId(), studyId);
// ignore
}
});
if (network.getLogo() != null) {
builder.setLogo(attachmentDtos.asDto(network.getLogo()));
}
network.getNetworkIds().stream().filter(nId -> asDraft && subjectAclService.isPermitted("/draft/network", "VIEW", nId) || subjectAclService.isAccessible("/network", nId)).forEach(nId -> {
try {
builder.addNetworkSummaries(networkSummaryDtos.asDtoBuilder(nId, asDraft));
builder.addNetworkIds(nId);
} catch (NoSuchEntityException e) {
log.warn("Network not found in network {}: {}", network.getId(), nId);
// ignore
}
});
return builder;
}
Aggregations