protected Object unwrap(Object data) { if (data instanceof Wrapped) { return ((Wrapped) data).unwrap(); } return data; }
protected Object unwrap(Object data) { if (data instanceof Wrapped) { return ((Wrapped) data).unwrap(); } return data; }
@Override public List<?> unwrap() { List<Object> unwrapped = new ArrayList<Object>(); if (items != null) { for (Object o : items) { Object item = o; if (o instanceof Wrapped) { item = ((Wrapped) o).unwrap(); } unwrapped.add(item); } } return unwrapped; } }
@Override public Map<String, Object> unwrap() { if (entries == null || entries.isEmpty()) { return Collections.emptyMap(); } for (Map.Entry<String, Object> entry : entries.entrySet()) { if (entry.getValue() instanceof Wrapped) { entry.setValue(((Wrapped) entry.getValue()).unwrap()); } } return entries; } }
public <T> T unmarshal(String data, String marshallingFormat, Class<T> unmarshalType) { if (data == null || data.isEmpty()) { return null; } MarshallingFormat format = getFormat(marshallingFormat); Marshaller marshaller = serverMarshallers.get(format); if (marshaller == null) { marshaller = MarshallerFactory.getMarshaller(getExtraClasses(registry), format, this.getClass().getClassLoader()); serverMarshallers.put(format, marshaller); } Object instance = marshaller.unmarshall(data, unmarshalType); if (instance instanceof Wrapped) { return (T) ((Wrapped) instance).unwrap(); } return (T) instance; }
protected void unwrapParameters() { if (parameters == null) { return; } for (QueryParam param : parameters) { if (param.getValue() != null) { List<Object> items = new ArrayList<>(); param.getValue().forEach(item -> { Object toAdd = item; if (item instanceof Wrapped) { toAdd = ((Wrapped) item).unwrap(); } items.add(toAdd); }); param.setValue(items); } } } }
public static <T> T unmarshal(String data, String marshallingFormat, Class<T> unmarshalType) { if (data == null || data.isEmpty()) { return null; } MarshallingFormat format = getFormat(marshallingFormat); Marshaller marshaller = null; switch (format) { case JAXB: { marshaller = jaxbMarshaller; break; } case JSON: { marshaller = jsonMarshaller; break; } default: { marshaller = jsonMarshaller; break; } } Object instance = marshaller.unmarshall(data, unmarshalType); if (instance instanceof Wrapped) { return (T) ((Wrapped) instance).unwrap(); } return (T) instance; }
public <T> T unmarshal(String containerId, String data, String marshallingFormat, Class<T> unmarshalType, ContainerLocator locator) { if (data == null || data.isEmpty()) { return null; } MarshallingFormat format = getFormat(marshallingFormat); KieContainerInstance containerInstance = registry.getContainer(containerId, locator); if (containerInstance == null || format == null) { throw new IllegalArgumentException("No container found for id " + containerId + " or unknown marshalling format " + marshallingFormat); } Marshaller marshaller = containerInstance.getMarshaller(format); if (marshaller == null) { throw new IllegalArgumentException("No marshaller found for format " + format); } Object instance = marshaller.unmarshall(data, unmarshalType); if (instance instanceof Wrapped) { return (T) ((Wrapped) instance).unwrap(); } return (T) instance; }
@Override public Object getCaseInstanceData(String containerId, String caseId, String name) { Object result = null; if( config.isRest() ) { Map<String, Object> valuesMap = new HashMap<String, Object>(); valuesMap.put(CONTAINER_ID, containerId); valuesMap.put(CASE_ID, caseId); valuesMap.put(CASE_FILE_ITEM, name); result = makeHttpGetRequestAndCreateCustomResponse( build(loadBalancer.getUrl(), CASE_URI + "/" + CASE_FILE_BY_NAME_GET_URI, valuesMap), Object.class); } else { CommandScript script = new CommandScript( Collections.singletonList( (KieServerCommand) new DescriptorCommand("CaseService", "getCaseFileDataByName", marshaller.getFormat().getType(), new Object[]{containerId, caseId, name})) ); ServiceResponse<String> response = (ServiceResponse<String>) executeJmsCommand( script, DescriptorCommand.class.getName(), KieServerConstants.CAPABILITY_CASE ).getResponses().get(0); if (shouldReturnWithNullResponse(response)) { return null; } result = deserialize(response.getResult(), Object.class); } if (result instanceof Wrapped) { return ((Wrapped) result).unwrap(); } return result; }
@Override public Long notifyWhenNotCompleted(String containerId, Long taskId, String expiresAt, EmailNotification emailNotification) { Object result = null; if( config.isRest() ) { Map<String, Object> valuesMap = new HashMap<String, Object>(); valuesMap.put(CONTAINER_ID, containerId); valuesMap.put(TASK_INSTANCE_ID, taskId); Map<String, String> headers = new HashMap<String, String>(); String queryString = "?expiresAt=" + expiresAt+"&whenNotCompleted=true"; result = makeHttpPostRequestAndCreateCustomResponse( build(loadBalancer.getUrl(), ADMIN_TASK_URI + "/" + TASK_INSTANCE_NOTIFICATIONS_URI, valuesMap) + queryString, emailNotification, Object.class, headers); } else { CommandScript script = new CommandScript( Collections.singletonList( (KieServerCommand) new DescriptorCommand("UserTaskAdminService", "notifyWhenNotCompleted", serialize(emailNotification), marshaller.getFormat().getType(), new Object[]{containerId, taskId, expiresAt}))); ServiceResponse<String> response = (ServiceResponse<String>) executeJmsCommand( script, DescriptorCommand.class.getName(), "BPM", containerId ).getResponses().get(0); throwExceptionOnFailure(response); if (shouldReturnWithNullResponse(response)) { return null; } result = deserialize(response.getResult(), Object.class); } if (result instanceof Wrapped) { return (Long) ((Wrapped) result).unwrap(); } return ((Number) result).longValue(); }
@Override public Long reassignWhenNotCompleted(String containerId, Long taskId, String expiresAt, OrgEntities orgEntities) { Object result = null; if( config.isRest() ) { Map<String, Object> valuesMap = new HashMap<String, Object>(); valuesMap.put(CONTAINER_ID, containerId); valuesMap.put(TASK_INSTANCE_ID, taskId); Map<String, String> headers = new HashMap<String, String>(); String queryString = "?expiresAt=" + expiresAt+"&whenNotCompleted=true"; result = makeHttpPostRequestAndCreateCustomResponse( build(loadBalancer.getUrl(), ADMIN_TASK_URI + "/" + TASK_INSTANCE_REASSIGNMENTS_URI, valuesMap) + queryString, orgEntities, Object.class, headers); } else { CommandScript script = new CommandScript( Collections.singletonList( (KieServerCommand) new DescriptorCommand("UserTaskAdminService", "reassignWhenNotCompleted", serialize(orgEntities), marshaller.getFormat().getType(), new Object[]{containerId, taskId, expiresAt}))); ServiceResponse<String> response = (ServiceResponse<String>) executeJmsCommand( script, DescriptorCommand.class.getName(), "BPM", containerId ).getResponses().get(0); throwExceptionOnFailure(response); if (shouldReturnWithNullResponse(response)) { return null; } result = deserialize(response.getResult(), Object.class); } if (result instanceof Wrapped) { return (Long) ((Wrapped) result).unwrap(); } return ((Number) result).longValue(); }
@Override public List<String> getAvailableSignals(String containerId, Long processInstanceId) { Object signals = null; if( config.isRest() ) { Map<String, Object> valuesMap = new HashMap<String, Object>(); valuesMap.put(CONTAINER_ID, containerId); valuesMap.put(PROCESS_INST_ID, processInstanceId); signals = makeHttpGetRequestAndCreateCustomResponse( build(loadBalancer.getUrl(), PROCESS_URI + "/" + PROCESS_INSTANCE_SIGNALS_GET_URI, valuesMap), Object.class); } else { CommandScript script = new CommandScript( Collections.singletonList( (KieServerCommand) new DescriptorCommand( "ProcessService", "getAvailableSignals", marshaller.getFormat().getType(), new Object[]{containerId, processInstanceId}) ) ); ServiceResponse<String> response = (ServiceResponse<String>) executeJmsCommand( script, DescriptorCommand.class.getName(), "BPM", containerId ).getResponses().get(0); throwExceptionOnFailure(response); if (shouldReturnWithNullResponse(response)) { return null; } signals = deserialize(response.getResult(), Object.class); } if (signals instanceof Wrapped) { return (List<String>) ((Wrapped)signals).unwrap(); } return (List<String>) signals; }
@Override public Map<String, Object> getTaskOutputContentByTaskId(String containerId, Long taskId) { Object variables = null; if( config.isRest() ) { Map<String, Object> valuesMap = new HashMap<String, Object>(); valuesMap.put(CONTAINER_ID, containerId); valuesMap.put(TASK_INSTANCE_ID, taskId); variables = makeHttpGetRequestAndCreateCustomResponse( build(loadBalancer.getUrl(), TASK_URI + "/" + TASK_INSTANCE_OUTPUT_DATA_GET_URI, valuesMap), Object.class); } else { CommandScript script = new CommandScript( Collections.singletonList( (KieServerCommand) new DescriptorCommand( "UserTaskService", "getTaskOutputContentByTaskId", marshaller.getFormat().getType(), new Object[]{containerId, taskId}) ) ); ServiceResponse<String> response = (ServiceResponse<String>) executeJmsCommand( script, DescriptorCommand.class.getName(), "BPM", containerId ).getResponses().get(0); throwExceptionOnFailure(response); if (shouldReturnWithNullResponse(response)) { return null; } variables = deserialize(response.getResult(), Object.class); } if (variables instanceof Wrapped) { return (Map) ((Wrapped) variables).unwrap(); } return (Map) variables; }
@Override public Map<String, Object> getProcessInstanceVariables(String containerId, Long processInstanceId) { Object variables = null; if( config.isRest() ) { Map<String, Object> valuesMap = new HashMap<String, Object>(); valuesMap.put(CONTAINER_ID, containerId); valuesMap.put(PROCESS_INST_ID, processInstanceId); variables = makeHttpGetRequestAndCreateCustomResponse( build(loadBalancer.getUrl(), PROCESS_URI + "/" + PROCESS_INSTANCE_VARS_GET_URI, valuesMap), Object.class); } else { CommandScript script = new CommandScript( Collections.singletonList( (KieServerCommand) new DescriptorCommand( "ProcessService", "getProcessInstanceVariables", marshaller.getFormat().getType(), new Object[]{containerId, processInstanceId}) ) ); ServiceResponse<String> response = (ServiceResponse<String>) executeJmsCommand( script, DescriptorCommand.class.getName(), "BPM", containerId ).getResponses().get(0); throwExceptionOnFailure(response); if (shouldReturnWithNullResponse(response)) { return null; } variables = deserialize(response.getResult(), Object.class); } if (variables instanceof Wrapped) { return (Map) ((Wrapped) variables).unwrap(); } return (Map) variables; }
@Override public Long startProcess(String containerId, String processId, Map<String, Object> variables) { Object result = null; if( config.isRest() ) { Map<String, Object> valuesMap = new HashMap<String, Object>(); valuesMap.put(CONTAINER_ID, containerId); valuesMap.put(PROCESS_ID, processId); result = makeHttpPostRequestAndCreateCustomResponse( build(loadBalancer.getUrl(), PROCESS_URI + "/" + START_PROCESS_POST_URI, valuesMap), variables, Object.class); } else { CommandScript script = new CommandScript( Collections.singletonList( (KieServerCommand) new DescriptorCommand( "ProcessService", "startProcess", serialize(safeMap(variables)), marshaller.getFormat().getType(), new Object[]{containerId, processId}) ) ); ServiceResponse<String> response = (ServiceResponse<String>) executeJmsCommand( script, DescriptorCommand.class.getName(), "BPM", containerId ).getResponses().get(0); throwExceptionOnFailure(response); if (shouldReturnWithNullResponse(response)) { return null; } result = deserialize(response.getResult(), Object.class); } if (result instanceof Wrapped) { return (Long) ((Wrapped) result).unwrap(); } return ((Number) result).longValue(); }
@Override public Long saveTaskContent(String containerId, Long taskId, Map<String, Object> values) { Object contentId = null; if( config.isRest() ) { Map<String, Object> valuesMap = new HashMap<String, Object>(); valuesMap.put(CONTAINER_ID, containerId); valuesMap.put(TASK_INSTANCE_ID, taskId); contentId = makeHttpPutRequestAndCreateCustomResponse( build(loadBalancer.getUrl(), TASK_URI + "/" + TASK_INSTANCE_OUTPUT_DATA_PUT_URI, valuesMap), values, Object.class, getHeaders(null)); } else { CommandScript script = new CommandScript( Collections.singletonList( (KieServerCommand) new DescriptorCommand( "UserTaskService", "saveContent", serialize(values), marshaller.getFormat().getType(), new Object[]{containerId, taskId}) ) ); ServiceResponse<String> response = (ServiceResponse<String>) executeJmsCommand( script, DescriptorCommand.class.getName(), "BPM", containerId ).getResponses().get(0); throwExceptionOnFailure(response); if (shouldReturnWithNullResponse(response)) { return null; } contentId = deserialize(response.getResult(), Object.class); } if (contentId instanceof Wrapped) { return (Long) ((Wrapped) contentId).unwrap(); } return ((Number) contentId).longValue(); }
@Override public Long startProcess(String containerId, String processId, CorrelationKey correlationKey, Map<String, Object> variables) { Object result = null; if( config.isRest() ) { Map<String, Object> valuesMap = new HashMap<String, Object>(); valuesMap.put(CONTAINER_ID, containerId); valuesMap.put(PROCESS_ID, processId); valuesMap.put(CORRELATION_KEY, correlationKey.toExternalForm()); result = makeHttpPostRequestAndCreateCustomResponse( build(loadBalancer.getUrl(), PROCESS_URI + "/" + START_PROCESS_WITH_CORRELATION_KEY_POST_URI, valuesMap), variables, Object.class); } else { CommandScript script = new CommandScript( Collections.singletonList( (KieServerCommand) new DescriptorCommand( "ProcessService", "startProcessWithCorrelation", serialize(safeMap(variables)), marshaller.getFormat().getType(), new Object[]{containerId, processId, correlationKey.toExternalForm()}) ) ); ServiceResponse<String> response = (ServiceResponse<String>) executeJmsCommand( script, DescriptorCommand.class.getName(), "BPM", containerId ).getResponses().get(0); throwExceptionOnFailure(response); if (shouldReturnWithNullResponse(response)) { return null; } result = deserialize(response.getResult(), Object.class); } if (result instanceof Wrapped) { return (Long) ((Wrapped) result).unwrap(); } return ((Number) result).longValue(); }
@Override public String startCase(String containerId, String caseDefinitionId, CaseFile caseFile) { Object result = null; if( config.isRest() ) { Map<String, Object> valuesMap = new HashMap<String, Object>(); valuesMap.put(CONTAINER_ID, containerId); valuesMap.put(CASE_DEF_ID, caseDefinitionId); result = makeHttpPostRequestAndCreateCustomResponse( build(loadBalancer.getUrl(), CASE_URI + "/" + START_CASE_POST_URI, valuesMap), caseFile, String.class); } else { CommandScript script = new CommandScript( Collections.singletonList( (KieServerCommand) new DescriptorCommand("CaseService", "startCase", serialize(caseFile), marshaller.getFormat().getType(), new Object[]{containerId, caseDefinitionId})) ); ServiceResponse<String> response = (ServiceResponse<String>) executeJmsCommand( script, DescriptorCommand.class.getName(), KieServerConstants.CAPABILITY_CASE ).getResponses().get(0); throwExceptionOnFailure(response); if (shouldReturnWithNullResponse(response)) { return null; } result = deserialize(response.getResult(), Object.class); } if (result instanceof Wrapped) { return (String) ((Wrapped) result).unwrap(); } return (String) result; }
@Override public Long addTaskAttachment(String containerId, Long taskId, String userId, String name, Object attachment) { Object attachmentId = null; if( config.isRest() ) { Map<String, Object> valuesMap = new HashMap<String, Object>(); valuesMap.put(CONTAINER_ID, containerId); valuesMap.put(TASK_INSTANCE_ID, taskId); attachmentId = makeHttpPostRequestAndCreateCustomResponse( build(loadBalancer.getUrl(), TASK_URI + "/" + TASK_INSTANCE_ATTACHMENT_ADD_POST_URI, valuesMap) + getUserAndAdditionalParam(userId, "name", name), attachment, Object.class, getHeaders(null)); } else { CommandScript script = new CommandScript( Collections.singletonList( (KieServerCommand) new DescriptorCommand( "UserTaskService", "addAttachment", serialize(attachment), marshaller.getFormat().getType(), new Object[]{containerId, taskId, userId, name}) ) ); ServiceResponse<String> response = (ServiceResponse<String>) executeJmsCommand( script, DescriptorCommand.class.getName(), "BPM", containerId ).getResponses().get(0); throwExceptionOnFailure(response); if (shouldReturnWithNullResponse(response)) { return null; } attachmentId = deserialize(response.getResult(), Object.class); } if (attachmentId instanceof Wrapped) { return (Long) ((Wrapped) attachmentId).unwrap(); } return ((Number) attachmentId).longValue(); }
@Override public String createDocument(DocumentInstance documentInstance) { Object result = null; if( config.isRest() ) { Map<String, Object> valuesMap = new HashMap<String, Object>(); result = makeHttpPostRequestAndCreateCustomResponse( build(loadBalancer.getUrl(), DOCUMENT_URI, valuesMap), documentInstance, Object.class); } else { CommandScript script = new CommandScript( Collections.singletonList( (KieServerCommand) new DescriptorCommand("DocumentService", "storeDocument", serialize(documentInstance), marshaller.getFormat().getType(), new Object[]{})) ); ServiceResponse<String> response = (ServiceResponse<String>) executeJmsCommand( script, DescriptorCommand.class.getName(), "BPM" ).getResponses().get(0); throwExceptionOnFailure(response); if (shouldReturnWithNullResponse(response)) { return null; } result = response.getResult(); } if (result instanceof Wrapped) { return (String) ((Wrapped) result).unwrap(); } return (String) result; }