use of eu.bcvsolutions.idm.acc.domain.IdmAttachmentWithDataDto in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemAttributeMappingService method convertAttachment.
/**
* Convert attachment to {@link IdmAttachmentWithDataDto}
*
* @param attachmentDto
* @return
*/
private IdmAttachmentWithDataDto convertAttachment(IdmAttachmentDto attachmentDto) {
if (attachmentDto == null) {
return null;
}
IdmAttachmentWithDataDto data = new IdmAttachmentWithDataDto(attachmentDto);
data.setAttachmentType(attachmentDto.getAttachmentType());
data.setContentId(attachmentDto.getContentId());
data.setContentPath(attachmentDto.getContentPath());
data.setDescription(attachmentDto.getDescription());
data.setEncoding(attachmentDto.getEncoding());
data.setFilesize(attachmentDto.getFilesize());
data.setId(attachmentDto.getId());
data.setMimetype(attachmentDto.getMimetype());
data.setName(attachmentDto.getName());
data.setNextVersion(attachmentDto.getNextVersion());
data.setOwnerId(attachmentDto.getOwnerId());
data.setOwnerState(attachmentDto.getOwnerState());
data.setParent(attachmentDto.getParent());
data.setVersionLabel(attachmentDto.getVersionLabel());
data.setVersionNumber(attachmentDto.getVersionNumber());
return data;
}
use of eu.bcvsolutions.idm.acc.domain.IdmAttachmentWithDataDto in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemAttributeMappingService method transformValueToResource.
@Override
public Object transformValueToResource(String uid, Object value, String script, AbstractDto entity, SysSystemDto system, MappingContext mappingContext) {
if (!StringUtils.isEmpty(script)) {
Map<String, Object> variables = new HashMap<>();
variables.put(CONTEXT_KEY, mappingContext);
variables.put(ACCOUNT_UID, uid);
variables.put(ATTRIBUTE_VALUE_KEY, value);
variables.put(SYSTEM_KEY, system);
variables.put(ENTITY_KEY, entity);
variables.put(AbstractScriptEvaluator.SCRIPT_EVALUATOR, // add default script evaluator, for
pluginExecutors.getPluginFor(IdmScriptCategory.TRANSFORM_TO));
// call another scripts
//
// Add access for script evaluator
List<Class<?>> extraClass = new ArrayList<>();
extraClass.add(AbstractScriptEvaluator.Builder.class);
//
return groovyScriptService.evaluate(script, variables, extraClass);
}
// attachment's data (array of bytes) will be returned.
if (value instanceof IdmAttachmentWithDataDto) {
IdmAttachmentWithDataDto attachmentWithDataDto = (IdmAttachmentWithDataDto) value;
return attachmentWithDataDto.getData();
}
return value;
}
use of eu.bcvsolutions.idm.acc.domain.IdmAttachmentWithDataDto in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemAttributeMappingService method resolveFormValue.
/**
* Resolve form value
*
* @param formValue
* @return
*/
private Object resolveFormValue(IdmFormValueDto formValue) {
if (formValue == null) {
return null;
}
Serializable value = formValue.getValue();
// IdmAttachmentWithDataDto.
if (PersistentType.ATTACHMENT == formValue.getPersistentType() && value instanceof UUID) {
IdmAttachmentDto attachmentDto = attachmentManager.get((UUID) value);
// Convert attachment to attachment with data
IdmAttachmentWithDataDto attachmentWithDataDto = this.convertAttachment(attachmentDto);
try (InputStream inputStream = attachmentManager.getAttachmentData((UUID) value)) {
if (inputStream != null) {
byte[] bytes = IOUtils.toByteArray(inputStream);
attachmentWithDataDto.setData(bytes);
}
} catch (IOException e) {
throw new CoreException(e);
}
return attachmentWithDataDto;
}
return value;
}
Aggregations