You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@clerezza.apache.org by it...@apache.org on 2010/09/15 11:04:39 UTC

svn commit: r997235 - in /incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.utils.customproperty/src/main/java/org/apache/clerezza/utils/customproperty: CustomProperty.java ontology/CUSTOMPROPERTY.java

Author: ito
Date: Wed Sep 15 09:04:35 2010
New Revision: 997235

URL: http://svn.apache.org/viewvc?rev=997235&view=rev
Log:
CLEREZZA-300: locks added and dct:description

Modified:
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.utils.customproperty/src/main/java/org/apache/clerezza/utils/customproperty/CustomProperty.java
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.utils.customproperty/src/main/java/org/apache/clerezza/utils/customproperty/ontology/CUSTOMPROPERTY.java

Modified: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.utils.customproperty/src/main/java/org/apache/clerezza/utils/customproperty/CustomProperty.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.utils.customproperty/src/main/java/org/apache/clerezza/utils/customproperty/CustomProperty.java?rev=997235&r1=997234&r2=997235&view=diff
==============================================================================
--- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.utils.customproperty/src/main/java/org/apache/clerezza/utils/customproperty/CustomProperty.java (original)
+++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.utils.customproperty/src/main/java/org/apache/clerezza/utils/customproperty/CustomProperty.java Wed Sep 15 09:04:35 2010
@@ -21,6 +21,7 @@ package org.apache.clerezza.utils.custom
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
+import java.util.concurrent.locks.Lock;
 
 import org.apache.clerezza.utils.customproperty.ontology.CUSTOMPROPERTY;
 import org.apache.clerezza.platform.graphprovider.content.ContentGraphProvider;
@@ -30,8 +31,10 @@ import org.apache.clerezza.rdf.core.MGra
 import org.apache.clerezza.rdf.core.NonLiteral;
 import org.apache.clerezza.rdf.core.Triple;
 import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.access.LockableMGraph;
 import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl;
 import org.apache.clerezza.rdf.core.impl.TripleImpl;
+import org.apache.clerezza.rdf.ontologies.DCTERMS;
 import org.apache.clerezza.rdf.ontologies.RDF;
 
 /**
@@ -65,21 +68,48 @@ public class CustomProperty {
 	public boolean addSingleCustomField(UriRef dependency,
 		String dependencyValue, String label, UriRef property, int length,
 		int cardinality) {
-		MGraph contentGraph = cgProvider.getContentGraph();
-		
+			return addSingleCustomField(dependency, dependencyValue, label, null,
+					null, property, length, cardinality);
+	}
+
+	/**
+	 * Adding a single customfield to customize any item of a dependency
+	 *
+	 * @param dependency		type UriRef defining the dependency item of the customfield
+	 * @param dependencyValue	String to specify the property within the dependency type
+	 * @param label				label of the customfield
+	 * @param description		the description about the usage of this custom field
+	 * @param config			configuration parameter for this customfield
+	 * @param property			UriRef defining the meaning of the customfield
+	 * @param length
+	 * @param cardinality
+	 *
+	 * @return true if field could be added
+	 */
+	public boolean addSingleCustomField(UriRef dependency,
+		String dependencyValue, String label, String description, String config, 
+			UriRef property, int length, int cardinality) {
+		LockableMGraph contentGraph = cgProvider.getContentGraph();
+
 		NonLiteral customfield = addBasicCustomField(contentGraph,
-			property, cardinality, label, getCustomPropertyCollection(
+			property, cardinality, label, description, config, getCustomPropertyCollection(
 				dependency, dependencyValue));
-		
-		if(customfield != null){
-			contentGraph.add(new TripleImpl( customfield , CUSTOMPROPERTY.length,
-				LiteralFactory.getInstance().createTypedLiteral(length)));
-			return true;
-		} else {
-			return false;
+		Lock lock = contentGraph.getLock().writeLock();
+		lock.lock();
+		try {
+			if(customfield != null){
+				contentGraph.add(new TripleImpl( customfield , CUSTOMPROPERTY.length,
+					LiteralFactory.getInstance().createTypedLiteral(length)));
+				return true;
+			} else {
+				return false;
+			}
+		} finally {
+			lock.unlock();
 		}
 	}
 
+
 	/**
 	 * Adding a customfield to select one or more values within some predefined ones
 	 * 
@@ -96,50 +126,97 @@ public class CustomProperty {
 	public boolean addMultipleCustomField(UriRef dependency,
 			String dependencyValue, String label, UriRef property,
 			String multiselect, String selectableValues, int cardinality) {
-		MGraph contentGraph = cgProvider.getContentGraph();
-			
+		
+		return addMultipleCustomField(dependency, dependencyValue, label, null, null, property,
+				multiselect, selectableValues, cardinality);
+	}
+
+	/**
+	 * Adding a customfield to select one or more values within some predefined ones
+	 *
+	 * @param dependency		type UriRef defining the dependency item of the customfield
+	 * @param dependencyValue	String to specify the property within the dependency type
+	 * @param label				label of the customfield
+	 * @param description		the description about the usage of this custom field
+	 * @param config			configuration parameter for this customfield
+	 * @param property			UriRef defining the meaning of the customfield
+	 * @param multiselect		defines if one or more values can be selected
+	 * @param selectableValues	the values as a string seperated with a ","
+	 * @param cardinality
+	 *
+	 * @return true if field could be added
+	 */
+	public boolean addMultipleCustomField(UriRef dependency,
+			String dependencyValue, String label, String description, String config, UriRef property,
+			String multiselect, String selectableValues, int cardinality) {
+		LockableMGraph contentGraph = cgProvider.getContentGraph();
+
 		NonLiteral customfield = addBasicCustomField(contentGraph, property,
-			cardinality, label, getCustomPropertyCollection(dependency,
+			cardinality, label, description, config, getCustomPropertyCollection(dependency,
 				dependencyValue));
-		if(customfield != null){
-			Collection<Triple> tripleArray = new ArrayList<Triple>();
-			String[] values = selectableValues.split(",");
-			for (int i = 0; i < values.length; i++) {
-				tripleArray
-						.add(new TripleImpl(customfield, CUSTOMPROPERTY.value,
-								LiteralFactory.getInstance().createTypedLiteral(
-										values[i])));
+		Lock lock = contentGraph.getLock().writeLock();
+		lock.lock();
+		try {
+			if(customfield != null){
+				Collection<Triple> tripleArray = new ArrayList<Triple>();
+				String[] values = selectableValues.split(",");
+				for (int i = 0; i < values.length; i++) {
+					tripleArray
+							.add(new TripleImpl(customfield, CUSTOMPROPERTY.value,
+									LiteralFactory.getInstance().createTypedLiteral(
+											values[i])));
+				}
+				tripleArray.add(new TripleImpl(customfield,
+						CUSTOMPROPERTY.multiselectable, LiteralFactory.getInstance()
+								.createTypedLiteral(multiselect)));
+				contentGraph.addAll(tripleArray);
+				return true;
+			} else {
+				return false;
 			}
-			tripleArray.add(new TripleImpl(customfield,
-					CUSTOMPROPERTY.multiselectable, LiteralFactory.getInstance()
-							.createTypedLiteral(multiselect)));
-			contentGraph.addAll(tripleArray);
-			return true;
-		} else {
-			return false;
+		} finally {
+			lock.unlock();
 		}
 	}
 	
-	protected NonLiteral addBasicCustomField(MGraph contentGraph,
-			UriRef property, int cardinality, String label,
-			NonLiteral propertyCollection) {
-		Collection<Triple> tripleArray = new ArrayList<Triple>();
-		NonLiteral customField = new BNode();
-		contentGraph.add(new TripleImpl(customField, 
-				CUSTOMPROPERTY.property, property));
-		tripleArray.add(new TripleImpl(propertyCollection,
-				CUSTOMPROPERTY.customfield, customField));
-		tripleArray.add(new TripleImpl(customField, RDF.type,
-				CUSTOMPROPERTY.CustomField));
-		tripleArray.add(new TripleImpl(customField, CUSTOMPROPERTY.cardinality,
-				LiteralFactory.getInstance().createTypedLiteral(cardinality)));
-		tripleArray.add(new TripleImpl(customField,
-				CUSTOMPROPERTY.presentationlabel, new PlainLiteralImpl(label)));
-		if(contentGraph.addAll(tripleArray)){
-			return customField;
-		} else {
-			return null;
+	protected NonLiteral addBasicCustomField(LockableMGraph contentGraph,
+			UriRef property, int cardinality, String label, String description,
+			String config, NonLiteral propertyCollection) {
+		Lock lock = contentGraph.getLock().writeLock();
+		lock.lock();
+		try {
+			if(contentGraph.filter(null, CUSTOMPROPERTY.property, property).hasNext()) {
+				return null;
+			}
+			Collection<Triple> tripleArray = new ArrayList<Triple>();
+			NonLiteral customField = new BNode();
+			contentGraph.add(new TripleImpl(customField,
+					CUSTOMPROPERTY.property, property));
+			tripleArray.add(new TripleImpl(propertyCollection,
+					CUSTOMPROPERTY.customfield, customField));
+			tripleArray.add(new TripleImpl(customField, RDF.type,
+					CUSTOMPROPERTY.CustomField));
+			tripleArray.add(new TripleImpl(customField, CUSTOMPROPERTY.cardinality,
+					LiteralFactory.getInstance().createTypedLiteral(cardinality)));
+			tripleArray.add(new TripleImpl(customField,
+					CUSTOMPROPERTY.presentationlabel, new PlainLiteralImpl(label)));
+			if(description != null && !description.isEmpty()) {
+				tripleArray.add(new TripleImpl(customField,
+					DCTERMS.description, new PlainLiteralImpl(description)));
+			}
+			if(config != null && !config.isEmpty()) {
+				tripleArray.add(new TripleImpl(customField,
+					CUSTOMPROPERTY.configuration, new PlainLiteralImpl(config)));
+			}
+			if(contentGraph.addAll(tripleArray)){
+				return customField;
+			} else {
+				return null;
+			}
+		} finally {
+			lock.unlock();
 		}
+
 		
 	}
 
@@ -153,35 +230,47 @@ public class CustomProperty {
 	 */
 	public NonLiteral getCustomPropertyCollection(UriRef dependency,
 			String dependencyValue) {
-		MGraph contentGraph = cgProvider.getContentGraph();
-		Iterator<Triple> collections = contentGraph.filter(null, RDF.type,
-				CUSTOMPROPERTY.CustomFieldCollection);
-		while (collections.hasNext()) {
-			Iterator<Triple> collections2 = contentGraph
-					.filter(collections.next().getSubject(),
-							CUSTOMPROPERTY.dependency, dependency);
-			while (collections2.hasNext()) {
-				Iterator<Triple> collections3 = contentGraph.filter(
-						collections2.next().getSubject(),
-						CUSTOMPROPERTY.dependencyvalue, LiteralFactory
-								.getInstance().createTypedLiteral(
-										dependencyValue));
-				if (collections3.hasNext()) {
-					return collections3.next().getSubject();
+		LockableMGraph contentGraph = cgProvider.getContentGraph();
+		Lock lock = contentGraph.getLock().readLock();
+		lock.lock();
+		try {
+			Iterator<Triple> collections = contentGraph.filter(null, RDF.type,
+					CUSTOMPROPERTY.CustomFieldCollection);
+			while (collections.hasNext()) {
+				Iterator<Triple> collections2 = contentGraph
+						.filter(collections.next().getSubject(),
+								CUSTOMPROPERTY.dependency, dependency);
+				while (collections2.hasNext()) {
+					Iterator<Triple> collections3 = contentGraph.filter(
+							collections2.next().getSubject(),
+							CUSTOMPROPERTY.dependencyvalue, LiteralFactory
+									.getInstance().createTypedLiteral(
+											dependencyValue));
+					if (collections3.hasNext()) {
+						return collections3.next().getSubject();
+					}
 				}
 			}
+		} finally {
+			lock.unlock();
+		}
+		lock = contentGraph.getLock().writeLock();
+		lock.lock();
+		try {
+			Collection<Triple> tripleArray = new ArrayList<Triple>();
+			NonLiteral cfc = new BNode();
+			tripleArray.add(new TripleImpl(cfc, RDF.type,
+					CUSTOMPROPERTY.CustomFieldCollection));
+			tripleArray.add(new TripleImpl(cfc, CUSTOMPROPERTY.dependency,
+					dependency));
+			tripleArray.add(new TripleImpl(cfc, CUSTOMPROPERTY.dependencyvalue,
+					LiteralFactory.getInstance()
+							.createTypedLiteral(dependencyValue)));
+			contentGraph.addAll(tripleArray);
+			return getCustomPropertyCollection(dependency, dependencyValue);
+		} finally {
+			lock.unlock();
 		}
-		Collection<Triple> tripleArray = new ArrayList<Triple>();
-		NonLiteral cfc = new BNode();
-		tripleArray.add(new TripleImpl(cfc, RDF.type,
-				CUSTOMPROPERTY.CustomFieldCollection));
-		tripleArray.add(new TripleImpl(cfc, CUSTOMPROPERTY.dependency,
-				dependency));
-		tripleArray.add(new TripleImpl(cfc, CUSTOMPROPERTY.dependencyvalue,
-				LiteralFactory.getInstance()
-						.createTypedLiteral(dependencyValue)));
-		contentGraph.addAll(tripleArray);
-		return getCustomPropertyCollection(dependency, dependencyValue);
 	}
 	
 	/**
@@ -190,12 +279,18 @@ public class CustomProperty {
 	 */
 	public ArrayList<NonLiteral>getCustomfieldsOfCollection(NonLiteral collection){
 		ArrayList<NonLiteral> customfields = new ArrayList<NonLiteral>();
-		MGraph contentGraph = cgProvider.getContentGraph();
-		Iterator <Triple> result= contentGraph.filter(collection, CUSTOMPROPERTY.customfield, null);
-		while(result.hasNext()){
-			customfields.add((NonLiteral) result.next().getObject());
+		LockableMGraph contentGraph = cgProvider.getContentGraph();
+		Lock lock = contentGraph.getLock().readLock();
+		lock.lock();
+		try {
+			Iterator <Triple> result= contentGraph.filter(collection, CUSTOMPROPERTY.customfield, null);
+			while(result.hasNext()){
+				customfields.add((NonLiteral) result.next().getObject());
+			}
+			return customfields;
+		} finally {
+			lock.unlock();
 		}
-		return customfields;
 	}
 
 	/**
@@ -204,15 +299,22 @@ public class CustomProperty {
 	 */
 	public ArrayList<UriRef>getPropertiesOfCollection(NonLiteral collection){
 		ArrayList<UriRef> customproperties = new ArrayList<UriRef>();
-		MGraph contentGraph = cgProvider.getContentGraph();
-		Iterator <Triple> result= contentGraph.filter(collection, CUSTOMPROPERTY.customfield, null);
-		while(result.hasNext()){
-			Iterator <Triple> property= contentGraph.filter((NonLiteral)result.next().getObject(), CUSTOMPROPERTY.property, null);
-			if(property.hasNext()){
-				customproperties.add((UriRef)property.next().getObject());
+		LockableMGraph contentGraph = cgProvider.getContentGraph();
+		Lock lock = contentGraph.getLock().readLock();
+		lock.lock();
+		try {
+			Iterator <Triple> result= contentGraph.filter(collection, CUSTOMPROPERTY.customfield, null);
+			while(result.hasNext()){
+				Iterator <Triple> property= contentGraph.filter(
+						(NonLiteral)result.next().getObject(), CUSTOMPROPERTY.property, null);
+				if(property.hasNext()){
+					customproperties.add((UriRef)property.next().getObject());
+				}
 			}
+			return customproperties;
+		} finally {
+			lock.unlock();
 		}
-		return customproperties;
 	}
 
 	
@@ -227,32 +329,40 @@ public class CustomProperty {
 	 */
 	public boolean deleteCustomField(UriRef dependency, String dependencyValue,
 			UriRef property) {
-		MGraph contentGraph = cgProvider.getContentGraph();
+		LockableMGraph contentGraph = cgProvider.getContentGraph();
 		Collection<Triple> allCustomFieldTriples = new ArrayList<Triple>();
 		Iterator<Triple> customfields = contentGraph.filter(
 				getCustomPropertyCollection(dependency, dependencyValue),
 				CUSTOMPROPERTY.customfield, null);
-		while (customfields.hasNext()) {
-			Iterator<Triple> customfields2 = contentGraph.filter(
-					(NonLiteral) customfields.next().getObject(),
-					CUSTOMPROPERTY.property, property);
-			if (customfields2.hasNext()) {
-				NonLiteral customField = customfields2.next().getSubject();
-				Iterator<Triple> someCustomfieldTriples = contentGraph.filter(
-						customField, null, null);
-				while (someCustomfieldTriples.hasNext()) {
-					allCustomFieldTriples.add(someCustomfieldTriples.next());
-				}
-				Iterator<Triple> otherCustomFieldTriples = contentGraph.filter(
-						null, null, customField);
-				while (otherCustomFieldTriples.hasNext()) {
-					allCustomFieldTriples.add(otherCustomFieldTriples.next());
+		boolean customFieldDelete = false;
+		Lock lock = contentGraph.getLock().writeLock();
+		lock.lock();
+		try {
+			while (customfields.hasNext()) {
+				Iterator<Triple> customfields2 = contentGraph.filter(
+						(NonLiteral) customfields.next().getObject(),
+						CUSTOMPROPERTY.property, property);
+				if (customfields2.hasNext()) {
+					NonLiteral customField = customfields2.next().getSubject();
+					Iterator<Triple> someCustomfieldTriples = contentGraph.filter(
+							customField, null, null);
+					while (someCustomfieldTriples.hasNext()) {
+						allCustomFieldTriples.add(someCustomfieldTriples.next());
+					}
+					Iterator<Triple> otherCustomFieldTriples = contentGraph.filter(
+							null, null, customField);
+					while (otherCustomFieldTriples.hasNext()) {
+						allCustomFieldTriples.add(otherCustomFieldTriples.next());
+					}
+					customFieldDelete =  true;
 				}
-				contentGraph.removeAll(allCustomFieldTriples);
-				return true;
 			}
-		}
-		return false;
+			contentGraph.removeAll(allCustomFieldTriples);
+		} finally {
+			lock.unlock();
+		}		
+		return customFieldDelete;
+
 	}
 	
 	/**
@@ -262,7 +372,8 @@ public class CustomProperty {
 	 */
 	public UriRef getCustomFieldProperty(NonLiteral customfield){
 		MGraph contentGraph = cgProvider.getContentGraph();
-		return (UriRef)contentGraph.filter(customfield, CUSTOMPROPERTY.property, null).next().getObject();
+		return (UriRef)contentGraph.filter(customfield, CUSTOMPROPERTY.property,
+				null).next().getObject();
 	}
 	
 	protected void bindCgProvider(ContentGraphProvider cgProvider) {

Modified: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.utils.customproperty/src/main/java/org/apache/clerezza/utils/customproperty/ontology/CUSTOMPROPERTY.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.utils.customproperty/src/main/java/org/apache/clerezza/utils/customproperty/ontology/CUSTOMPROPERTY.java?rev=997235&r1=997234&r2=997235&view=diff
==============================================================================
--- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.utils.customproperty/src/main/java/org/apache/clerezza/utils/customproperty/ontology/CUSTOMPROPERTY.java (original)
+++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.utils.customproperty/src/main/java/org/apache/clerezza/utils/customproperty/ontology/CUSTOMPROPERTY.java Wed Sep 15 09:04:35 2010
@@ -42,6 +42,8 @@ public class CUSTOMPROPERTY {
 
 	public static final UriRef presentationlabel = new UriRef(
 			"http://clerezza.org/2009/06/custompropery#presentationlabel");
+	public static final UriRef configuration = new UriRef(
+			"http://clerezza.org/2009/06/custompropery#configuration");
 	public static final UriRef property = new UriRef(
 			"http://clerezza.org/2009/06/custompropery#property");
 	public static final UriRef cardinality = new UriRef(