diff --git a/pom.xml b/pom.xml
index cfa83b4f..768b6ba0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,6 +23,7 @@
bpmn-model
uengine-client-example
uengine-social-bpm-portal
+ uengine-persistence-couchbase
@@ -50,6 +51,18 @@
true
+
+ central
+ http://repo1.maven.org/maven2/
+
+ true
+
+
+ true
+
+
+
+
@@ -99,4 +112,4 @@
-
\ No newline at end of file
+
diff --git a/uengine-core/src/main/java/org/uengine/kernel/EJBProcessInstance.java b/uengine-core/src/main/java/org/uengine/kernel/EJBProcessInstance.java
index f8f748ec..836db877 100644
--- a/uengine-core/src/main/java/org/uengine/kernel/EJBProcessInstance.java
+++ b/uengine-core/src/main/java/org/uengine/kernel/EJBProcessInstance.java
@@ -11,7 +11,11 @@
import java.util.Set;
import java.util.Vector;
+import org.metaworks.dwr.MetaworksRemoteService;
import org.uengine.contexts.ComplexType;
+import org.uengine.modeling.resource.DefaultResource;
+import org.uengine.modeling.resource.IResource;
+import org.uengine.modeling.resource.ResourceManager;
import org.uengine.persistence.dao.UniqueKeyGenerator;
import org.uengine.persistence.processinstance.ProcessInstanceDAO;
import org.uengine.persistence.processinstance.ProcessInstanceDAOType;
@@ -51,10 +55,10 @@ public class EJBProcessInstance extends DefaultProcessInstance implements Transa
Map cachedRoleMappings;
//
+ private boolean fileBasedPersistence = GlobalContext.getPropertyString("persistence.file-based", "true").equals("true");
+
//for caching
boolean caching;
- private boolean fileBasedPersistence = GlobalContext.getPropertyString("persistence.file-based", "false").equals("true");
-
public boolean isCaching() {
return caching;
}
@@ -303,7 +307,7 @@ public void applyChanges() throws Exception{
if(modifiedKeyMap!=null){
if(fileBasedPersistence) {
- setProcessVariablesFile(getVariables());
+ setProcessVariablesToFile(getVariables());
}else {
/*DB based.*/
@@ -544,7 +548,7 @@ private void setImpl(String scopeByTracingTag, String key, Serializable val, int
if(fileBasedPersistence) {
if(!isBatch)
- setProcessVariablesFile(createFullKey(scopeByTracingTag, key, isProperty), val);
+ setProcessVariablesToFile(createFullKey(scopeByTracingTag, key, isProperty), val);
}else {
@@ -622,22 +626,11 @@ private void beginCaching(String scopeByTracingTag, String key, boolean isProper
//20130815 var filePath save
if(fileBasedPersistence){ //file based variable persistence is disabled for concurrent variable data change.
- Date starteddate = (Date)getProcessInstanceDAO().get("STARTEDDATE");
- Calendar cal = Calendar.getInstance();
- cal.setTime(starteddate);
- String calendarDirectory = cal.get(Calendar.YEAR)
- + "/" + (cal.get(Calendar.MONTH) + 1) + "/"
- + cal.get(Calendar.DAY_OF_MONTH);
- String filePath =GlobalContext.FILE_SYSTEM_PATH + (GlobalContext.FILE_SYSTEM_PATH.endsWith("/") ? "" : "/") + calendarDirectory +"/vars_" + getInstanceId() + ".json";
+ Map fileVariables = getAllFromFile();
+ fileVariables.putAll(variables);
-
- File varFile = new File(filePath);
- if (varFile.exists()) {
- Map fileVariables = (Map) GlobalContext.deserialize(new FileInputStream(filePath), Object.class);
- fileVariables.putAll(variables);
- variables = fileVariables;
- }
+ variables = fileVariables;
} else {
@@ -761,7 +754,7 @@ public Serializable getImpl(String scopeByTracingTag, String key, boolean isProp
}
if(sourceValue==null)
- sourceValue = getFile(scopeByTracingTag, key, firstPart, isProperty);
+ sourceValue = getFromFile(scopeByTracingTag, key, firstPart, isProperty);
if(sourceValue == null){
ProcessDefinition pd = getProcessDefinition();
@@ -833,7 +826,7 @@ public Map getAll(String scope) throws Exception {
return variables;
// if(fileBasedPersistence)
-// return getAllFile();
+// return getAllFromFile();
// else
// return getProcessVariableDAOFacade().getAll(getInstanceId());
}
@@ -1392,29 +1385,17 @@ public String getMainExecutionScope() {
}
}
- private void setProcessVariablesFile (Map modifiedVariables) throws FileNotFoundException, Exception {
- Date starteddate = (Date)getProcessInstanceDAO().get("STARTEDDATE");
- Calendar cal = Calendar.getInstance();
- cal.setTime(starteddate);
- String calendarDirectory = cal.get(Calendar.YEAR)
- + "/" + (cal.get(Calendar.MONTH) + 1) + "/"
- + cal.get(Calendar.DAY_OF_MONTH);
- String filePath = GlobalContext.FILE_SYSTEM_PATH + (GlobalContext.FILE_SYSTEM_PATH.endsWith("/") ? "" : "/") + calendarDirectory ;
+ private void setProcessVariablesToFile(Map modifiedVariables) throws FileNotFoundException, Exception {
+ String filePath = getSaveFilePath();
- File newFile = new File(filePath);
- File dir = newFile.getParentFile();
- if (!dir.exists()) {
- dir.mkdirs();
- }
- if (!newFile.exists()) {
- newFile.mkdirs();
- }
+ ResourceManager resourceManager = MetaworksRemoteService.getComponent(ResourceManager.class);
+
+ IResource resource = new DefaultResource(filePath);
- File varFile = new File(filePath +"/vars_"+getInstanceId() + ".json");
Map procVars = null;
- if ( varFile.exists() ) {
- procVars = (Map) GlobalContext.deserialize(new FileInputStream(varFile), Object.class);
+ if ( resourceManager.exists(resource) ) {
+ procVars = (Map) resourceManager.getObject(resource);
} else {
DefaultProcessInstance shotProcessInstance = getProcessVariableDAOFacade().getAllVariablesAsDefaultProcessInstance(getInstanceId());
procVars = shotProcessInstance.variables;
@@ -1422,135 +1403,91 @@ private void setProcessVariablesFile (Map modifiedVariables) throws FileNotFound
procVars.putAll(modifiedVariables);
- GlobalContext.serialize(procVars,new FileOutputStream(filePath +"/vars_"+getInstanceId() + ".json"), Object.class);
+ resourceManager.save(resource, procVars);
+
+ }
+
+ private void setProcessVariablesToFile(String key, Serializable val) throws FileNotFoundException, Exception {
+ Map change = new HashMap();
+ change.put(key, val);
+ setProcessVariablesToFile(change);
}
- private void setProcessVariablesFile (String key, Serializable val) throws FileNotFoundException, Exception {
+ private String getSaveFilePath() throws Exception {
Date starteddate = (Date)getProcessInstanceDAO().get("STARTEDDATE");
Calendar cal = Calendar.getInstance();
cal.setTime(starteddate);
String calendarDirectory = cal.get(Calendar.YEAR)
+ "/" + (cal.get(Calendar.MONTH) + 1) + "/"
+ cal.get(Calendar.DAY_OF_MONTH);
- String filePath = GlobalContext.FILE_SYSTEM_PATH + (GlobalContext.FILE_SYSTEM_PATH.endsWith("/") ? "" : "/") + calendarDirectory ;
-
- File newFile = new File(filePath);
- File dir = newFile.getParentFile();
- if (!dir.exists()) {
- dir.mkdirs();
- }
- if (!newFile.exists()) {
- newFile.mkdirs();
- }
-
- File varFile = new File(filePath +"/vars_"+getInstanceId() + ".json");
- Map procVars = null;
-
- if ( varFile.exists() ) {
- procVars = (Map) GlobalContext.deserialize(new FileInputStream(varFile), Object.class);
- } else {
- DefaultProcessInstance shotProcessInstance = getProcessVariableDAOFacade().getAllVariablesAsDefaultProcessInstance(getInstanceId());
- procVars = shotProcessInstance.variables;
- }
+ String folder = GlobalContext.FILE_SYSTEM_PATH + (GlobalContext.FILE_SYSTEM_PATH.endsWith("/") ? "" : "/") + calendarDirectory;
- if(val != null){
- procVars.put(key, val);
- }
-
- GlobalContext.serialize(procVars,new FileOutputStream(filePath +"/vars_"+getInstanceId() + ".json"), Object.class);
+ return folder +"/vars_"+getInstanceId() + ".json";
}
- private Map getAllFile() throws FileNotFoundException, Exception {
- Date starteddate = (Date)getProcessInstanceDAO().get("STARTEDDATE");
- Calendar cal = Calendar.getInstance();
- cal.setTime(starteddate);
- String calendarDirectory = cal.get(Calendar.YEAR)
- + "/" + (cal.get(Calendar.MONTH) + 1) + "/"
- + cal.get(Calendar.DAY_OF_MONTH);
- String filePath = GlobalContext.FILE_SYSTEM_PATH + calendarDirectory ;
+ private Map getAllFromFile() throws FileNotFoundException, Exception {
+ ResourceManager resourceManager = MetaworksRemoteService.getComponent(ResourceManager.class);
- File varFile = new File(filePath +"/vars_"+getInstanceId() + ".json");
- Map procVars = null;
+ IResource resource = new DefaultResource(getSaveFilePath());
- if (varFile.exists()) {
- return (Map) GlobalContext.deserialize(new FileInputStream(varFile), Object.class);
+ if ( resourceManager.exists(resource) ) {
+ return (Map) resourceManager.getObject(resource);
+ }else{
+ return new HashMap(); // return empty one
}
- else
- return getProcessVariableDAOFacade().getAll(getInstanceId());
}
private ProcessVariableValue getMultipeFromFile(String scopeByTracingTag, String key) throws FileNotFoundException, Exception {
- Date starteddate = (Date)getProcessInstanceDAO().get("STARTEDDATE");
- Calendar cal = Calendar.getInstance();
- cal.setTime(starteddate);
- String calendarDirectory = cal.get(Calendar.YEAR)
- + "/" + (cal.get(Calendar.MONTH) + 1) + "/"
- + cal.get(Calendar.DAY_OF_MONTH);
-
- String filePath =GlobalContext.FILE_SYSTEM_PATH +"/"+ calendarDirectory +"/vars_" + getInstanceId() + ".json";
- File varFile = new File(filePath);
- if (varFile.exists()) {
- Map fileVariables = (Map) GlobalContext.deserialize(new FileInputStream(filePath), Object.class);
+ Map fileVariables = getAllFromFile();
- Object originalValue = fileVariables.get(createFullKey(scopeByTracingTag, key, false));
+ Object originalValue = fileVariables.get(createFullKey(scopeByTracingTag, key, false));
- if(originalValue instanceof IndexedProcessVariableMap) {
- IndexedProcessVariableMap ipvm = (IndexedProcessVariableMap) originalValue;
+ if(originalValue instanceof IndexedProcessVariableMap) {
+ IndexedProcessVariableMap ipvm = (IndexedProcessVariableMap) originalValue;
- if (ipvm != null) {
+ if (ipvm != null) {
- int maxIndex = ipvm.getMaxIndex();
- ProcessVariableValue pvv = new ProcessVariableValue();
- for (int i = 0; i < maxIndex + 1; i++) {
- Serializable value = ipvm.getProcessVariableAt(i);
+ int maxIndex = ipvm.getMaxIndex();
+ ProcessVariableValue pvv = new ProcessVariableValue();
+ for (int i = 0; i < maxIndex + 1; i++) {
+ Serializable value = ipvm.getProcessVariableAt(i);
+ pvv.setValue(value);
+ pvv.moveToAdd();
+ }
+ pvv.beforeFirst();
+ if (pvv.size() == 0 || (pvv.size() == 1 && pvv.getValue() == null)) {
+ try {
+ Serializable value = (Serializable) getProcessDefinition().getProcessVariable(key).getDefaultValue();
pvv.setValue(value);
- pvv.moveToAdd();
- }
- pvv.beforeFirst();
- if (pvv.size() == 0 || (pvv.size() == 1 && pvv.getValue() == null)) {
- try {
- Serializable value = (Serializable) getProcessDefinition().getProcessVariable(key).getDefaultValue();
- pvv.setValue(value);
-
- return pvv;
- } catch (Exception e) {
- }
- }
-
- return pvv;
- } else {
- // ProcessVariableValue pvv = new ProcessVariableValue();
- // pvv.setName(key);
- return null;
+ return pvv;
+ } catch (Exception e) {
+ }
}
- }else{
-
- ProcessVariableValue pvv = new ProcessVariableValue();
- pvv.setValue(originalValue);
return pvv;
+ } else {
+ // ProcessVariableValue pvv = new ProcessVariableValue();
+ // pvv.setName(key);
+
+ return null;
}
+ }else{
+
+ ProcessVariableValue pvv = new ProcessVariableValue();
+ pvv.setValue(originalValue);
+
+ return pvv;
}
- return getProcessVariableDAOFacade().getAsProcessVariableValue(getInstanceId(), scopeByTracingTag, key);
}
- private Serializable getFile(String scopeByTracingTag, String key, String firstPart, boolean isProperty) throws FileNotFoundException, Exception {
- Date starteddate = (Date)getProcessInstanceDAO().get("STARTEDDATE");
- Calendar cal = Calendar.getInstance();
- cal.setTime(starteddate);
- String calendarDirectory = cal.get(Calendar.YEAR)
- + "/" + (cal.get(Calendar.MONTH) + 1) + "/"
- + cal.get(Calendar.DAY_OF_MONTH);
- String filePath =GlobalContext.FILE_SYSTEM_PATH +"/"+ calendarDirectory +"/vars_" + getInstanceId() + ".json";
- File varFile = new File(filePath);
+
+ private Serializable getFromFile(String scopeByTracingTag, String key, String firstPart, boolean isProperty) throws FileNotFoundException, Exception {
+
Serializable sourceValue;
- if (varFile.exists()) {
- Map fileVariables = (Map) GlobalContext.deserialize(new FileInputStream(filePath), Object.class);
- sourceValue = (Serializable)fileVariables.get(createFullKey(scopeByTracingTag, key, isProperty));
- } else
- sourceValue = getProcessVariableDAOFacade().get(getInstanceId(), scopeByTracingTag, firstPart);
+ Map fileVariables = getAllFromFile();
+ sourceValue = (Serializable)fileVariables.get(createFullKey(scopeByTracingTag, key, isProperty));
return sourceValue;
}
diff --git a/uengine-persistence-couchbase/pom.xml b/uengine-persistence-couchbase/pom.xml
new file mode 100644
index 00000000..8cb6ea9e
--- /dev/null
+++ b/uengine-persistence-couchbase/pom.xml
@@ -0,0 +1,59 @@
+
+ 4.0.0
+
+ org.uengine
+ uengine
+ 4.1.0-SNAPSHOT
+
+ uengine-persistence-couchbase
+ jar
+
+
+ 1.2.0-SNAPSHOT
+ 1.3.0-SNAPSHOT
+ 4.1.0-SNAPSHOT
+
+
+
+
+
+
+ com.couchbase.client
+ java-client
+ 2.2.7
+
+
+ org.uengine
+ uengine-core
+ ${project.version}
+
+
+ org.uengine
+ uengine-resource-manager
+ ${project.version}
+
+
+ org.springframework
+ spring-test
+ 4.1.4.RELEASE
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 2.3.2
+
+
+ 1.7
+ UTF-8
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/uengine-persistence-couchbase/src/main/java/org/uengine/persistence/couchbase/CouchBaseProcessInstance.java b/uengine-persistence-couchbase/src/main/java/org/uengine/persistence/couchbase/CouchBaseProcessInstance.java
new file mode 100644
index 00000000..bb80b725
--- /dev/null
+++ b/uengine-persistence-couchbase/src/main/java/org/uengine/persistence/couchbase/CouchBaseProcessInstance.java
@@ -0,0 +1,78 @@
+package org.uengine.persistence.couchbase;
+
+import com.couchbase.client.java.Bucket;
+import com.couchbase.client.java.Cluster;
+import com.couchbase.client.java.CouchbaseCluster;
+import com.couchbase.client.java.document.JsonDocument;
+import com.couchbase.client.java.document.json.JsonObject;
+import com.couchbase.client.java.env.CouchbaseEnvironment;
+import com.couchbase.client.java.env.DefaultCouchbaseEnvironment;
+import com.couchbase.client.java.query.N1qlQuery;
+import com.couchbase.client.java.query.N1qlQueryResult;
+import com.couchbase.client.java.query.N1qlQueryRow;
+import com.couchbase.client.java.view.ViewResult;
+import org.uengine.kernel.EJBProcessInstance;
+import org.uengine.kernel.ProcessDefinition;
+
+import java.util.Map;
+
+import static com.couchbase.client.java.query.Select.select;
+import static com.couchbase.client.java.query.dsl.Expression.x;
+
+/**
+ * Created by jangjinyoung on 2017. 3. 27..
+ */
+public class CouchbaseProcessInstance extends EJBProcessInstance {
+ public CouchbaseProcessInstance(ProcessDefinition procDef, String name, Map options) throws Exception {
+ super(procDef, name, options);
+ }
+
+ public static void main (String... args) throws Exception{
+// Connect to localhost
+
+ CouchbaseEnvironment env = DefaultCouchbaseEnvironment.builder()
+ .queryEnabled(true) //that's the important part
+ .build();
+ CouchbaseCluster cluster = CouchbaseCluster.create(env, "127.0.0.1");
+ //Cluster cluster = CouchbaseCluster.create();
+
+// Open the default bucket and the "beer-sample" one
+ Bucket defaultBucket = cluster.openBucket();
+ Bucket beerSampleBucket = cluster.openBucket("beer-sample");
+
+ JsonObject user = JsonObject.empty()
+ .put("instId", "50")
+ .put("key", "White")
+ .put("value", "chemistry teacher");
+
+ JsonDocument stored = beerSampleBucket.upsert(JsonDocument.create("instId-fullkey(execscope:key)", user));
+
+ JsonDocument walter = beerSampleBucket.get("instId-fullkey(execscope:key)");
+ System.out.println("Found: " + walter.content().getString("key"));
+
+
+ user = JsonObject.empty()
+ .put("instId", "50")
+ .put("key", "xxxx")
+ .put("value", "value 2");
+
+ beerSampleBucket.upsert(JsonDocument.create("instId-fullkey(xxxx:xxxx)", user));
+
+ N1qlQueryResult result =
+ beerSampleBucket.query(N1qlQuery.simple("SELECT * FROM `beer-sample` WHERE `instId`=\"50\""));//select("*").from("beer-sample").where(x("instId").eq(x("50")))));
+
+// QueryResult result =
+// beerSampleBucket.query(Query.simple("SELECT * FROM `beer-sample` WHERE `instId`=\"50\""));
+
+ for (N1qlQueryRow row : result) {
+ JsonObject doc = row.value();
+
+ System.out.println(((JsonObject)doc.get("beer-sample")).getString("instId"));
+ }
+
+// Disconnect and clear all allocated resources
+ cluster.disconnect();
+
+
+ }
+}
diff --git a/uengine-persistence-couchbase/src/main/java/org/uengine/persistence/couchbase/CouchBaseStorage.java b/uengine-persistence-couchbase/src/main/java/org/uengine/persistence/couchbase/CouchBaseStorage.java
new file mode 100644
index 00000000..e823b516
--- /dev/null
+++ b/uengine-persistence-couchbase/src/main/java/org/uengine/persistence/couchbase/CouchBaseStorage.java
@@ -0,0 +1,186 @@
+package org.uengine.persistence.couchbase;
+
+import com.couchbase.client.java.Bucket;
+import com.couchbase.client.java.CouchbaseCluster;
+import com.couchbase.client.java.document.JsonDocument;
+import com.couchbase.client.java.document.json.JsonObject;
+import com.couchbase.client.java.env.CouchbaseEnvironment;
+import com.couchbase.client.java.env.DefaultCouchbaseEnvironment;
+import com.couchbase.client.java.query.N1qlQuery;
+import com.couchbase.client.java.query.N1qlQueryResult;
+import com.couchbase.client.java.query.N1qlQueryRow;
+import org.metaworks.MetaworksContext;
+import org.uengine.modeling.resource.*;
+
+import javax.annotation.PostConstruct;
+import java.io.*;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Created by jangjinyoung on 2017. 3. 28..
+ */
+public class CouchbaseStorage extends AbstractStorage {
+
+
+ String serverIp;
+ public String getServerIp() {
+ return serverIp;
+ }
+ public void setServerIp(String serverIp) {
+ this.serverIp = serverIp;
+ }
+
+ String bucketName;
+ public String getBucketName() {
+ return bucketName;
+ }
+ public void setBucketName(String bucketName) {
+ this.bucketName = bucketName;
+ }
+
+ CouchbaseCluster cluster;
+
+ @PostConstruct
+ public void init(){
+ CouchbaseEnvironment env = DefaultCouchbaseEnvironment.builder()
+ .queryEnabled(true) //that's the important part
+ .build();
+
+ cluster = CouchbaseCluster.create(env, getServerIp());
+//
+// try{
+// getBucket();
+// }catch (Exception e){
+// cluster.
+// }
+
+ }
+
+ protected Bucket getBucket(){
+ return cluster.openBucket(getBucketName());
+ }
+
+ @Override
+ public void delete(IResource resource) throws IOException {
+
+ getBucket().remove(getAbsolutePath(resource));
+
+ }
+
+ @Override
+ public void rename(IResource resource, String newName) {
+
+
+ }
+
+ @Override
+ public void copy(IResource src, String desPath) throws Exception {
+ String value = getSource(src);
+ DefaultResource destResource = new DefaultResource(desPath);
+
+ saveSource(destResource, value);
+ }
+
+ @Override
+ public void move(IResource src, IContainer container) throws IOException {
+
+ }
+
+ @Override
+ public List listFiles(IContainer containerResource) throws Exception {
+
+ List resourceList = new ArrayList();
+
+ String tenantBasePath = getTenantBasePath();
+ String abstractTenantBasePath = new File(tenantBasePath).getAbsolutePath();
+
+
+ N1qlQueryResult result =
+ getBucket().query(N1qlQuery.simple("SELECT META(t).id, t.type as type FROM `" + getBucketName() + "` AS t WHERE `parent`=\"" + getAbsolutePath(containerResource) + "\""));
+
+
+ for (N1qlQueryRow row : result) {
+ JsonObject doc = row.value();
+
+ String path = doc.getString("id");
+ String type = doc.getString("type");
+
+ String relativePath = path.replace("\\", "/");
+ relativePath = relativePath.substring(abstractTenantBasePath.length() + 1);
+
+ if("folder".equals(type)){
+ ContainerResource subContainerResource = (ContainerResource) containerResource.getClass().newInstance();
+
+ subContainerResource.setPath(relativePath);
+ subContainerResource.setMetaworksContext(new MetaworksContext());
+ subContainerResource.setChildren(listFiles(subContainerResource));
+
+ resourceList.add(subContainerResource);
+ }else{
+ resourceList.add(DefaultResource.createResource(relativePath));
+ }
+ }
+
+ return resourceList;
+ }
+
+ @Override
+ public void createFolder(IContainer containerResource) throws Exception {
+ JsonObject jsonObject = JsonObject.empty()
+ .put("parent", getParentAbsolutePath(containerResource))
+ .put("type", "folder");
+
+ JsonDocument stored = getBucket().upsert(JsonDocument.create(getAbsolutePath(containerResource), jsonObject));
+
+ }
+
+ @Override
+ public boolean exists(IResource resource) throws Exception {
+ return getBucket().exists(getAbsolutePath(resource));
+ }
+
+ @Override
+ public Object getObject(IResource resource) throws Exception {
+
+ String value = getSource(resource);
+
+ return Serializer.deserialize(value);
+ }
+
+ private String getSource(IResource resource) {
+ JsonDocument document = getBucket().get(getAbsolutePath(resource));
+ return document.content().getString("value");
+ }
+
+ @Override
+ public void save(IResource resource, Object object) throws Exception {
+ saveSource(resource, Serializer.serialize(object));
+ }
+
+ private JsonDocument saveSource(IResource resource, String sourceString) throws Exception {
+ JsonObject jsonObject = JsonObject.empty()
+ .put("parent", getParentAbsolutePath(resource))
+ .put("value", sourceString);
+
+
+
+ JsonDocument stored = getBucket().upsert(JsonDocument.create(getAbsolutePath(resource), jsonObject));
+
+ return stored;
+ }
+
+ @Override
+ public InputStream getInputStream(IResource resource) throws Exception {
+ String value = getSource(resource);
+
+ ByteArrayInputStream bai = new ByteArrayInputStream(value.getBytes());
+
+ return bai;
+ }
+
+ @Override
+ public OutputStream getOutputStream(IResource resource) throws Exception {
+ return null;
+ }
+}
diff --git a/uengine-resource-manager/src/main/java/org/uengine/modeling/resource/AbstractStorage.java b/uengine-resource-manager/src/main/java/org/uengine/modeling/resource/AbstractStorage.java
new file mode 100644
index 00000000..95b32540
--- /dev/null
+++ b/uengine-resource-manager/src/main/java/org/uengine/modeling/resource/AbstractStorage.java
@@ -0,0 +1,84 @@
+package org.uengine.modeling.resource;
+
+import org.apache.commons.io.FileUtils;
+import org.metaworks.MetaworksContext;
+import org.oce.garuda.multitenancy.TenantContext;
+import org.springframework.stereotype.Component;
+
+import java.io.*;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.util.ArrayList;
+import java.util.List;
+
+import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
+
+/**
+ * Created by jangjinyoung on 15. 7. 12..
+ */
+@Component
+public abstract class AbstractStorage implements Storage{
+
+ boolean doNotOverwrite;
+ public boolean isDoNotOverwrite() {
+ return doNotOverwrite;
+ }
+ public void setDoNotOverwrite(boolean doNotOverwrite) {
+ this.doNotOverwrite = doNotOverwrite;
+ }
+
+ String basePath;
+ public String getBasePath() {
+ return basePath;
+ }
+ public void setBasePath(String basePath) {
+ this.basePath = basePath;
+ }
+
+
+ @Override
+ public Object getObject(IResource resource) throws Exception {
+ return Serializer.deserialize(getInputStream(resource));
+ }
+
+ @Override
+ public void save(IResource resource, Object object) throws Exception {
+ Serializer.serialize(object, getOutputStream(resource));
+
+ }
+
+ protected String getTenantBasePath() {
+ String tenantId = TenantContext.getThreadLocalInstance().getTenantId();
+
+ if(tenantId==null){
+ tenantId = "default";
+ }
+
+ return getBasePath() + (getBasePath().endsWith("/") ? "":"/") + tenantId + "/";
+ }
+
+ protected String getAbsolutePath(IResource resource){
+ String path = (resource!=null ? resource.getPath() : "");
+
+ if(path.startsWith("/")) path = path.substring(1);
+
+ return getTenantBasePath()
+ + path;
+ }
+
+ protected String getParentAbsolutePath(IResource resource){
+ if(resource==null) return "";
+
+ String path = resource.getPath();
+
+ int lastFolderNmIdx = path.lastIndexOf("/");
+
+ if(lastFolderNmIdx==-1) return "";
+
+ path = path.substring(0, lastFolderNmIdx);
+ IResource parentResource = new DefaultResource(path);
+
+ return getAbsolutePath(parentResource);
+ }
+}
diff --git a/uengine-resource-manager/src/main/java/org/uengine/modeling/resource/CachedResourceManager.java b/uengine-resource-manager/src/main/java/org/uengine/modeling/resource/CachedResourceManager.java
index 5d4f61e3..2bb374c9 100644
--- a/uengine-resource-manager/src/main/java/org/uengine/modeling/resource/CachedResourceManager.java
+++ b/uengine-resource-manager/src/main/java/org/uengine/modeling/resource/CachedResourceManager.java
@@ -1,5 +1,6 @@
package org.uengine.modeling.resource;
+import org.codehaus.jackson.map.util.LRUMap;
import org.metaworks.dao.TransactionContext;
import java.util.Map;
@@ -10,10 +11,26 @@
public class CachedResourceManager extends ResourceManager {
public static final String RESOURCE_MANAGER_CACHE = "resourceManagerCache_";
+ static LRUMap lruCache = new LRUMap<>(0, 10);
+
+ boolean perTransaction;
+ public boolean isPerTransaction() {
+ return perTransaction;
+ }
+ public void setPerTransaction(boolean perTransaction) {
+ this.perTransaction = perTransaction;
+ }
+
@Override
public Object getObject(IResource resource) throws Exception {
- Object cache = TransactionContext.getThreadLocalInstance().getSharedContext(RESOURCE_MANAGER_CACHE + resource.getPath());
+
+ Object cache;
+ if(isPerTransaction()){
+ cache = TransactionContext.getThreadLocalInstance().getSharedContext(RESOURCE_MANAGER_CACHE + resource.getPath());
+ }else{
+ cache = lruCache.get(resource.getPath());
+ }
if(cache != null){
return cache;
@@ -21,7 +38,11 @@ public Object getObject(IResource resource) throws Exception {
Object object = super.getObject(resource);
- TransactionContext.getThreadLocalInstance().setSharedContext(RESOURCE_MANAGER_CACHE + resource.getPath(), object);
+ if(isPerTransaction()){
+ TransactionContext.getThreadLocalInstance().setSharedContext(RESOURCE_MANAGER_CACHE + resource.getPath(), object);
+ }else {
+ lruCache.put(resource.getPath(), object);
+ }
return object;
}
@@ -30,7 +51,13 @@ public Object getObject(IResource resource) throws Exception {
public void save(IResource resource, Object object) throws Exception {
super.save(resource, object);
- TransactionContext.getThreadLocalInstance().setSharedContext(RESOURCE_MANAGER_CACHE + resource.getPath(), object);
+
+ if(isPerTransaction()) {
+ TransactionContext.getThreadLocalInstance().setSharedContext(RESOURCE_MANAGER_CACHE + resource.getPath(), object);
+ }else{
+ lruCache.put(resource.getPath(), object);
+ }
+ //
}
}
diff --git a/uengine-resource-manager/src/main/java/org/uengine/modeling/resource/LocalFileStorage.java b/uengine-resource-manager/src/main/java/org/uengine/modeling/resource/LocalFileStorage.java
index c2a2c7e8..00246fee 100644
--- a/uengine-resource-manager/src/main/java/org/uengine/modeling/resource/LocalFileStorage.java
+++ b/uengine-resource-manager/src/main/java/org/uengine/modeling/resource/LocalFileStorage.java
@@ -19,25 +19,7 @@
* Created by jangjinyoung on 15. 7. 12..
*/
@Component
-public class LocalFileStorage implements Storage{
-
- String localBasePath;
- public String getLocalBasePath() {
- return localBasePath;
- }
- public void setLocalBasePath(String localBasePath) {
- this.localBasePath = localBasePath;
- }
-
-
- boolean doNotOverwrite;
- public boolean isDoNotOverwrite() {
- return doNotOverwrite;
- }
- public void setDoNotOverwrite(boolean doNotOverwrite) {
- this.doNotOverwrite = doNotOverwrite;
- }
-
+public class LocalFileStorage extends AbstractStorage{
@Override
public void delete(IResource fileResource) throws IOException {
@@ -167,15 +149,6 @@ private File getFile(IResource fileResource) {
+ fileResource.getPath());
}
- private String getTenantBasePath() {
- String tenantId = TenantContext.getThreadLocalInstance().getTenantId();
-
- if(tenantId==null){
- tenantId = "default";
- }
-
- return getLocalBasePath() + "/" + tenantId + "/";
- }
@Override
public void move(IResource src, IContainer container) throws IOException {
diff --git a/uengine-social-bpm-portal/src/main/webapp/WEB-INF/customContext.xml b/uengine-social-bpm-portal/src/main/webapp/WEB-INF/customContext.xml
index c3cc4ec1..30836d30 100644
--- a/uengine-social-bpm-portal/src/main/webapp/WEB-INF/customContext.xml
+++ b/uengine-social-bpm-portal/src/main/webapp/WEB-INF/customContext.xml
@@ -16,8 +16,14 @@
-
-
+
+
+
+
+
+
+
+
diff --git a/uengine-social-bpm-portal/src/test/java/org/uengine/modeling/resource/LocalFileStorageTest.java b/uengine-social-bpm-portal/src/test/java/org/uengine/modeling/resource/LocalFileStorageTest.java
index b38ccd97..51e8f556 100644
--- a/uengine-social-bpm-portal/src/test/java/org/uengine/modeling/resource/LocalFileStorageTest.java
+++ b/uengine-social-bpm-portal/src/test/java/org/uengine/modeling/resource/LocalFileStorageTest.java
@@ -28,7 +28,7 @@ public void initialize() throws Exception{
localFileStorage = new LocalFileStorage();
localFileStorage.setDoNotOverwrite(false);
- localFileStorage.setLocalBasePath("./target/resource_framework_test_disposable");
+ localFileStorage.setBasePath("./target/resource_framework_test_disposable");
resourceManager = new ResourceManager();
resourceManager.setStorage(localFileStorage);