Skip to content

Commit

Permalink
Merge pull request #856 from ashishbhasin45/refactor/remove-design-sm…
Browse files Browse the repository at this point in the history
…ells

Refactoring- Removed 3 design smells
  • Loading branch information
rsoika committed Apr 2, 2024
2 parents dec3110 + 9667c5d commit 0328b53
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ public void removeModel(String version) {
public Model getModelByWorkitem(ItemCollection workitem) throws ModelException {
return model;
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,14 @@ protected void setErrorParameters(java.lang.Object[] aparams) {
this.params = aparams;
}

@Override
public String formatErrorMessageWithParameters(String message){
if (params != null && params.length > 0) {
for (int i = 0; i < params.length; i++) {
message = message.replace("{" + i + "}", params[i].toString());
}
}

return message;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,7 @@ public void setErrorCode(String errorCode) {
this.errorCode = errorCode;
}

public String formatErrorMessageWithParameters(String message){
return message;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
import jakarta.ejb.TimerService;
import java.util.logging.Level;

import static org.imixs.workflow.engine.AsyncEventSchedulerConfig.*;

/**
* The AsyncEventScheduler starts a scheduler service to process async events in
* an asynchronous way by calling the AsyncEventService.
Expand All @@ -71,12 +73,7 @@
@Singleton
public class AsyncEventScheduler {

public static final String ASYNCEVENT_PROCESSOR_ENABLED = "asyncevent.processor.enabled";
public static final String ASYNCEVENT_PROCESSOR_INTERVAL = "asyncevent.processor.interval";
public static final String ASYNCEVENT_PROCESSOR_INITIALDELAY = "asyncevent.processor.initialdelay";
public static final String ASYNCEVENT_PROCESSOR_DEADLOCK = "asyncevent.processor.deadlock";

public static final String EVENTLOG_TOPIC_ASYNC_EVENT = "async.event";

// enabled
@Inject
Expand All @@ -95,7 +92,7 @@ public class AsyncEventScheduler {

// deadlock timeout interval in ms
@Inject
@ConfigProperty(name = AsyncEventScheduler.ASYNCEVENT_PROCESSOR_DEADLOCK, defaultValue = "60000")
@ConfigProperty(name = ASYNCEVENT_PROCESSOR_DEADLOCK, defaultValue = "60000")
long deadLockInterval;

private static final Logger logger = Logger.getLogger(AsyncEventScheduler.class.getName());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.imixs.workflow.engine;

public class AsyncEventSchedulerConfig {
public static final String ASYNCEVENT_PROCESSOR_ENABLED = "asyncevent.processor.enabled";
public static final String ASYNCEVENT_PROCESSOR_INTERVAL = "asyncevent.processor.interval";
public static final String ASYNCEVENT_PROCESSOR_INITIALDELAY = "asyncevent.processor.initialdelay";
public static final String ASYNCEVENT_PROCESSOR_DEADLOCK = "asyncevent.processor.deadlock";

public static final String EVENTLOG_TOPIC_ASYNC_EVENT = "async.event";
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
import jakarta.ejb.TransactionAttributeType;
import jakarta.persistence.OptimisticLockException;

import static org.imixs.workflow.engine.AsyncEventSchedulerConfig.ASYNCEVENT_PROCESSOR_ENABLED;
import static org.imixs.workflow.engine.AsyncEventSchedulerConfig.EVENTLOG_TOPIC_ASYNC_EVENT;

/**
* The AsyncEventService can be used to process workflow events in an
* asynchronous batch process. The AsyncEventService lookup eventLog entries of
Expand Down Expand Up @@ -89,7 +92,7 @@ public class AsyncEventService {

// enabled
@Inject
@ConfigProperty(name = AsyncEventScheduler.ASYNCEVENT_PROCESSOR_ENABLED, defaultValue = "false")
@ConfigProperty(name = ASYNCEVENT_PROCESSOR_ENABLED, defaultValue = "false")
boolean enabled;

private static final Logger logger = Logger.getLogger(AsyncEventService.class.getName());
Expand Down Expand Up @@ -140,7 +143,7 @@ public void onProcess(@Observes ProcessingEvent processingEvent) throws ModelExc
asyncEventData.setItemValue("timeDuration", boundaryDuration);
asyncEventData.setItemValue(WorkflowKernel.TRANSACTIONID,
processingEvent.getDocument().getItemValueString(WorkflowKernel.TRANSACTIONID));
eventLogService.createEvent(AsyncEventScheduler.EVENTLOG_TOPIC_ASYNC_EVENT,
eventLogService.createEvent(EVENTLOG_TOPIC_ASYNC_EVENT,
processingEvent.getDocument().getUniqueID(), asyncEventData, cal);

}
Expand All @@ -166,7 +169,7 @@ public void processEventLog() {

// test for new event log entries by timeout...
List<EventLog> events = eventLogService.findEventsByTimeout(100,
AsyncEventScheduler.EVENTLOG_TOPIC_ASYNC_EVENT);
EVENTLOG_TOPIC_ASYNC_EVENT);

if (debug) {
logger.log(Level.FINEST, "......found {0} eventLog entries", events.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,8 @@

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,23 +155,7 @@ public static void addErrorMessage(WorkflowException pe) {
}

// parse message for params
if (pe instanceof PluginException) {
PluginException p = (PluginException) pe;
if (p.getErrorParameters() != null && p.getErrorParameters().length > 0) {
for (int i = 0; i < p.getErrorParameters().length; i++) {
message = message.replace("{" + i + "}", p.getErrorParameters()[i].toString());
}
}
} else {
if (pe instanceof ValidationException) {
ValidationException p = (ValidationException) pe;
if (p.getErrorParameters() != null && p.getErrorParameters().length > 0) {
for (int i = 0; i < p.getErrorParameters().length; i++) {
message = message.replace("{" + i + "}", p.getErrorParameters()[i].toString());
}
}
}
}
pe.formatErrorMessageWithParameters(message);
FacesContext.getCurrentInstance().addMessage(null,
new FacesMessage(FacesMessage.SEVERITY_INFO, errorCode, message));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,15 @@ protected void setErrorParameters(Object[] aparams) {
this.params = aparams;
}

@Override
public String formatErrorMessageWithParameters(String message){
if (params != null && params.length > 0) {
for (int i = 0; i < params.length; i++) {
message = message.replace("{" + i + "}", params[i].toString());
}
}

return message;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -146,51 +146,13 @@ private void printVersionTable(OutputStream out) {
try {
StringBuffer buffer = new StringBuffer();

List<String> modelVersionList = modelService.getVersions();

// compute rootContext:
String rootContext = servletRequest.getContextPath() + servletRequest.getServletPath();

buffer.append("<table>");
buffer.append("<tr><th>Version</th><th>Uploaded</th><th>Workflow Groups</th></tr>");
for (String modelVersion : modelVersionList) {

Model model = modelService.getModel(modelVersion);
ItemCollection modelEntity = modelService.loadModelEntity(modelVersion);

// now check groups...
List<String> groupList = model.getGroups();

buffer.append("<tr>");

if (modelEntity != null) {

buffer.append("<td><a href=\"" + rootContext + "/model/" + modelVersion + "/bpmn\">" + modelVersion
+ "</a></td>");

// print upload date...
if (modelEntity != null) {
Date dat = modelEntity.getItemValueDate("$Modified");
SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
buffer.append("<td>" + formater.format(dat) + "</td>");
}
} else {
buffer.append("<td>" + modelVersion + "</td>");
buffer.append("<td> - </td>");
}

// Groups
buffer.append("<td>");
for (String group : groupList) {
// build a link for each group to get the Tasks

buffer.append("<a href=\"" + rootContext + "/model/" + modelVersion + "/groups/" + group + "\">"
+ group + "</a></br>");
}
buffer.append("</td>");
buffer.append("</tr>");

}
// append current model version table as a html string
buffer.append(modelVersionTableToString(rootContext));

buffer.append("</table>");
out.write(buffer.toString().getBytes());
Expand Down Expand Up @@ -495,4 +457,57 @@ public void postModel(XMLDataCollection ecol) {
putModel(ecol);
}

/**
* Returns the current model information in html format
* @param rootContext
* @return model version table as a html string
* @throws ModelException
*/
private String modelVersionTableToString(String rootContext) throws ModelException{
List<String> modelVersionList = modelService.getVersions();
StringBuffer buffer = new StringBuffer();

for (String modelVersion : modelVersionList) {

appendTagsToBuffer(modelVersion, rootContext, buffer);
}
return buffer.toString();
}

private void appendTagsToBuffer(String modelVersion, String rootContext, StringBuffer buffer) throws ModelException{
Model model = modelService.getModel(modelVersion);
ItemCollection modelEntity = modelService.loadModelEntity(modelVersion);

// now check groups...
List<String> groupList = model.getGroups();

buffer.append("<tr>");

if (modelEntity != null) {

buffer.append("<td><a href=\"" + rootContext + "/model/" + modelVersion + "/bpmn\">" + modelVersion
+ "</a></td>");

// print upload date...
if (modelEntity != null) {
Date dat = modelEntity.getItemValueDate("$Modified");
SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
buffer.append("<td>" + formater.format(dat) + "</td>");
}
} else {
buffer.append("<td>" + modelVersion + "</td>");
buffer.append("<td> - </td>");
}

// Groups
buffer.append("<td>");
for (String group : groupList) {
// build a link for each group to get the Tasks

buffer.append("<a href=\"" + rootContext + "/model/" + modelVersion + "/groups/" + group + "\">"
+ group + "</a></br>");
}
buffer.append("</td>");
buffer.append("</tr>");
}
}

0 comments on commit 0328b53

Please sign in to comment.