public class DetachedAnswer implements DetachedCommunication {
static final long serialVersionUID = 1l;
- public static int UNKOWN = -1;
- public static int PROCESSED = 0;
- public static int ERROR = 1;
- public static int SKIPPED = 2;
- public static int CLOSED_SESSION = 10;
+ public final static int UNKOWN = -1;
+ public final static int PROCESSED = 0;
+ public final static int ERROR = 1;
+ public final static int SKIPPED = 2;
+ public final static int CLOSED_SESSION = 10;
private Properties properties = new Properties();
private int status = UNKOWN;
this.uuid = uuid;
}
+ public String getStatusAsString() {
+ return convertStatus(getStatus());
+ }
+
+ public static String convertStatus(int status) {
+ switch (status) {
+ case UNKOWN:
+ return "UNKOWN";
+ case PROCESSED:
+ return "PROCESSED";
+ case SKIPPED:
+ return "SKIPPED";
+ case ERROR:
+ return "ERROR";
+ case CLOSED_SESSION:
+ return "CLOSED_SESSION";
+ default:
+ throw new DetachedException("Unkown status " + status);
+ }
+ }
}
public synchronized DetachedAnswer executeRequest(DetachedRequest request) {
DetachedAnswer answer = null;
try {
- // DetachedStep step = null;
-
// Find action
ServiceReference[] refs = bundleContext.getAllServiceReferences(
StaticRefProvider.class.getName(), null);
throw new DetachedException("Unknown action type "
+ obj.getClass() + " for action with ref "
+ request.getRef());
- } else {
- log.info("Processed '" + request.getRef() + "' (path="
- + request.getPath() + ")");
}
-
- } catch (DetachedException e) {
+ } catch (Exception e) {
answer = new DetachedAnswer(request);
answer.setStatus(DetachedAnswer.ERROR);
answer.setLog(e.getMessage());
- } catch (Exception e) {
- e.printStackTrace();
- throw new DetachedException(
- "Unexpected exception while executing request " + request,
- e);
}
getCurrentSession().getRequests().add(request);
getCurrentSession().getAnswers().add(answer);
+ if (log.isDebugEnabled())
+ log.debug("Processed '" + request.getRef() + "' (status="
+ + answer.getStatusAsString() + ", path="
+ + request.getPath() + ")");
return answer;
}
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
+import java.text.SimpleDateFormat;
+import java.util.Date;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
public class FileDriver extends AbstractDriver implements DetachedClient,
InitializingBean {
private final static Log log = LogFactory.getLog(FileDriver.class);
+ private final static SimpleDateFormat sdf = new SimpleDateFormat(
+ "yyMMdd_HHmmss_SSS");
private File baseDir;
private File requestsDir;
private File answersDir;
private File processedRequestsDir;
private File processedAnswersDir;
+ private File cleanedRequestsDir;
+ private File cleanedAnswersDir;
private String lockFileExt = "lck";
private FileFilter notLockFileFilter = new NotFileFilter(
throws Exception {
final File file;
if (getXmlConverter() != null)
- file = new File(dir.getPath() + File.separator + detCom.getUuid()
- + ".xml");
+ file = new File(dir.getPath() + File.separator
+ + sdf.format(new Date()) + '-' + detCom.getUuid() + ".xml");
else
file = new File(dir.getPath() + File.separator + detCom.getUuid());
+ File.separator + "processed" + File.separator + "requests");
this.processedAnswersDir = new File(baseDir.getAbsolutePath()
+ File.separator + "processed" + File.separator + "answers");
+ this.cleanedRequestsDir = new File(baseDir.getAbsolutePath()
+ + File.separator + "cleaned" + File.separator + "requests");
+ this.cleanedAnswersDir = new File(baseDir.getAbsolutePath()
+ + File.separator + "cleaned" + File.separator + "answers");
createIfNotExist(requestsDir);
createIfNotExist(answersDir);
createIfNotExist(processedRequestsDir);
createIfNotExist(processedAnswersDir);
+ createIfNotExist(cleanedRequestsDir);
+ createIfNotExist(cleanedAnswersDir);
}
}
import org.argeo.slc.detached.DetachedContext;
import org.argeo.slc.detached.DetachedRequest;
-public interface UiPart {
- public void init(DetachedContext context, DetachedRequest request);
+public abstract class UiPart {
+ private boolean initialized = false;
+
+ public synchronized final void init(DetachedContext context,
+ DetachedRequest request) {
+ initUi(context, request);
+ initialized = true;
+ }
+
+ public synchronized final void reset(DetachedContext context,
+ DetachedRequest request) {
+ resetUi(context, request);
+ initialized = false;
+ }
+
+ protected abstract void initUi(DetachedContext context,
+ DetachedRequest request);
+
+ protected void resetUi(DetachedContext context, DetachedRequest request) {
+
+ }
+
+ public synchronized boolean isInitialized() {
+ return initialized;
+ }
+
}
import org.argeo.slc.detached.DetachedContext;
import org.argeo.slc.detached.DetachedRequest;
import org.argeo.slc.detached.DetachedStep;
+import org.springframework.beans.factory.BeanNameAware;
-public abstract class UiStep implements DetachedStep {
+public abstract class UiStep implements DetachedStep, BeanNameAware {
private UiPart uiPart;
+ private String beanName;
public final DetachedAnswer execute(DetachedContext detachedContext,
DetachedRequest detachedStepRequest) {
- uiPart.init(detachedContext, detachedStepRequest);
+ // uiPart.init(detachedContext, detachedStepRequest);
return executeUiStep(detachedContext, detachedStepRequest);
}
this.uiPart = uiPart;
}
+ public void setBeanName(String name) {
+ this.beanName = name;
+ }
+
+ public String getBeanName() {
+ return beanName;
+ }
+
}