Search in sources :

Example 1 with UserRequestFormProperty

use of org.apache.syncope.common.lib.to.UserRequestFormProperty in project syncope by apache.

the class FlowableUserRequestHandler method getForm.

@SuppressWarnings("unchecked")
protected UserRequestForm getForm(final String procInstId, final String taskId, final String formKey, final List<FormProperty> props) {
    UserRequestForm formTO = new UserRequestForm();
    formTO.setBpmnProcess(engine.getRuntimeService().createProcessInstanceQuery().processInstanceId(procInstId).singleResult().getProcessDefinitionKey());
    User user = userDAO.find(getUserKey(procInstId));
    if (user == null) {
        throw new NotFoundException("User for process instance id " + procInstId);
    }
    formTO.setUsername(user.getUsername());
    formTO.setTaskId(taskId);
    formTO.setFormKey(formKey);
    formTO.setUserTO(engine.getRuntimeService().getVariable(procInstId, FlowableRuntimeUtils.USER_TO, UserTO.class));
    formTO.setUserUR(engine.getRuntimeService().getVariable(procInstId, FlowableRuntimeUtils.USER_UR, UserUR.class));
    formTO.getProperties().addAll(props.stream().map(fProp -> {
        UserRequestFormProperty propertyTO = new UserRequestFormProperty();
        propertyTO.setId(fProp.getId());
        propertyTO.setName(fProp.getName());
        propertyTO.setReadable(fProp.isReadable());
        propertyTO.setRequired(fProp.isRequired());
        propertyTO.setWritable(fProp.isWritable());
        propertyTO.setValue(fProp.getValue());
        propertyTO.setType(fromFlowableFormType(fProp.getType()));
        switch(propertyTO.getType()) {
            case Date:
                propertyTO.setDatePattern((String) fProp.getType().getInformation("datePattern"));
                break;
            case Enum:
                ((Map<String, String>) fProp.getType().getInformation("values")).forEach((key, value) -> {
                    propertyTO.getEnumValues().add(new UserRequestFormPropertyValue(key, value));
                });
                break;
            case Dropdown:
                String valueProviderBean = (String) fProp.getType().getInformation(DropdownValueProvider.NAME);
                try {
                    DropdownValueProvider valueProvider = ApplicationContextProvider.getApplicationContext().getBean(valueProviderBean, DropdownValueProvider.class);
                    valueProvider.getValues().forEach((key, value) -> {
                        propertyTO.getDropdownValues().add(new UserRequestFormPropertyValue(key, value));
                    });
                } catch (Exception e) {
                    LOG.error("Could not find bean {} of type {} for form property {}", valueProviderBean, DropdownValueProvider.class.getName(), propertyTO.getId(), e);
                }
                break;
            default:
        }
        return propertyTO;
    }).collect(Collectors.toList()));
    return formTO;
}
Also used : UserRequestForm(org.apache.syncope.common.lib.to.UserRequestForm) User(org.apache.syncope.core.persistence.api.entity.user.User) UserTO(org.apache.syncope.common.lib.to.UserTO) UserRequestFormProperty(org.apache.syncope.common.lib.to.UserRequestFormProperty) UserUR(org.apache.syncope.common.lib.request.UserUR) UserRequestFormPropertyValue(org.apache.syncope.common.lib.to.UserRequestFormPropertyValue) DropdownValueProvider(org.apache.syncope.core.flowable.api.DropdownValueProvider) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) Map(java.util.Map) HashMap(java.util.HashMap) WorkflowException(org.apache.syncope.core.workflow.api.WorkflowException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) FlowableException(org.flowable.common.engine.api.FlowableException) FlowableIllegalArgumentException(org.flowable.common.engine.api.FlowableIllegalArgumentException)

Example 2 with UserRequestFormProperty

use of org.apache.syncope.common.lib.to.UserRequestFormProperty in project syncope by apache.

the class FlowableUserRequestHandler method getHistoricFormTO.

protected UserRequestForm getHistoricFormTO(final String procInstId, final String taskId, final String formKey, final List<HistoricFormPropertyEntity> props) {
    UserRequestForm formTO = new UserRequestForm();
    formTO.setBpmnProcess(engine.getRuntimeService().createProcessInstanceQuery().processInstanceId(procInstId).singleResult().getProcessDefinitionKey());
    User user = userDAO.find(getUserKey(procInstId));
    if (user == null) {
        throw new NotFoundException("User for process instance id " + procInstId);
    }
    formTO.setUsername(user.getUsername());
    formTO.setTaskId(taskId);
    formTO.setFormKey(formKey);
    formTO.setUserTO(engine.getRuntimeService().getVariable(procInstId, FlowableRuntimeUtils.USER_TO, UserTO.class));
    formTO.setUserUR(engine.getRuntimeService().getVariable(procInstId, FlowableRuntimeUtils.USER_UR, UserUR.class));
    formTO.getProperties().addAll(props.stream().map(prop -> {
        UserRequestFormProperty propertyTO = new UserRequestFormProperty();
        propertyTO.setId(prop.getPropertyId());
        propertyTO.setName(prop.getPropertyId());
        propertyTO.setValue(prop.getPropertyValue());
        return propertyTO;
    }).collect(Collectors.toList()));
    return formTO;
}
Also used : UserRequestForm(org.apache.syncope.common.lib.to.UserRequestForm) User(org.apache.syncope.core.persistence.api.entity.user.User) UserTO(org.apache.syncope.common.lib.to.UserTO) UserRequestFormProperty(org.apache.syncope.common.lib.to.UserRequestFormProperty) UserUR(org.apache.syncope.common.lib.request.UserUR) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException)

Aggregations

UserUR (org.apache.syncope.common.lib.request.UserUR)2 UserRequestForm (org.apache.syncope.common.lib.to.UserRequestForm)2 UserRequestFormProperty (org.apache.syncope.common.lib.to.UserRequestFormProperty)2 UserTO (org.apache.syncope.common.lib.to.UserTO)2 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)2 User (org.apache.syncope.core.persistence.api.entity.user.User)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 UserRequestFormPropertyValue (org.apache.syncope.common.lib.to.UserRequestFormPropertyValue)1 DropdownValueProvider (org.apache.syncope.core.flowable.api.DropdownValueProvider)1 WorkflowException (org.apache.syncope.core.workflow.api.WorkflowException)1 FlowableException (org.flowable.common.engine.api.FlowableException)1 FlowableIllegalArgumentException (org.flowable.common.engine.api.FlowableIllegalArgumentException)1