use of eu.bcvsolutions.idm.core.api.domain.Codeable in project CzechIdMng by bcvsolutions.
the class AbstractBulkAction method createPermissionFailedLog.
/**
* Create failed log for given dto with exception for insufficient permission
*
* @param dto
*/
protected void createPermissionFailedLog(DTO dto) {
String entityCode = "";
if (dto instanceof Codeable) {
entityCode = ((Codeable) dto).getCode();
}
DefaultResultModel model = new DefaultResultModel(CoreResultCode.BULK_ACTION_INSUFFICIENT_PERMISSION, ImmutableMap.of("bulkAction", this.getAction().getName(), "entityId", dto.getId(), "entityCode", entityCode));
//
this.logItemProcessed(dto, new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(model).build());
}
use of eu.bcvsolutions.idm.core.api.domain.Codeable in project CzechIdMng by bcvsolutions.
the class AbstractBackupBulkAction method processDto.
@Override
@SuppressWarnings("unchecked")
protected OperationResult processDto(DTO dto) {
try {
Assert.notNull(dto, "Entity to backup is required!");
Assert.notNull(dto.getId(), "Id of entity to backup is required!");
Assert.isTrue(getService() instanceof Recoverable, "Entity service has to implement recoverable interface!");
Recoverable<DTO> service = (Recoverable<DTO>) getService();
// call backup
File backupFile = service.backup(dto);
// rename to zip folder
String fileName = dto.getId().toString();
if (dto instanceof Codeable) {
fileName = attachmentManager.getValidFileName(((Codeable) dto).getCode());
}
File targetFile = new File(zipFolder.toString(), String.format("%s.xml", fileName));
// and copy file
FileUtils.copyFile(backupFile, targetFile);
//
return new OperationResult(OperationState.EXECUTED);
} catch (Exception ex) {
return new //
OperationResult.Builder(//
OperationState.EXCEPTION).setCause(//
ex).build();
}
}
use of eu.bcvsolutions.idm.core.api.domain.Codeable in project CzechIdMng by bcvsolutions.
the class DefaultRequestManager method changeRequestState.
/**
* Change request state
*
* @param requestable
* @param request
* @param ex
* @return
*/
private <R extends Requestable> IdmRequestDto changeRequestState(R requestable, IdmRequestDto request, ResultCodeException ex) {
if (request.getState().isTerminatedState()) {
// If is request in the terminated state, then we only add result code
// exception,
// but don't modify the result state
request.setResult(//
new Builder(request.getResult().getState()).setException(//
ex).build());
} else {
request = requestService.cancel(request);
request.setResult(//
new Builder(OperationState.CANCELED).setException(//
ex).build());
}
if (requestable instanceof Codeable && ((Codeable) requestable).getCode() != null) {
request.setName(((Codeable) requestable).getCode());
}
return request;
}
use of eu.bcvsolutions.idm.core.api.domain.Codeable in project CzechIdMng by bcvsolutions.
the class DefaultRequestManager method makeNiceValue.
private Object makeNiceValue(Object value) {
if (value == null) {
return null;
}
if (value instanceof Codeable) {
Codeable codeable = (Codeable) value;
return codeable.getCode();
}
if (value instanceof Niceable) {
Niceable codeable = (Niceable) value;
return codeable.getNiceLabel();
}
if (value instanceof Identifiable) {
Identifiable identifiable = (Identifiable) value;
return identifiable.getId();
}
if (value instanceof ConfigurationMap) {
ConfigurationMap configurationMap = (ConfigurationMap) value;
Map<String, Serializable> map = configurationMap.toMap();
return map.toString();
}
return value;
}
use of eu.bcvsolutions.idm.core.api.domain.Codeable in project CzechIdMng by bcvsolutions.
the class DefaultCommonFormServiceIntegrationTest method testCreateForm.
@Test
@Transactional
public void testCreateForm() {
Codeable owner = getHelper().createIdentity((GuardedString) null);
IdmFormAttributeDto attribute = createDefinition();
IdmFormValueDto formValue = new IdmFormValueDto(attribute);
formValue.setValue("testOne");
IdmFormDto formOne = new IdmFormDto();
formOne.setName("test");
formOne.setFormDefinition(attribute.getFormDefinition());
formOne.setValues(Lists.newArrayList(formValue));
formOne.setOwnerCode(owner.getCode());
//
commonFormService.saveForm(owner, formOne);
formOne = commonFormService.getForms(owner).get(0);
//
Assert.assertNotNull(formOne.getId());
Assert.assertEquals(owner.getCode(), formOne.getOwnerCode());
Assert.assertEquals(lookupService.lookupEntity(owner.getClass(), owner.getId()).getClass().getCanonicalName(), formOne.getOwnerType());
Assert.assertEquals(owner.getId(), formOne.getOwnerId());
Assert.assertEquals(formValue.getValue(), formOne.getValues().get(0).getValue());
//
commonFormService.deleteForms(owner);
Assert.assertTrue(commonFormService.getForms(owner).isEmpty());
}
Aggregations