Search in sources :

Example 1 with IdmAttachmentWithDataDto

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;
}
Also used : IdmAttachmentWithDataDto(eu.bcvsolutions.idm.acc.domain.IdmAttachmentWithDataDto)

Example 2 with IdmAttachmentWithDataDto

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;
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AbstractScriptEvaluator(eu.bcvsolutions.idm.core.script.evaluator.AbstractScriptEvaluator) SysSchemaObjectClass(eu.bcvsolutions.idm.acc.entity.SysSchemaObjectClass) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmAttachmentWithDataDto(eu.bcvsolutions.idm.acc.domain.IdmAttachmentWithDataDto)

Example 3 with IdmAttachmentWithDataDto

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;
}
Also used : IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) Serializable(java.io.Serializable) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) InputStream(java.io.InputStream) IOException(java.io.IOException) UUID(java.util.UUID) IdmAttachmentWithDataDto(eu.bcvsolutions.idm.acc.domain.IdmAttachmentWithDataDto)

Aggregations

IdmAttachmentWithDataDto (eu.bcvsolutions.idm.acc.domain.IdmAttachmentWithDataDto)3 SysSchemaObjectClass (eu.bcvsolutions.idm.acc.entity.SysSchemaObjectClass)1 CoreException (eu.bcvsolutions.idm.core.api.exception.CoreException)1 IdmAttachmentDto (eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto)1 AbstractScriptEvaluator (eu.bcvsolutions.idm.core.script.evaluator.AbstractScriptEvaluator)1 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 UUID (java.util.UUID)1