Skip to content

Commit

Permalink
ALFREDAPI-562: Make only AbstractAlfredApiWorkflowConvertor leaves Au…
Browse files Browse the repository at this point in the history
…toWired
  • Loading branch information
WimCrols committed Dec 12, 2024
1 parent 5beb549 commit 36e86db
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
package eu.xenit.alfred.api.alfresco;

import eu.xenit.alfred.api.alfresco.workflow.WorkflowServiceApsImpl;
import eu.xenit.alfred.api.alfresco.workflow.AbstractAlfredApiQueryConverter;
import eu.xenit.alfred.api.alfresco.workflow.AbstractQueryConverterFactory;
import eu.xenit.alfred.api.alfresco.workflow.WorkflowServiceActivitiImpl;
import eu.xenit.alfred.api.alfresco.workflow.WorkflowServiceApsImpl;
import eu.xenit.alfred.api.people.IPeopleService;
import eu.xenit.alfred.api.workflow.IWorkflowService;
import java.util.Properties;
import org.alfresco.service.ServiceRegistry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;

/**
* Spring configuration for components based on properties.
*
* Components based on Alfresco version are wired in eu.xenit.alfred.api.alfrescoXX.SpringConfiguration (where XX is version)
* Components based on Alfresco version are wired in eu.xenit.alfred.api.alfrescoXX.SpringConfiguration (where XX is
* version)
*/
@Configuration
public class AlfredApiSpringConfiguration {
Expand Down Expand Up @@ -44,20 +50,31 @@ public String getBpm() {

@Bean(name = "eu.xenit.alfred.api.workflow.IWorkflowService")
@DependsOn("global-properties")
public IWorkflowService workflowService() {
public IWorkflowService workflowService(
ServiceRegistry serviceRegistry,
AlfredApiToAlfrescoConversion c,
@Qualifier("eu.xenit.alfred.api.alfresco.workflow.activiti.AlfredApiActivitiWorkflowProcessQueryConverter")
AbstractAlfredApiQueryConverter alfredApiWfProcQueryConverter,
@Qualifier("eu.xenit.alfred.api.alfresco.workflow.activiti.AlfredApiActivitiWorkflowTaskQueryConverter")
AbstractAlfredApiQueryConverter alfredApiWfTaskQueryConverter,
IPeopleService peopleService,
@Qualifier("eu.xenit.alfred.api.alfresco.workflow.activiti.ActivitiQueryConverterFactory")
AbstractQueryConverterFactory activitiQueryConverterFactory) {
IWorkflowService result;
String bpm = getBpm();
switch (bpm) {
case "aps":
result = new WorkflowServiceApsImpl();
result = new WorkflowServiceApsImpl(getProperties());
break;
case "embedded-activiti":
result = new WorkflowServiceActivitiImpl();
result = new WorkflowServiceActivitiImpl(serviceRegistry, c, alfredApiWfProcQueryConverter,
alfredApiWfTaskQueryConverter, peopleService, activitiQueryConverterFactory);
break;
default:
logger.warn("Bpm option not recognised in alfresco-global-properties, defaulting to embedded "
+ "activiti");
result = new WorkflowServiceActivitiImpl();
logger.warn("Bpm option '{}' not recognised in alfresco-global-properties," +
" defaulting to embedded activiti", bpm);
result = new WorkflowServiceActivitiImpl(serviceRegistry, c, alfredApiWfProcQueryConverter,
alfredApiWfTaskQueryConverter, peopleService, activitiQueryConverterFactory);
}
logger.info("Configuring BPM: using {}", result.getClass());
return result;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package eu.xenit.alfred.api.alfresco.workflow;

import eu.xenit.alfred.api.alfresco.AlfredApiToAlfrescoConversion;
import eu.xenit.alfred.api.people.IPeopleService;
import eu.xenit.alfred.api.workflow.IWorkflowService;
import eu.xenit.alfred.api.workflow.model.WorkflowOrTaskChanges;
import java.io.Serializable;
Expand All @@ -26,7 +27,6 @@
import org.alfresco.util.ISO8601DateFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

public abstract class AbstractAlfredApiAlfrescoWorkflowConvertor extends AbstractAlfredApiWorkflowConvertor {

Expand Down Expand Up @@ -104,9 +104,11 @@ private static boolean IsIntProperty(String prop) {
return integerProperties.contains(prop);
}

@Autowired
public AbstractAlfredApiAlfrescoWorkflowConvertor(ServiceRegistry serviceRegistry,
public AbstractAlfredApiAlfrescoWorkflowConvertor(
ServiceRegistry serviceRegistry,
IPeopleService peopleService,
AlfredApiToAlfrescoConversion alfredApiToAlfrescoConversion) {
super(serviceRegistry, peopleService);
c = alfredApiToAlfrescoConversion;
workflowService = serviceRegistry.getWorkflowService();
messageService = serviceRegistry.getMessageService();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@
import org.alfresco.service.namespace.QName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

public abstract class AbstractAlfredApiWorkflowConvertor {

private static final Logger logger = LoggerFactory.getLogger(AbstractAlfredApiWorkflowConvertor.class);
private IPeopleService peopleService;
private AuthorityService authorityService;

@Autowired
public AbstractAlfredApiWorkflowConvertor(ServiceRegistry serviceRegistry, IPeopleService peopleService) {
this.peopleService = peopleService;
authorityService = serviceRegistry.getAuthorityService();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

@Service

public class WorkflowServiceActivitiImpl implements IWorkflowService, InitializingBean {

private final Logger logger = LoggerFactory.getLogger(WorkflowServiceActivitiImpl.class);
Expand All @@ -46,14 +43,12 @@ public class WorkflowServiceActivitiImpl implements IWorkflowService, Initializi
private AuthenticationService authenticationService;
private WorkflowService workflowService;

@Autowired
public WorkflowServiceActivitiImpl(
ServiceRegistry serviceRegistry,
AlfredApiToAlfrescoConversion c,
AbstractAlfredApiQueryConverter alfredApiWfProcQueryConverter,
AbstractAlfredApiQueryConverter alfredApiWfTaskQueryConverter,
IPeopleService peopleService,
@Qualifier("eu.xenit.alfred.api.alfresco.workflow.activiti.ActivitiQueryConverterFactory")
AbstractQueryConverterFactory activitiQueryConverterFactory) {
this.c = c;
this.peopleService = peopleService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import eu.xenit.alfred.api.alfresco.AlfredApiSpringConfiguration;
import eu.xenit.alfred.api.alfresco.workflow.aps.ApsFormDefinition;
import eu.xenit.alfred.api.alfresco.workflow.aps.ApsFormField;
import eu.xenit.alfred.api.data.QName;
Expand All @@ -26,7 +25,9 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import org.apache.commons.codec.binary.Base64;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
Expand All @@ -36,23 +37,22 @@
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.commons.codec.binary.Base64;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class WorkflowServiceApsImpl implements IWorkflowService {

@Autowired
private AlfredApiSpringConfiguration configuration;

private static final String APS_REST_DEFAULT_BASE_URL = "http://process-service:8080/activiti-app/api";
private static final String APS_REST_DEFAULT_USERNAME = "admin";
private static final String APS_REST_DEFAULT_PASSWORD = "admin";
private final Logger logger = LoggerFactory.getLogger(WorkflowServiceApsImpl.class);

private final Properties properties;

public WorkflowServiceApsImpl(Properties properties) {
this.properties = properties;
}

private HttpEntity doHttp(HttpUriRequest request) {
HttpClient httpClient = new DefaultHttpClient();
logger.debug("Doing HTTP {} to {}", request.getMethod(), request.getURI());
Expand Down Expand Up @@ -108,9 +108,7 @@ private List<WorkflowDefinition> getAllDefinitions(boolean onlyLatest) {
def.version = node.get("version").asText();
list.add(def);
}

return list;

}

@Override
Expand Down Expand Up @@ -281,6 +279,7 @@ private String getWorkflowDefinitionKey(String definitionKeyOrId) {
* Helper class for representing an APS process variable, serializes nicely to the json that APS expects.
*/
private static class ApsVarRepresentation {

// Class names recognized by APS
private final static Set<String> knownClasses = new HashSet<>(Arrays.asList(
"string", "integer", "boolean", "double", "date"));
Expand All @@ -306,23 +305,24 @@ static List<ApsVarRepresentation> listFromMap(Map<String, Serializable> map) {
}

private String getApsRestBaseUrl() {
if (configuration == null || configuration.getProperties() == null) {
if (properties == null) {
return APS_REST_DEFAULT_BASE_URL;
}
return configuration.getProperties().getProperty("aps.rest.base_url", APS_REST_DEFAULT_BASE_URL);
return properties.getProperty("aps.rest.base_url", APS_REST_DEFAULT_BASE_URL);
}

private String getApsRestUsername() {
if (configuration == null || configuration.getProperties() == null) {
if (properties == null) {
return APS_REST_DEFAULT_USERNAME;
}
return configuration.getProperties().getProperty("aps.rest.username", APS_REST_DEFAULT_USERNAME);
return properties.getProperty("aps.rest.username", APS_REST_DEFAULT_USERNAME);
}

private String getApsRestPassword() {
if (configuration == null || configuration.getProperties() == null) {
if (properties == null) {
return APS_REST_DEFAULT_PASSWORD;
}
return configuration.getProperties().getProperty("aps.rest.password", APS_REST_DEFAULT_PASSWORD);
return properties.getProperty("aps.rest.password", APS_REST_DEFAULT_PASSWORD);
}

private String getApsAuthorization() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,28 @@

import eu.xenit.alfred.api.alfresco.workflow.AbstractAlfredApiWorkflowConvertor;
import eu.xenit.alfred.api.alfresco.workflow.WorkflowConverterFactory;
import eu.xenit.alfred.api.people.IPeopleService;
import eu.xenit.alfred.api.workflow.model.ITaskOrWorkflow;
import eu.xenit.alfred.api.workflow.model.WorkflowOrTaskChanges;
import org.activiti.engine.history.HistoricProcessInstance;
import org.alfresco.service.ServiceRegistry;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

@Component("eu.xenit.alfred.api.alfresco.workflow.activiti.ActivitiProcessInstanceWorkflowConvertor")
public class ActivitiProcessInstanceWorkflowConvertor extends AbstractAlfredApiWorkflowConvertor {

@Qualifier("eu.xenit.alfred.api.alfresco.workflow.alfresco.AlfrescoInstanceConverterFactory")
@Autowired
protected WorkflowConverterFactory alfrescoWorkflowConverterFactory;

@Autowired
public ActivitiProcessInstanceWorkflowConvertor(
ServiceRegistry serviceRegistry,
IPeopleService peopleService,
@Qualifier("eu.xenit.alfred.api.alfresco.workflow.alfresco.AlfrescoInstanceConverterFactory") WorkflowConverterFactory workflowConverterFactory) {
super(serviceRegistry, peopleService);
alfrescoWorkflowConverterFactory = workflowConverterFactory;
}

private AbstractAlfredApiWorkflowConvertor getConvertor() {
return this.alfrescoWorkflowConverterFactory.getProcessInstanceConvertor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import eu.xenit.alfred.api.alfresco.workflow.AbstractAlfredApiWorkflowConvertor;
import eu.xenit.alfred.api.alfresco.workflow.WorkflowConverterFactory;
import eu.xenit.alfred.api.people.IPeopleService;
import eu.xenit.alfred.api.workflow.model.ITaskOrWorkflow;
import eu.xenit.alfred.api.workflow.model.WorkflowOrTaskChanges;
import org.activiti.engine.task.Task;
import org.alfresco.service.ServiceRegistry;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
Expand All @@ -14,10 +16,17 @@ public class ActivitiWorkflowTaskWorkflowConvertor extends AbstractAlfredApiWork

public static String ACTIVITI_PREFIX = "activiti$";

@Qualifier("eu.xenit.alfred.api.alfresco.workflow.alfresco.AlfrescoInstanceConverterFactory")
@Autowired
protected WorkflowConverterFactory alfrescoWorkflowConverterFactory;

@Autowired
public ActivitiWorkflowTaskWorkflowConvertor(
ServiceRegistry serviceRegistry,
IPeopleService peopleService,
@Qualifier("eu.xenit.alfred.api.alfresco.workflow.alfresco.AlfrescoInstanceConverterFactory") WorkflowConverterFactory workflowConverterFactory) {
super(serviceRegistry, peopleService);
alfrescoWorkflowConverterFactory = workflowConverterFactory;
}

private AbstractAlfredApiWorkflowConvertor getConvertor() {
return this.alfrescoWorkflowConverterFactory.getTaskInstanceConvertor();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package eu.xenit.alfred.api.alfresco.workflow.alfresco;

import eu.xenit.alfred.api.alfresco.AlfredApiToAlfrescoConversion;
import eu.xenit.alfred.api.alfresco.workflow.AbstractAlfredApiAlfrescoWorkflowConvertor;
import eu.xenit.alfred.api.alfresco.workflow.AbstractAlfredApiWorkflowConvertor;
import eu.xenit.alfred.api.people.IPeopleService;
import eu.xenit.alfred.api.workflow.model.ITaskOrWorkflow;
import eu.xenit.alfred.api.workflow.model.Task;
import eu.xenit.alfred.api.workflow.model.Workflow;
Expand Down Expand Up @@ -38,8 +40,11 @@ public class AlfrescoProcessInstanceWorkflowConvertor extends AbstractAlfredApiA
@Autowired
public AlfrescoProcessInstanceWorkflowConvertor(
ServiceRegistry serviceRegistry,
IPeopleService peopleService,
AlfredApiToAlfrescoConversion alfredApiToAlfrescoConversion,
@Qualifier("eu.xenit.alfred.api.alfresco.workflow.alfresco.AlfrescoWorkflowTaskWorkflowConvertor")
AbstractAlfredApiWorkflowConvertor taskConvertor) {
super(serviceRegistry, peopleService, alfredApiToAlfrescoConversion);
personService = serviceRegistry.getPersonService();
this.taskConvertor = taskConvertor;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package eu.xenit.alfred.api.alfresco.workflow.alfresco;

import eu.xenit.alfred.api.alfresco.AlfredApiToAlfrescoConversion;
import eu.xenit.alfred.api.alfresco.workflow.AbstractAlfredApiAlfrescoWorkflowConvertor;
import eu.xenit.alfred.api.alfresco.workflow.AbstractAlfredApiWorkflowConvertor;
import eu.xenit.alfred.api.alfresco.workflow.activiti.ActivitiWorkflowTaskWorkflowConvertor;
import eu.xenit.alfred.api.people.IPeopleService;
import eu.xenit.alfred.api.workflow.IWorkflowService;
import eu.xenit.alfred.api.workflow.model.ITaskOrWorkflow;
import eu.xenit.alfred.api.workflow.model.Task;
Expand All @@ -14,20 +17,31 @@
import java.util.Map;
import org.alfresco.repo.security.permissions.AccessDeniedException;
import org.alfresco.repo.workflow.WorkflowModel;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.workflow.WorkflowTask;
import org.alfresco.service.cmr.workflow.WorkflowTaskDefinition;
import org.alfresco.service.cmr.workflow.WorkflowTransition;
import org.alfresco.service.namespace.QName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

@Component("eu.xenit.alfred.api.alfresco.workflow.alfresco.AlfrescoWorkflowTaskWorkflowConvertor")
public class AlfrescoWorkflowTaskWorkflowConvertor extends AbstractAlfredApiAlfrescoWorkflowConvertor {

private static final Logger logger = LoggerFactory.getLogger(AlfrescoWorkflowTaskWorkflowConvertor.class);

@Autowired
public AlfrescoWorkflowTaskWorkflowConvertor(
ServiceRegistry serviceRegistry,
IPeopleService peopleService,
AlfredApiToAlfrescoConversion alfredApiToAlfrescoConversion) {
super(serviceRegistry, peopleService, alfredApiToAlfrescoConversion);
}

public <T> String getId(T task) {
return ((WorkflowTask) task).getId();
}
Expand Down

0 comments on commit 36e86db

Please sign in to comment.