[caboto commit] r545 - ASSIGNED - # 236: Repeating properties per annotation

1 view
Skip to first unread message

codesite...@google.com

unread,
Jul 10, 2009, 9:26:27 AM7/10/09
to cabot...@googlegroups.com
Author: jasper....@gmail.com
Date: Fri Jul 10 06:24:46 2009
New Revision: 545

Added:

branches/stars/Caboto/caboto/src/main/java/org/caboto/domain/AnnotationException.java
- copied unchanged from r539,
/trunk/Caboto/caboto/src/main/java/org/caboto/domain/AnnotationException.java
Modified:
branches/stars/Caboto/caboto/pom.xml

branches/stars/Caboto/caboto/src/main/java/org/caboto/CabotoJsonSupport.java
branches/stars/Caboto/caboto/src/main/java/org/caboto/CabotoUtility.java

branches/stars/Caboto/caboto/src/main/java/org/caboto/dao/AnnotationDao.java

branches/stars/Caboto/caboto/src/main/java/org/caboto/dao/AnnotationDaoImpl.java

branches/stars/Caboto/caboto/src/main/java/org/caboto/domain/Annotation.java

branches/stars/Caboto/caboto/src/main/java/org/caboto/domain/AnnotationFactory.java

branches/stars/Caboto/caboto/src/main/java/org/caboto/profile/ProfileRepository.java

branches/stars/Caboto/caboto/src/main/java/org/caboto/profile/ProfileRepositoryXmlImpl.java

branches/stars/Caboto/caboto/src/main/java/org/caboto/validation/AnnotationValidatorImpl.java

branches/stars/Caboto/caboto/src/test/java/org/caboto/dao/AnnotationDaoImplTest.java

branches/stars/Caboto/caboto/src/test/java/org/caboto/profile/MockProfileRepositoryImpl.java

branches/stars/Caboto/caboto/src/test/java/org/caboto/rest/resources/AboutResourceTest.java

branches/stars/Caboto/caboto/src/test/java/org/caboto/rest/resources/AbstractResourceTest.java

branches/stars/Caboto/caboto/src/test/java/org/caboto/rest/resources/BasicAuthenticationClientFilter.java

branches/stars/Caboto/caboto/src/test/java/org/caboto/validation/AnnotationValidationTest.java
branches/stars/Caboto/caboto/src/test/resources/test-graph3.rdf (props
changed)

Log:
ASSIGNED - # 236: Repeating properties per annotation
https://webfutures.ilrt.bris.ac.uk/stars/ticket/236

Modified: branches/stars/Caboto/caboto/pom.xml
==============================================================================
--- branches/stars/Caboto/caboto/pom.xml (original)
+++ branches/stars/Caboto/caboto/pom.xml Fri Jul 10 06:24:46 2009
@@ -3,13 +3,13 @@
<parent>
<artifactId>caboto-parent</artifactId>
<groupId>org.caboto</groupId>
- <version>0.6</version>
+ <version>0.9-STARS</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.caboto</groupId>
<artifactId>caboto</artifactId>
<name>caboto</name>
- <version>0.6</version>
+ <version>0.9-STARS</version>
<url>http://maven.apache.org</url>
<build>
<filters>
@@ -247,7 +247,6 @@
<version>1.3</version>
<scope>test</scope>
</dependency>
-
</dependencies>

</project>

Modified:
branches/stars/Caboto/caboto/src/main/java/org/caboto/CabotoJsonSupport.java
==============================================================================
---
branches/stars/Caboto/caboto/src/main/java/org/caboto/CabotoJsonSupport.java
(original)
+++
branches/stars/Caboto/caboto/src/main/java/org/caboto/CabotoJsonSupport.java
Fri Jul 10 06:24:46 2009
@@ -33,15 +33,16 @@
*/
package org.caboto;

+import org.codehaus.jettison.json.JSONArray;
+import org.codehaus.jettison.json.JSONException;
+import org.codehaus.jettison.json.JSONObject;
+
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ResIterator;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.rdf.model.StmtIterator;
-import org.codehaus.jettison.json.JSONArray;
-import org.codehaus.jettison.json.JSONException;
-import org.codehaus.jettison.json.JSONObject;

/**
* A utility class used to convert RDF (Jena Model and Resource classes)
to JSON.
@@ -74,6 +75,10 @@
}

public JSONObject generateJsonObject(Resource resource) throws
JSONException {
+ return generateJsonObject(resource, false);
+ }
+
+ public JSONObject generateJsonObject(Resource resource, boolean
multiValued) throws JSONException {

JSONObject jsonObject = new JSONObject();
jsonObject.put("id", resource.getURI());
@@ -102,12 +107,18 @@
}

} else {
- jsonObject.put(key, generateJsonObject((Resource)
stmt.getObject()));
+ jsonObject.put(key, generateJsonObject((Resource)
stmt.getObject(), true));
}

} else if (stmt.getObject().isLiteral()) {
-
- jsonObject.put(key, (((Literal)
stmt.getObject()).getLexicalForm()));
+ if(multiValued) {
+ if(!jsonObject.has(key)) {
+ jsonObject.put(key, new JSONArray());
+ }
+ jsonObject.getJSONArray(key).put(((Literal)
stmt.getObject()).getLexicalForm());
+ } else {
+ jsonObject.put(key, ((Literal)
stmt.getObject()).getLexicalForm());
+ }
}

}

Modified:
branches/stars/Caboto/caboto/src/main/java/org/caboto/CabotoUtility.java
==============================================================================
---
branches/stars/Caboto/caboto/src/main/java/org/caboto/CabotoUtility.java
(original)
+++
branches/stars/Caboto/caboto/src/main/java/org/caboto/CabotoUtility.java
Fri Jul 10 06:24:46 2009
@@ -33,6 +33,7 @@
*/
package org.caboto;

+import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;
@@ -47,6 +48,8 @@
*/
public final class CabotoUtility {

+ private static String DATE_FORMAT_STRING="yyyy-MM-dd'T'HH:mm:ssZ";
+
/**
* Private constructor.
*/
@@ -69,6 +72,26 @@

return graphId + id;
}
+
+
+ public static String getGraphId(final String id) {
+
+ int index=id.lastIndexOf("/");
+ if (index!=-1) {
+ return id.substring(0,index+1);
+
+ }
+ return null;
+ }
+
+ public static String getId(final String uri) {
+
+ int index=uri.lastIndexOf("/");
+ if (index!=-1) {
+ return uri.substring(index+1);
+ }
+ return null;
+ }

/**
* <p>Parses a date to a format that is a valid XSD:dateTime.</p>
@@ -78,12 +101,21 @@
*/
public static String parseDate(final Date date) {

- String temp = new
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(date);
+ String temp = new
SimpleDateFormat(DATE_FORMAT_STRING).format(date);

return temp.substring(0, temp.length() - 2) + ":"
+ temp.substring(temp.length() - 2, temp.length());
}

+ public static Date parseDate (final String XsdDate) throws
ParseException{
+ String temp = XsdDate.substring(0, XsdDate.length() - 3)
+ + XsdDate.substring(XsdDate.length() - 2, XsdDate.length());
+
+ Date date = new SimpleDateFormat(DATE_FORMAT_STRING).parse(temp);
+ return date;
+ }
+
+
/**
* @param path the path details of a request.
* @return whether or not its a public resource.

Modified:
branches/stars/Caboto/caboto/src/main/java/org/caboto/dao/AnnotationDao.java
==============================================================================
---
branches/stars/Caboto/caboto/src/main/java/org/caboto/dao/AnnotationDao.java
(original)
+++
branches/stars/Caboto/caboto/src/main/java/org/caboto/dao/AnnotationDao.java
Fri Jul 10 06:24:46 2009
@@ -33,6 +33,8 @@
*/
package org.caboto.dao;

+import java.util.List;
+
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.Model;
import org.caboto.domain.Annotation;
@@ -53,8 +55,16 @@
Model findAnnotations(AnnotationFilter[] filters);

Model findAnnotationsByGraph(String graph, AnnotationFilter...
filters);
+
+ Annotation getAnnotation(String id);

Model findAnnotations(String about, AnnotationFilter... filters);
+
+ List<Annotation> getAnnotations(String about);
+
+ Model findAnnotationsByAuthor(String author);
+
+ List<Annotation> getAnnotationsByAuthor(String author);

void deleteAnnotation(Resource resource);


Modified:
branches/stars/Caboto/caboto/src/main/java/org/caboto/dao/AnnotationDaoImpl.java
==============================================================================
---
branches/stars/Caboto/caboto/src/main/java/org/caboto/dao/AnnotationDaoImpl.java
(original)
+++
branches/stars/Caboto/caboto/src/main/java/org/caboto/dao/AnnotationDaoImpl.java
Fri Jul 10 06:24:46 2009
@@ -44,6 +44,8 @@
import com.hp.hpl.jena.vocabulary.RDF;
import org.caboto.CabotoUtility;
import org.caboto.domain.Annotation;
+import org.caboto.domain.AnnotationException;
+import org.caboto.domain.AnnotationFactory;
import org.caboto.jena.db.Database;
import org.caboto.jena.db.Utils;
import org.caboto.profile.Profile;
@@ -53,6 +55,7 @@
import org.caboto.vocabulary.Annotea;

import java.util.Date;
+import java.util.List;
import org.caboto.filters.AnnotationFilter;
import org.caboto.filters.AnnotationFilterFactory;

@@ -70,6 +73,7 @@
this.database = database;
}

+
public void addAnnotation(final Annotation annotation) {

try {
@@ -102,15 +106,15 @@
annotationResource.addProperty(Annotea.author,
model.createResource(annotation.getAuthor()));

- Date created = new Date();
-
// creation date
+ if (annotation.getCreated()==null){
+ annotation.setCreated(new Date());
+ }
annotationResource.addProperty(Annotea.created,
-
model.createTypedLiteral(CabotoUtility.parseDate(created),
+
model.createTypedLiteral(CabotoUtility.parseDate(annotation.getCreated()),
XSDDatatype.XSDdateTime));

annotation.setId(uri);
- annotation.setCreated(created);

// --- CREATE THE BODY OF THE ANNOTATION ---

@@ -118,28 +122,27 @@
String bodyUri = uri + "#body";
Resource bodyResource = model.createResource(bodyUri);

-
for (ProfileEntry entry : profile.getProfileEntries()) {

- String val = annotation.getBody().get(entry.getId());
-
- if(val != null) { // may by un-required entry
-
- Property prop =
model.createProperty(entry.getPropertyType());
-
- String dataType = entry.getObjectDatatype();
-
- if (dataType != null) {
-
- if (dataType.equals("String")) {
- bodyResource.addProperty(prop, val,
XSDDatatype.XSDstring);
- }
-
- } else {
- bodyResource.addProperty(prop, val);
- }
- }
-
+ List<String> values =
annotation.getBody().get(entry.getId());
+ if ((values == null) && !entry.isRequired()){
+ continue;
+ }
+
+ for(String val: values) {
+ Property prop =
model.createProperty(entry.getPropertyType());
+
+ String dataType = entry.getObjectDatatype();
+
+ if (dataType != null) {
+ if (dataType.equals("String")) {
+ bodyResource.addProperty(prop, val,
XSDDatatype.XSDstring);
+ }
+
+ } else {
+ bodyResource.addProperty(prop, val);
+ }
+ }
}

// add the body to the resource
@@ -206,8 +209,44 @@
AnnotationFilterFactory.applyFilters(query, "body", filters);
return database.executeConstructQuery(query,
initialBindings);
+
+ }
+
+ public Annotation getAnnotation(final String id){
+ Annotation annotation=null;
+ try {
+ annotation=new Annotation(findAnnotation(id), profileRepository);
+ } catch (AnnotationException e) {
+ e.printStackTrace();
+ }
+ return annotation;
+ }
+
+ public List<Annotation> getAnnotations(final String about){
+ Model annModel = findAnnotations(about);
+ return
AnnotationFactory.annotationsFromModel(annModel,profileRepository);
+ }
+
+
+ public Model findAnnotationsByAuthor(final String author) {
+
+ // create bindings
+ QuerySolutionMap initialBindings = new QuerySolutionMap();
+
+ initialBindings.add("author",
ResourceFactory.createResource(author));
+
+ Model m = database.executeConstructQuery(findAnnotationSparql,
+ initialBindings);
+
+ return m;
+
}

+ public List<Annotation> getAnnotationsByAuthor(final String author){
+ Model annModel = findAnnotationsByAuthor(author);
+ return
AnnotationFactory.annotationsFromModel(annModel,profileRepository);
+ }
+
public void deleteAnnotation(final Resource resource) {

String id = resource.getURI();

Modified:
branches/stars/Caboto/caboto/src/main/java/org/caboto/domain/Annotation.java
==============================================================================
---
branches/stars/Caboto/caboto/src/main/java/org/caboto/domain/Annotation.java
(original)
+++
branches/stars/Caboto/caboto/src/main/java/org/caboto/domain/Annotation.java
Fri Jul 10 06:24:46 2009
@@ -33,9 +33,26 @@
*/
package org.caboto.domain;

+import java.text.ParseException;
+import java.util.ArrayList;
import java.util.Date;
-import java.util.Map;
import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.caboto.CabotoUtility;
+import org.caboto.profile.Profile;
+import org.caboto.profile.ProfileEntry;
+import org.caboto.profile.ProfileRepository;
+import org.caboto.vocabulary.Annotea;
+
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
+import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.rdf.model.Statement;
+import com.hp.hpl.jena.rdf.model.StmtIterator;
+import com.hp.hpl.jena.vocabulary.RDF;

/**
* @author Mike Jones (mike.a...@bristol.ac.uk)
@@ -48,7 +65,7 @@
}

public Annotation(final String id, final String graphId, final String
annotates,
- final String author, final Date created, final
Map<String, String> body,
+ final String author, final Date created, final
Map<String, List<String>> body,
final String type) {
this.id = id;
this.graphId = graphId;
@@ -58,6 +75,55 @@
this.body = body;
this.type = type;
}
+
+ public Annotation(Resource resource , ProfileRepository
profileRepository) throws AnnotationException {
+ Statement rtype = resource.getProperty(RDF.type);
+ if (rtype==null){
+ throw new AnnotationException("RDF type not set");
+ }
+ this.type = rtype.getResource().getURI();
+ Profile profile;
+ try {
+ profile = profileRepository.findProfileByUri(type);
+ } catch (Exception e) {
+ throw new AnnotationException(e);
+ }
+ if (profile==null){
+ throw new AnnotationException("RDF type unknown in profile");
+ }
+ this.type=profile.getId();
+ Model model=ModelFactory.createDefaultModel();
+ this.id = resource.getURI().toString();
+ this.graphId =CabotoUtility.getGraphId(id);
+ this.annotates =
resource.getProperty(Annotea.annotates).getResource().getURI();
+ this.author =
resource.getProperty(Annotea.author).getResource().getURI();
+ Resource bodyResource =
resource.getProperty(Annotea.body).getResource();
+ try {
+ this.created =
CabotoUtility.parseDate(resource.getProperty(Annotea.created).getString());
+ } catch (ParseException e) {
+ throw new AnnotationException(e);
+ }
+ ProfileEntry profileEntry=null;
+ Statement bodyValue=null;
+ Iterator<ProfileEntry> profileIter =
profile.getProfileEntries().iterator();
+ while (profileIter.hasNext()){
+ profileEntry=profileIter.next();
+ StmtIterator bodyValues =
bodyResource.listProperties(model.createProperty(profileEntry.getPropertyType()));
+ if(!bodyValues.hasNext()) {
+ if (profileEntry.isRequired()){
+ throw new AnnotationException("Annotation needs:" +
profileEntry.getId());
+ }
+ } else {
+ while(bodyValues.hasNext()) {
+ bodyValue=bodyValues.nextStatement();
+ if(!body.containsKey(profileEntry.getId())) {
+ body.put(profileEntry.getId(),new ArrayList<String>());
+ }
+ body.get(profileEntry.getId()).add(bodyValue.getString());
+ }
+ }
+ }
+ }

public String getId() {
return id;
@@ -96,14 +162,15 @@
}

public void setCreated(final Date created) {
+ System.err.println("Date="+created);
this.created = created;
}

- public Map<String, String> getBody() {
+ public Map<String, List<String>> getBody() {
return body;
}

- public void setBody(final Map<String, String> body) {
+ public void setBody(final Map<String, List<String>> body) {
this.body = body;
}

@@ -132,6 +199,6 @@
private String annotates;
private String author;
private Date created;
- private Map<String, String> body = new HashMap<String, String>();
+ private Map<String, List<String>> body = new HashMap<String,
List<String>>();
private String type = "";
}

Modified:
branches/stars/Caboto/caboto/src/main/java/org/caboto/domain/AnnotationFactory.java
==============================================================================
---
branches/stars/Caboto/caboto/src/main/java/org/caboto/domain/AnnotationFactory.java
(original)
+++
branches/stars/Caboto/caboto/src/main/java/org/caboto/domain/AnnotationFactory.java
Fri Jul 10 06:24:46 2009
@@ -34,8 +34,20 @@
package org.caboto.domain;

import javax.ws.rs.core.MultivaluedMap;
+
+import org.caboto.CabotoUtility;
+import org.caboto.profile.ProfileRepository;
+
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ResIterator;
+import com.hp.hpl.jena.rdf.model.Resource;
+
import java.net.URI;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.List;
+import java.util.Vector;

/**
* <p>A simple factory for creating Annotation objects.</p>
@@ -50,6 +62,31 @@
*/
private AnnotationFactory() {
}
+
+
+ /**
+ * <p>Creates a List of annotation objects based on values received
from a rdf Model</p>
+ *
+ * @param model the RDF model containing AnnotoationsURI of the named
graph that will hold the annotation.
+ * @param params the parameters from an HTTP POST.
+ * @return an annotation object based on the HTTP POST values.
+ */
+
+ public static List<Annotation> annotationsFromModel(Model model,
ProfileRepository profileRepository){
+ List<Annotation> annList = new Vector<Annotation>();
+ ResIterator resIt = model.listSubjects();
+ while (resIt.hasNext()){
+ Resource annResource = resIt.nextResource();
+ Annotation annotation;
+ try {
+ annotation = new Annotation(annResource,profileRepository);
+ annList.add(annotation);
+ } catch (AnnotationException e) {
+ // resource is not an annotation
+ }
+ }
+ return annList;
+ }

/**
* <p>Creates an annotation object based on values received from a map
- the map values
@@ -85,10 +122,20 @@
if (params.get("type") != null) {
annotation.setType(params.remove("type").get(0));
}
+
+ Date date=new Date();
+ if (params.get("created") !=null) {
+ try {
+ date = CabotoUtility.parseDate(params.remove("created").get(0));
+ } catch (ParseException e) {
+ // do nothing
+ }
+ }
+ annotation.setCreated(date);

// copy the rest of map
for (String key : params.keySet()) {
- annotation.getBody().put(key, params.get(key).get(0));
+ annotation.getBody().put(key, params.get(key));
}

return annotation;

Modified:
branches/stars/Caboto/caboto/src/main/java/org/caboto/profile/ProfileRepository.java
==============================================================================
---
branches/stars/Caboto/caboto/src/main/java/org/caboto/profile/ProfileRepository.java
(original)
+++
branches/stars/Caboto/caboto/src/main/java/org/caboto/profile/ProfileRepository.java
Fri Jul 10 06:24:46 2009
@@ -40,5 +40,7 @@
public interface ProfileRepository {

Profile findProfile(String profileId) throws
ProfileRepositoryException;
+
+ Profile findProfileByUri(String profileUri) throws
ProfileRepositoryException;

}

Modified:
branches/stars/Caboto/caboto/src/main/java/org/caboto/profile/ProfileRepositoryXmlImpl.java
==============================================================================
---
branches/stars/Caboto/caboto/src/main/java/org/caboto/profile/ProfileRepositoryXmlImpl.java
(original)
+++
branches/stars/Caboto/caboto/src/main/java/org/caboto/profile/ProfileRepositoryXmlImpl.java
Fri Jul 10 06:24:46 2009
@@ -143,6 +143,68 @@
return profile;
}

+ public Profile findProfileByUri(final String profileUri) throws
ProfileRepositoryException {
+
+ Profile profile = null;
+
+ if (profileUri == null) {
+
+ // ????????????????????????
+ }
+
+ try {
+
+ // find the profile matching the id
+ XPathFactory xpathFactory = XPathFactory.newInstance();
+ XPath xpath = xpathFactory.newXPath();
+ XPathExpression expression =
+ xpath.compile("//profile[@type=\"" + profileUri
+ "\"]");
+ Object result = expression.evaluate(document,
XPathConstants.NODE);
+
+ // get the profile
+ Node node = (Node) result;
+
+ // find the rdf type
+ NamedNodeMap attributes = node.getAttributes();
+ String profileId =
attributes.getNamedItem("id").getTextContent();
+
+ // get the child nodes
+ NodeList list = node.getChildNodes();
+
+ // temp container to hold profile entries
+ List<Node> profileEntryList = new ArrayList<Node>();
+
+ for (int i = 0; i < list.getLength(); i++) {
+
+ Node n = list.item(i);
+
+ if (n.getNodeName().equals("profileEntry")) {
+ profileEntryList.add(n);
+ }
+
+ }
+
+ // create the profile object if we have entries
+ if (profileEntryList.size() > 0) {
+
+ // create the profile object
+ profile = new Profile();
+ profile.setId(profileId);
+ profile.setType(profileUri);
+
+ for (Node n : profileEntryList) {
+ profile.getProfileEntries().add(getProfileEntry(n));
+ }
+ }
+
+
+ } catch (XPathExpressionException e) {
+ throw new ProfileRepositoryException(e.getMessage());
+ }
+
+ return profile;
+ }
+
private ProfileEntry getProfileEntry(final Node node) {

ProfileEntry entry = new ProfileEntry();

Modified:
branches/stars/Caboto/caboto/src/main/java/org/caboto/validation/AnnotationValidatorImpl.java
==============================================================================
---
branches/stars/Caboto/caboto/src/main/java/org/caboto/validation/AnnotationValidatorImpl.java
(original)
+++
branches/stars/Caboto/caboto/src/main/java/org/caboto/validation/AnnotationValidatorImpl.java
Fri Jul 10 06:24:46 2009
@@ -160,11 +160,23 @@
// (3) check that we have required values where
specified in the profile entries
for (ProfileEntry entry : profiles) {

- String bodyValue =
annotation.getBody().get(entry.getId());
+ List<String> bodyValues =
annotation.getBody().get(entry.getId());

if (entry.isRequired()) {

- if (bodyValue == null || bodyValue.length() ==
0) {
+ if (bodyValues == null || bodyValues.size() ==
0) {
+
errors.rejectValue("body", "annotation.body.missingRequiredVal",
+ new String[]{entry.getId()}, "");
+ }
+ // also check that there is at least one value
+ boolean passed = false;
+ for(String val: bodyValues) {
+ if(val != null && val.length() > 0) {
+ passed = true;
+ continue;
+ }
+ }
+ if(!passed) {

errors.rejectValue("body", "annotation.body.missingRequiredVal",
new String[]{entry.getId()}, "");
}

Modified:
branches/stars/Caboto/caboto/src/test/java/org/caboto/dao/AnnotationDaoImplTest.java
==============================================================================
---
branches/stars/Caboto/caboto/src/test/java/org/caboto/dao/AnnotationDaoImplTest.java
(original)
+++
branches/stars/Caboto/caboto/src/test/java/org/caboto/dao/AnnotationDaoImplTest.java
Fri Jul 10 06:24:46 2009
@@ -34,9 +34,13 @@
package org.caboto.dao;

import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.sdb.SDBFactory;
import com.hp.hpl.jena.sdb.Store;
+import com.hp.hpl.jena.sdb.StoreDesc;
+import com.hp.hpl.jena.sdb.sql.JDBC;
+
import junit.framework.TestCase;
import org.caboto.domain.Annotation;
import org.caboto.jena.db.Database;
@@ -46,7 +50,11 @@
import org.junit.Test;

import java.io.InputStream;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import org.caboto.filters.AnnotationFilter;
import org.caboto.filters.PropValAnnotationFilter;
@@ -61,15 +69,24 @@
@Override
public void setUp() throws Exception {

- store =
SDBFactory.connectStore(this.getClass().getResource("/sdb.ttl").getPath());
- store.getTableFormatter().format();

Database database = new SDBDatabase("/sdb.ttl");

annotationDao = new AnnotationDaoImpl(new
MockProfileRepositoryImpl(),
database);
- }

+ Model ttl = ModelFactory.createDefaultModel();
+ ttl.read(getClass().getResourceAsStream("/sdb.ttl"), null, "TTL");
+ StoreDesc storeDesc = StoreDesc.read(ttl);
+ String driver = JDBC.getDriver(storeDesc.getDbType());
+ JDBC.loadDriver(driver);
+ Connection sqlConn = DriverManager.getConnection(
+ storeDesc.connDesc.getJdbcURL(),
+ storeDesc.connDesc.getUser(),
+ storeDesc.connDesc.getPassword());
+ store = SDBFactory.connectStore(sqlConn, storeDesc);
+ store.getTableFormatter().format();
+ }

@Test
public void testAddAnnotation() {
@@ -80,9 +97,11 @@
annotation.setAuthor("http://caboto.org/person/mikej/");
annotation.setType("SimpleComment");

- Map<String, String> map = new HashMap<String, String>();
- map.put("title", "A title to the annotation");
- map.put("description", "Some description of the annotation");
+ Map<String, List<String>> map = new HashMap<String,
List<String>>();
+ map.put("title", new ArrayList<String>());
+ map.get("title").add("A title to the annotation");
+ map.put("description", new ArrayList<String>());
+ map.get("description").add("Some description of the annotation");

annotation.setBody(map);


Modified:
branches/stars/Caboto/caboto/src/test/java/org/caboto/profile/MockProfileRepositoryImpl.java
==============================================================================
---
branches/stars/Caboto/caboto/src/test/java/org/caboto/profile/MockProfileRepositoryImpl.java
(original)
+++
branches/stars/Caboto/caboto/src/test/java/org/caboto/profile/MockProfileRepositoryImpl.java
Fri Jul 10 06:24:46 2009
@@ -68,4 +68,34 @@
return null;
}

+ public Profile findProfileByUri(String profileUri)
+ throws ProfileRepositoryException {
+
+ if
(profileUri.equals("http://caboto.org/schema/annotations#SimpleComment")) {
+
+ Profile profile = new Profile();
+ profile.setId("SimpleComment");
+
profile.setType("http://caboto.org/schema/annotations#SimpleComment");
+
+ ProfileEntry entry1 = new ProfileEntry();
+ entry1.setId("title");
+
entry1.setPropertyType("http://purl.org/dc/elements/1.1/title");
+ entry1.setObjectDatatype("String");
+ entry1.setRequired(true);
+
+ ProfileEntry entry2 = new ProfileEntry();
+ entry2.setId("description");
+
entry2.setPropertyType("http://purl.org/dc/elements/1.1/description");
+ entry2.setObjectDatatype("String");
+ entry2.setRequired(true);
+
+ profile.getProfileEntries().add(entry1);
+ profile.getProfileEntries().add(entry2);
+
+ return profile;
+ }
+
+ return null;
+ }
+
}

Modified:
branches/stars/Caboto/caboto/src/test/java/org/caboto/rest/resources/AboutResourceTest.java
==============================================================================
---
branches/stars/Caboto/caboto/src/test/java/org/caboto/rest/resources/AboutResourceTest.java
(original)
+++
branches/stars/Caboto/caboto/src/test/java/org/caboto/rest/resources/AboutResourceTest.java
Fri Jul 10 06:24:46 2009
@@ -34,18 +34,21 @@

package org.caboto.rest.resources;

-import com.hp.hpl.jena.rdf.model.Model;
-import com.sun.jersey.api.client.ClientResponse;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Map;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
+
import org.caboto.RdfMediaType;
import org.caboto.domain.Annotation;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import static org.junit.Assert.*;
+
+import com.hp.hpl.jena.rdf.model.Model;
+import com.sun.jersey.api.client.ClientResponse;

/**
*
@@ -70,8 +73,9 @@
@Override
public Annotation createTestAnnotation(String graphUri) {
Annotation annotation = super.createTestAnnotation(graphUri);
- Map<String, String> body = annotation.getBody();
- body.put("title", "title" + count);
+ Map<String, List<String>> body = annotation.getBody();
+ body.put("title", new ArrayList());
+ body.get("title").add("title" + count);
count++;
return annotation;
}

Modified:
branches/stars/Caboto/caboto/src/test/java/org/caboto/rest/resources/AbstractResourceTest.java
==============================================================================
---
branches/stars/Caboto/caboto/src/test/java/org/caboto/rest/resources/AbstractResourceTest.java
(original)
+++
branches/stars/Caboto/caboto/src/test/java/org/caboto/rest/resources/AbstractResourceTest.java
Fri Jul 10 06:24:46 2009
@@ -33,19 +33,17 @@
*/
package org.caboto.rest.resources;

-import com.hp.hpl.jena.rdf.model.Model;
-import com.hp.hpl.jena.rdf.model.ModelFactory;
-import com.hp.hpl.jena.sdb.SDBFactory;
-import com.hp.hpl.jena.sdb.Store;
-import com.hp.hpl.jena.sdb.StoreDesc;
-import com.hp.hpl.jena.sdb.sql.JDBC;
-import com.sun.jersey.api.client.Client;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.config.ClientConfig;
-import com.sun.jersey.api.client.config.DefaultClientConfig;
-import com.sun.jersey.api.core.PackagesResourceConfig;
-import com.sun.jersey.spi.spring.container.servlet.SpringServlet;
+import java.net.Authenticator;
+import java.net.PasswordAuthentication;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
import junit.framework.TestCase;
+
import org.caboto.dao.AnnotationDao;
import org.caboto.dao.AnnotationDaoImpl;
import org.caboto.domain.Annotation;
@@ -62,12 +60,18 @@
import org.mortbay.jetty.servlet.ServletHolder;
import org.springframework.web.context.ContextLoaderServlet;

-import java.net.Authenticator;
-import java.net.PasswordAuthentication;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.util.HashMap;
-import java.util.Map;
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
+import com.hp.hpl.jena.sdb.SDBFactory;
+import com.hp.hpl.jena.sdb.Store;
+import com.hp.hpl.jena.sdb.StoreDesc;
+import com.hp.hpl.jena.sdb.sql.JDBC;
+import com.sun.jersey.api.client.Client;
+import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.api.client.config.ClientConfig;
+import com.sun.jersey.api.client.config.DefaultClientConfig;
+import com.sun.jersey.api.core.PackagesResourceConfig;
+import com.sun.jersey.spi.spring.container.servlet.SpringServlet;

/**
* @author Mike Jones (mike.a...@bristol.ac.uk)
@@ -238,9 +242,11 @@
Annotation createTestAnnotation(String graphUri) {

// body of the annotation
- Map<String, String> body = new HashMap<String, String>();
- body.put("title", "A title");
- body.put("description", "A description");
+ Map<String, List<String>> body = new HashMap<String,
List<String>>();
+ body.put("title", new ArrayList<String>());
+ body.get("title").add("A title");
+ body.put("description", new ArrayList<String>());
+ body.get("description").add("A description");

// main bits of the annotation
Annotation annotation = new Annotation();

Modified:
branches/stars/Caboto/caboto/src/test/java/org/caboto/rest/resources/BasicAuthenticationClientFilter.java
==============================================================================
---
branches/stars/Caboto/caboto/src/test/java/org/caboto/rest/resources/BasicAuthenticationClientFilter.java
(original)
+++
branches/stars/Caboto/caboto/src/test/java/org/caboto/rest/resources/BasicAuthenticationClientFilter.java
Fri Jul 10 06:24:46 2009
@@ -37,17 +37,19 @@
import com.sun.jersey.api.client.ClientRequest;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.filter.ClientFilter;
+
import org.apache.commons.codec.binary.Base64;

import java.util.ArrayList;
import java.util.List;

/**
+ *
* @author Mike Jones (mike.a...@bristol.ac.uk)
* @version $Id$
- */
-public class
- BasicAuthenticationClientFilter extends ClientFilter {
+ *
+ **/
+public class BasicAuthenticationClientFilter extends ClientFilter {

public BasicAuthenticationClientFilter(final String username, final
String password) {
this.username = username;

Modified:
branches/stars/Caboto/caboto/src/test/java/org/caboto/validation/AnnotationValidationTest.java
==============================================================================
---
branches/stars/Caboto/caboto/src/test/java/org/caboto/validation/AnnotationValidationTest.java
(original)
+++
branches/stars/Caboto/caboto/src/test/java/org/caboto/validation/AnnotationValidationTest.java
Fri Jul 10 06:24:46 2009
@@ -33,19 +33,21 @@
*/
package org.caboto.validation;

+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
import junit.framework.TestCase;
+
import org.caboto.domain.Annotation;
import org.caboto.profile.MockProfileRepositoryImpl;
+import org.junit.Before;
+import org.junit.Test;
import org.springframework.validation.BeanPropertyBindingResult;
import org.springframework.validation.Errors;
import org.springframework.validation.FieldError;
import org.springframework.validation.ObjectError;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;

/**
* @author Mike Jones (mike.a...@bristol.ac.uk)
@@ -67,9 +69,11 @@
annotation.setGraphId("http://caboto.org/person/MikeJ/public/");

// the body of the annotation
- Map<String, String> body = new HashMap<String, String>();
- body.put("title", "This is a test annotation");
- body.put("description", "Lorem ipsum dolor sit amet, consectetur
adipisicing elit, " +
+ Map<String, List<String>> body = new HashMap<String,
List<String>>();
+ body.put("title", new ArrayList<String>());
+ body.get("title").add("This is a test annotation");
+ body.put("description", new ArrayList<String>());
+ body.get("description").add("Lorem ipsum dolor sit amet,
consectetur adipisicing elit, " +
"sed do eiusmod tempor incididunt ut labore et dolore
magna aliqua.");
annotation.setBody(body);

@@ -170,7 +174,8 @@
@Test
public void testIncorrectBody() {

- annotation.getBody().put("extraField", "Some value or other");
+ annotation.getBody().put("extraField", new ArrayList<String>());
+ annotation.getBody().get("extraField").add("Some value or other");

validator.validate(annotation, errors);

@@ -196,7 +201,8 @@
@Test
public void testMissingBodyValue() {

- annotation.getBody().put("title", "");
+ annotation.getBody().put("title", new ArrayList<String>());
+ annotation.getBody().get("title").add("");

validator.validate(annotation, errors);

Reply all
Reply to author
Forward
0 new messages