Skip to content
This repository was archived by the owner on Mar 31, 2019. It is now read-only.

Commit 3833ed5

Browse files
authored
Merge pull request #261 from cristal-ise/feature/Issue1182-PropertyDescList-DescObject
Feature/issue182 property desc list desc object
2 parents 52caf28 + e214a62 commit 3833ed5

File tree

16 files changed

+645
-15
lines changed

16 files changed

+645
-15
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,12 @@
183183
<version>3.3</version>
184184
<scope>test</scope>
185185
</dependency>
186+
<dependency>
187+
<groupId>org.unitils</groupId>
188+
<artifactId>unitils-core</artifactId>
189+
<version>3.4.6</version>
190+
<scope>test</scope>
191+
</dependency>
186192
</dependencies>
187193

188194
<dependencyManagement>

src/main/java/org/cristalise/kernel/collection/DependencyDescription.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.cristalise.kernel.property.PropertyDescriptionList;
2828
import org.cristalise.kernel.property.PropertyUtility;
2929
import org.cristalise.kernel.utils.CastorHashMap;
30+
import org.cristalise.kernel.utils.Logger;
3031

3132
public class DependencyDescription extends Dependency implements CollectionDescription<DependencyMember> {
3233

@@ -54,15 +55,21 @@ public Collection<DependencyMember> newInstance() throws ObjectNotFoundException
5455
if (mMembers.list.size() == 1) {
5556
DependencyMember mem = mMembers.list.get(0);
5657
String descVer = getDescVer(mem);
58+
5759
PropertyDescriptionList pdList = PropertyUtility.getPropertyDescriptionOutcome(mem.getItemPath(), descVer, null);
5860

5961
if (pdList != null) {
6062
newDep.setProperties(PropertyUtility.convertTransitiveProperties(pdList));
6163
newDep.setClassProps(pdList.getClassProps());
6264
}
65+
else
66+
Logger.warning("DependencyDescription.newInstance("+getName()+") - No PropertyDesc was found. Dependency cannot check member type.");
6367

6468
if (mProperties != null) newDep.getProperties().merge(mProperties);
6569
}
70+
else
71+
Logger.warning("DependencyDescription.newInstance("+getName()+") - No PropertyDesc was found. Dependency cannot check member type.");
72+
6673
return newDep;
6774
}
6875

@@ -83,5 +90,4 @@ public void checkMembership() throws InvalidCollectionModification {
8390
if (mMembers.list.size() > 0)
8491
throw new InvalidCollectionModification("Dependency descriptions may not have more than one member.");
8592
}
86-
8793
}

src/main/java/org/cristalise/kernel/entity/proxy/ItemProxy.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,30 @@ public Outcome getOutcome(Viewpoint view, Object locker) throws ObjectNotFoundEx
738738
}
739739
}
740740

741+
/**
742+
* Gets the Outcome associated with the Event.
743+
*
744+
* @param event the Event to be used
745+
* @return the Outcome object
746+
* @throws ObjectNotFoundException
747+
*/
748+
public Outcome getOutcome(Event event) throws ObjectNotFoundException {
749+
return getOutcome(event, transactionKey);
750+
}
751+
752+
/**
753+
* Gets the Outcome associated with the Event. This method can be used in server side Script to find uncommitted changes
754+
* during the active transaction.
755+
*
756+
* @param event the Event to be used
757+
* @param locker the transaction key
758+
* @return the Outcome object
759+
* @throws ObjectNotFoundException object was not found
760+
*/
761+
public Outcome getOutcome(Event event, Object locker) throws ObjectNotFoundException {
762+
return getOutcome(event.getSchemaName(), event.getSchemaVersion(), event.getID(), locker);
763+
}
764+
741765
/**
742766
* Check if the given OutcomeAttachment exists
743767
*

src/main/java/org/cristalise/kernel/graph/model/BuiltInVertexProperties.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,20 @@ public enum BuiltInVertexProperties {
143143
*/
144144
OUTCOME_INIT("OutcomeInit"),
145145

146+
/**
147+
* String property. It contains either the name or the UUID of the PropertyDescription Item.
148+
*
149+
* Can be null or undefined.
150+
*/
151+
PROPERTY_DEF_NAME("PropertyDefName"),
152+
153+
/**
154+
* Integer property. It contains the version number of PropertyDescription Item.
155+
*
156+
* Can be null or undefined.
157+
*/
158+
PROPERTY_DEF_VERSION("PropertyDefVersion"),
159+
146160
/**
147161
* Boolean property. Enables the Loop Transition of the CompositeActivity StateMachine
148162
*/
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* This file is part of the CRISTAL-iSE kernel.
3+
* Copyright (c) 2001-2015 The CRISTAL Consortium. All rights reserved.
4+
*
5+
* This library is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU Lesser General Public License as published
7+
* by the Free Software Foundation; either version 3 of the License, or (at
8+
* your option) any later version.
9+
*
10+
* This library is distributed in the hope that it will be useful, but WITHOUT
11+
* ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
13+
* License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this library; if not, write to the Free Software Foundation,
17+
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
18+
*
19+
* http://www.fsf.org/licensing/licenses/lgpl.html
20+
*/
21+
package org.cristalise.kernel.process.module;
22+
23+
import org.cristalise.kernel.common.InvalidDataException;
24+
import org.cristalise.kernel.common.ObjectNotFoundException;
25+
import org.cristalise.kernel.entity.proxy.ItemProxy;
26+
import org.cristalise.kernel.process.resource.BuiltInResources;
27+
28+
import lombok.Getter;
29+
import lombok.Setter;
30+
31+
@Getter @Setter
32+
public class ModulePropertyDescription extends ModuleResource {
33+
34+
public ModulePropertyDescription() {
35+
super();
36+
type = BuiltInResources.PROPERTY_DESC_RESOURCE;
37+
}
38+
39+
public ModulePropertyDescription(ItemProxy child, Integer version) throws ObjectNotFoundException, InvalidDataException {
40+
this();
41+
this.version = version;
42+
}
43+
}

src/main/java/org/cristalise/kernel/process/resource/BuiltInResources.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
@Getter
3030
public enum BuiltInResources {
3131
// typeCode, schemaName, typeRoot, workflowDef
32-
PROPERTY_DESC_RESOURCE("property", "PropertyDescription", null, null), //'abstract' resource - does not have an Item
3332
ACTIVITY_DESC_RESOURCE("AC", "ActivityDef", null, null), //'abstract' resource - does not have an Item
33+
PROPERTY_DESC_RESOURCE("property", "PropertyDescription", "/desc/PropertyDesc", "ManagePropertyDesc"),
3434
MODULE_RESOURCE( "module", "Module", "/desc/Module", "ManageModule"),
3535
SCHEMA_RESOURCE( "OD", "Schema", "/desc/Schema", "ManageSchema"),
3636
SCRIPT_RESOURCE( "SC", "Script", "/desc/Script", "ManageScript"),

src/main/java/org/cristalise/kernel/property/PropertyDescriptionList.java

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,53 @@
2020
*/
2121
package org.cristalise.kernel.property;
2222

23+
import java.io.File;
24+
import java.io.IOException;
25+
import java.io.Writer;
2326
import java.util.ArrayList;
2427
import java.util.HashMap;
2528

29+
import org.cristalise.kernel.collection.CollectionArrayList;
2630
import org.cristalise.kernel.common.InvalidDataException;
31+
import org.cristalise.kernel.common.ObjectNotFoundException;
32+
import org.cristalise.kernel.lookup.ItemPath;
33+
import org.cristalise.kernel.process.Gateway;
34+
import org.cristalise.kernel.process.resource.BuiltInResources;
2735
import org.cristalise.kernel.utils.CastorArrayList;
36+
import org.cristalise.kernel.utils.DescriptionObject;
37+
import org.cristalise.kernel.utils.FileStringUtility;
38+
import org.cristalise.kernel.utils.Logger;
2839

40+
import lombok.Getter;
41+
import lombok.Setter;
42+
43+
44+
@Getter @Setter
45+
public class PropertyDescriptionList extends CastorArrayList<PropertyDescription> implements DescriptionObject {
46+
String name;
47+
Integer version;
48+
ItemPath itemPath;
2949

30-
public class PropertyDescriptionList extends CastorArrayList<PropertyDescription>
31-
{
3250
public PropertyDescriptionList() {
3351
super();
3452
}
3553

54+
public PropertyDescriptionList(String name, Integer version) {
55+
super();
56+
this.name = name;
57+
this.version = version;
58+
}
59+
3660
public PropertyDescriptionList(ArrayList<PropertyDescription> aList) {
3761
super(aList);
3862
}
3963

64+
public PropertyDescriptionList(String name, Integer version, ArrayList<PropertyDescription> aList) {
65+
super(aList);
66+
this.name = name;
67+
this.version = version;
68+
}
69+
4070
public String getClassProps() {
4171
StringBuffer props = new StringBuffer();
4272
for (PropertyDescription element : list) {
@@ -111,4 +141,49 @@ public PropertyArrayList instantiate(PropertyArrayList initProps) throws Invalid
111141
}
112142
return propInst;
113143
}
144+
145+
@Override
146+
public String getItemID() {
147+
return (itemPath != null) ? itemPath.getUUID().toString() : null;
148+
}
149+
150+
@Override
151+
public CollectionArrayList makeDescCollections() throws InvalidDataException, ObjectNotFoundException {
152+
return new CollectionArrayList();
153+
}
154+
155+
@Override
156+
public void export(Writer imports, File dir, boolean shallow) throws InvalidDataException, ObjectNotFoundException, IOException {
157+
String xml;
158+
String typeCode = BuiltInResources.PROPERTY_DESC_RESOURCE.getTypeCode();
159+
String fileName = getName() + (getVersion() == null ? "" : "_" + getVersion()) + ".xml";
160+
161+
try {
162+
xml = Gateway.getMarshaller().marshall(this);
163+
}
164+
catch (Exception e) {
165+
Logger.error(e);
166+
throw new InvalidDataException("Couldn't marshall PropertyDescriptionList name:" + getName());
167+
}
168+
169+
FileStringUtility.string2File(new File(new File(dir, typeCode), fileName), xml);
170+
171+
if (imports == null) return;
172+
173+
if (Gateway.getProperties().getBoolean("Resource.useOldImportFormat", false)) {
174+
imports.write("<Resource "
175+
+ "name='" + getName() + "' "
176+
+ (getItemPath() == null ? "" : "id='" + getItemID() + "' ")
177+
+ (getVersion() == null ? "" : "version='" + getVersion() + "' ")
178+
+ "type='" + typeCode + "'>boot/" + typeCode + "/" + fileName
179+
+ "</Resource>\n");
180+
}
181+
else {
182+
imports.write("<PropertyDescriptionResource "
183+
+ "name='" + getName() + "' "
184+
+ (getItemPath() == null ? "" : "id='" + getItemID() + "' ")
185+
+ (getVersion() == null ? "" : "version='" + getVersion() + "'")
186+
+ "/>\n");
187+
}
188+
}
114189
}

src/main/java/org/cristalise/kernel/property/PropertyUtility.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
*/
2121
package org.cristalise.kernel.property;
2222

23+
import static org.cristalise.kernel.process.resource.BuiltInResources.PROPERTY_DESC_RESOURCE;
24+
import static org.cristalise.kernel.property.BuiltInItemProperties.NAME;
25+
import static org.cristalise.kernel.property.BuiltInItemProperties.TYPE;
26+
2327
import java.util.ArrayList;
2428
import java.util.Iterator;
2529

@@ -29,7 +33,9 @@
2933
import org.cristalise.kernel.persistency.ClusterType;
3034
import org.cristalise.kernel.persistency.outcome.Outcome;
3135
import org.cristalise.kernel.process.Gateway;
36+
import org.cristalise.kernel.process.resource.BuiltInResources;
3237
import org.cristalise.kernel.utils.CastorHashMap;
38+
import org.cristalise.kernel.utils.LocalObjectLoader;
3339
import org.cristalise.kernel.utils.Logger;
3440

3541
public class PropertyUtility {
@@ -52,6 +58,10 @@ public static boolean propertyExists(ItemPath itemPath, String propName, Object
5258
return false;
5359
}
5460

61+
public static Property getProperty(ItemPath itemPath, BuiltInItemProperties prop, Object locker) throws ObjectNotFoundException {
62+
return getProperty(itemPath, prop.getName(), locker);
63+
}
64+
5565
public static Property getProperty(ItemPath itemPath, String propName, Object locker) throws ObjectNotFoundException {
5666
try {
5767
return (Property)Gateway.getStorage().get(itemPath, ClusterType.PROPERTY+"/"+propName, locker);
@@ -85,8 +95,14 @@ static public String getClassIdNames(ArrayList<PropertyDescription> pdlist) {
8595

8696
static public PropertyDescriptionList getPropertyDescriptionOutcome(ItemPath itemPath, String descVer, Object locker) throws ObjectNotFoundException {
8797
try {
88-
Outcome outc = (Outcome) Gateway.getStorage().get(itemPath,ClusterType.VIEWPOINT+"/PropertyDescription/"+descVer+"/data", locker);
89-
return (PropertyDescriptionList) Gateway.getMarshaller().unmarshall(outc.getData());
98+
if (getProperty(itemPath, TYPE, locker).getValue().equals(PROPERTY_DESC_RESOURCE.getSchemaName())) {
99+
String name = getProperty(itemPath, NAME, locker).getValue();
100+
return LocalObjectLoader.getPropertyDescriptionList(name, Integer.parseInt(descVer));
101+
}
102+
else {
103+
Outcome outc = (Outcome) Gateway.getStorage().get(itemPath, ClusterType.VIEWPOINT+"/PropertyDescription/"+descVer+"/data", locker);
104+
return (PropertyDescriptionList) Gateway.getMarshaller().unmarshall(outc.getData());
105+
}
90106
}
91107
catch (Exception ex) {
92108
Logger.error(ex);

src/main/java/org/cristalise/kernel/utils/LocalObjectLoader.java

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
*/
2121
package org.cristalise.kernel.utils;
2222

23+
import static org.cristalise.kernel.graph.model.BuiltInVertexProperties.PROPERTY_DEF_NAME;
24+
import static org.cristalise.kernel.graph.model.BuiltInVertexProperties.PROPERTY_DEF_VERSION;
2325
import static org.cristalise.kernel.graph.model.BuiltInVertexProperties.QUERY_NAME;
2426
import static org.cristalise.kernel.graph.model.BuiltInVertexProperties.QUERY_VERSION;
2527
import static org.cristalise.kernel.graph.model.BuiltInVertexProperties.SCHEMA_NAME;
@@ -39,18 +41,20 @@
3941
import org.cristalise.kernel.lifecycle.instance.stateMachine.StateMachine;
4042
import org.cristalise.kernel.lookup.ItemPath;
4143
import org.cristalise.kernel.persistency.outcome.Schema;
44+
import org.cristalise.kernel.property.PropertyDescriptionList;
4245
import org.cristalise.kernel.querying.Query;
4346
import org.cristalise.kernel.scripting.Script;
4447

4548

4649
public class LocalObjectLoader {
47-
private static ActDefCache actCache = new ActDefCache(null);
48-
private static ActDefCache compActCache = new ActDefCache(true);
49-
private static ActDefCache elemActCache = new ActDefCache(false);
50-
private static StateMachineCache smCache = new StateMachineCache();
51-
private static SchemaCache schCache = new SchemaCache();
52-
private static ScriptCache scrCache = new ScriptCache();
53-
private static QueryCache queryCache = new QueryCache();
50+
private static ActDefCache actCache = new ActDefCache(null);
51+
private static ActDefCache compActCache = new ActDefCache(true);
52+
private static ActDefCache elemActCache = new ActDefCache(false);
53+
private static StateMachineCache smCache = new StateMachineCache();
54+
private static SchemaCache schCache = new SchemaCache();
55+
private static ScriptCache scrCache = new ScriptCache();
56+
private static QueryCache queryCache = new QueryCache();
57+
private static PropertyDescriptionCache propDescCache = new PropertyDescriptionCache();
5458

5559
/**
5660
* Retrieves a named version of a script from the database
@@ -187,10 +191,41 @@ static public StateMachine getStateMachine(String smName, int smVersion) throws
187191
return smCache.get(smName, smVersion);
188192
}
189193

194+
/**
195+
*
196+
* @param properties
197+
* @return
198+
* @throws InvalidDataException
199+
* @throws ObjectNotFoundException
200+
*/
190201
static public StateMachine getStateMachine(CastorHashMap properties) throws InvalidDataException, ObjectNotFoundException {
191202
return (StateMachine)getDescObjectByProperty(properties, STATE_MACHINE_NAME, STATE_MACHINE_VERSION);
192203
}
193204

205+
/**
206+
*
207+
* @param name
208+
* @param version
209+
* @return
210+
* @throws ObjectNotFoundException
211+
* @throws InvalidDataException
212+
*/
213+
static public PropertyDescriptionList getPropertyDescriptionList(String name, int version) throws ObjectNotFoundException, InvalidDataException {
214+
Logger.msg(5, "LocalObjectLoader.PropertyDescriptionList("+name+" v"+version+")");
215+
return propDescCache.get(name, version);
216+
}
217+
218+
/**
219+
*
220+
* @param properties
221+
* @return
222+
* @throws InvalidDataException
223+
* @throws ObjectNotFoundException
224+
*/
225+
static public PropertyDescriptionList getPropertyDescriptionList(CastorHashMap properties) throws InvalidDataException, ObjectNotFoundException {
226+
return (PropertyDescriptionList)getDescObjectByProperty(properties, PROPERTY_DEF_NAME, PROPERTY_DEF_VERSION);
227+
}
228+
194229
/**
195230
*
196231
* @param properties

0 commit comments

Comments
 (0)