use of eu.bcvsolutions.idm.core.api.exception.ResultCodeException in project CzechIdMng by bcvsolutions.
the class DefaultCryptService method initCipher.
/**
* Method init {@link Cipher} by encrypt mode {@link Cipher}.
* Cipher is not thread safe and is not reusable, has to be constructed for all requests.
*
* @param encryptMode
* @param key
* @throws InvalidKeyException
*/
private Cipher initCipher(int encryptMode, SecretKey key) throws InvalidKeyException {
if (key == null) {
return null;
}
//
Cipher cipher = null;
try {
cipher = Cipher.getInstance(ALGORITHM + "/" + ALGORITHM_MODE + "/" + ALGORITHM_PADDING);
cipher.init(encryptMode, key, new IvParameterSpec(IV));
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidAlgorithmParameterException e) {
LOG.error("Cipher can't be initialized!");
throw new ResultCodeException(CoreResultCode.CRYPT_INITIALIZATION_PROBLEM, ImmutableMap.of("algorithm", ALGORITHM), e);
}
return cipher;
}
use of eu.bcvsolutions.idm.core.api.exception.ResultCodeException in project CzechIdMng by bcvsolutions.
the class WorkflowDefinitionController method getDiagram.
/**
* Generate process definition diagram image
*
* @param definitionKey
* @return
*/
@RequestMapping(value = "/{backendId}/diagram", method = RequestMethod.GET, produces = MediaType.IMAGE_JPEG_VALUE)
@ResponseBody
@PreAuthorize("hasAuthority('" + CoreGroupPermission.WORKFLOW_DEFINITION_READ + "')")
@ApiOperation(value = "Workflow definition diagram", nickname = "getWorkflowDefinitionDiagram", tags = { WorkflowDefinitionController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.WORKFLOW_DEFINITION_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.WORKFLOW_DEFINITION_READ, description = "") }) }, notes = "Returns input stream to definition's diagram.")
public ResponseEntity<InputStreamResource> getDiagram(@ApiParam(value = "Workflow definition key.", required = true) @PathVariable String backendId) {
// check rights
WorkflowProcessDefinitionDto result = definitionService.getByName(backendId);
if (result == null) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", backendId));
}
InputStream is = definitionService.getDiagramByKey(backendId);
try {
return ResponseEntity.ok().contentLength(is.available()).contentType(MediaType.IMAGE_PNG).body(new InputStreamResource(is));
} catch (IOException e) {
throw new ResultCodeException(CoreResultCode.INTERNAL_SERVER_ERROR, e);
}
}
use of eu.bcvsolutions.idm.core.api.exception.ResultCodeException in project CzechIdMng by bcvsolutions.
the class WorkflowHistoricProcessInstanceController method getDiagram.
/**
* Generate process instance diagram image
*
* @param historicProcessInstanceId
* @return
*/
@ResponseBody
@RequestMapping(value = "/{backendId}/diagram", method = RequestMethod.GET, produces = MediaType.IMAGE_PNG_VALUE)
@ApiOperation(value = "Historic process instance diagram", nickname = "getHistoricProcessInstanceDiagram", response = WorkflowHistoricProcessInstanceDto.class, tags = { WorkflowHistoricProcessInstanceController.TAG })
public ResponseEntity<InputStreamResource> getDiagram(@ApiParam(value = "Historic process instance id.", required = true) @PathVariable @NotNull String backendId) {
// check rights
WorkflowHistoricProcessInstanceDto result = workflowHistoricProcessInstanceService.get(backendId);
if (result == null) {
throw new ResultCodeException(CoreResultCode.FORBIDDEN);
}
InputStream is = workflowHistoricProcessInstanceService.getDiagram(backendId);
try {
return ResponseEntity.ok().contentLength(is.available()).contentType(MediaType.IMAGE_PNG).body(new InputStreamResource(is));
} catch (IOException e) {
throw new ResultCodeException(CoreResultCode.INTERNAL_SERVER_ERROR, e);
}
}
use of eu.bcvsolutions.idm.core.api.exception.ResultCodeException in project CzechIdMng by bcvsolutions.
the class DefaultWorkflowProcessInstanceService method delete.
@Override
public WorkflowProcessInstanceDto delete(String processInstanceId, String deleteReason) {
if (processInstanceId == null) {
return null;
}
if (deleteReason == null) {
deleteReason = "Deleted by " + securityService.getUsername();
}
WorkflowFilterDto filter = new WorkflowFilterDto();
filter.setProcessInstanceId(processInstanceId);
Collection<WorkflowProcessInstanceDto> resources = this.searchInternal(filter, false).getResources();
WorkflowProcessInstanceDto processInstanceToDelete = null;
if (!resources.isEmpty()) {
processInstanceToDelete = resources.iterator().next();
}
if (processInstanceToDelete == null) {
throw new ResultCodeException(CoreResultCode.FORBIDDEN, "You do not have permission for delete process instance with ID: %s !", ImmutableMap.of("processInstanceId", processInstanceId));
}
runtimeService.deleteProcessInstance(processInstanceToDelete.getProcessInstanceId(), deleteReason);
return processInstanceToDelete;
}
use of eu.bcvsolutions.idm.core.api.exception.ResultCodeException in project CzechIdMng by bcvsolutions.
the class IdmEntityEventController method toFilter.
@Override
protected IdmEntityEventFilter toFilter(MultiValueMap<String, Object> parameters) {
IdmEntityEventFilter filter = new IdmEntityEventFilter(parameters);
filter.setCreatedFrom(getParameterConverter().toDateTime(parameters, "createdFrom"));
filter.setCreatedTill(getParameterConverter().toDateTime(parameters, "createdTill"));
filter.setOwnerType(getParameterConverter().toString(parameters, "ownerType"));
//
String ownerId = getParameterConverter().toString(parameters, "ownerId");
if (StringUtils.isNotEmpty(filter.getOwnerType()) && StringUtils.isNotEmpty(ownerId)) {
// try to find entity owner by Codeable identifier
AbstractDto owner = manager.findOwner(filter.getOwnerType(), ownerId);
if (owner != null) {
filter.setOwnerId(owner.getId());
} else {
throw new ResultCodeException(CoreResultCode.BAD_VALUE, "Entity type [%s] with identifier [%s] does not found", ImmutableMap.of("entityClass", filter.getOwnerType(), "identifier", ownerId));
}
} else {
filter.setOwnerId(getParameterConverter().toUuid(parameters, "ownerId"));
}
filter.setStates(getParameterConverter().toEnums(parameters, "states", OperationState.class));
return filter;
}
Aggregations