Modified:
branches/multi_valued/caboto/src/main/java/org/caboto/dao/AnnotationDaoImpl.java
branches/multi_valued/caboto/src/main/java/org/caboto/domain/Annotation.java
branches/multi_valued/caboto/src/main/java/org/caboto/domain/AnnotationFactory.java
branches/multi_valued/caboto/src/main/java/org/caboto/validation/AnnotationValidatorImpl.java
branches/multi_valued/caboto/src/test/java/org/caboto/dao/AnnotationDaoImplTest.java
branches/multi_valued/caboto/src/test/java/org/caboto/rest/resources/AboutResourceTest.java
branches/multi_valued/caboto/src/test/java/org/caboto/rest/resources/AbstractResourceTest.java
branches/multi_valued/caboto/src/test/java/org/caboto/validation/AnnotationValidationTest.java
Log:
ASSIGNED - # 236: Repeating properties per annotation
https://webfutures.ilrt.bris.ac.uk/stars/ticket/236
Modified:
branches/multi_valued/caboto/src/main/java/org/caboto/dao/AnnotationDaoImpl.java
==============================================================================
---
branches/multi_valued/caboto/src/main/java/org/caboto/dao/AnnotationDaoImpl.java
(original)
+++
branches/multi_valued/caboto/src/main/java/org/caboto/dao/AnnotationDaoImpl.java
Thu Jul 9 06:37:42 2009
@@ -125,23 +125,25 @@
for (ProfileEntry entry : profile.getProfileEntries()) {
- String val = annotation.getBody().get(entry.getId());
- if ((val == null) && !entry.isRequired()){
+ List<String> values =
annotation.getBody().get(entry.getId());
+ if ((values == null) && !entry.isRequired()){
continue;
}
- Property prop =
model.createProperty(entry.getPropertyType());
+ for(String val: values) {
+ Property prop =
model.createProperty(entry.getPropertyType());
- String dataType = entry.getObjectDatatype();
+ String dataType = entry.getObjectDatatype();
- if (dataType != null) {
+ if (dataType != null) {
- if (dataType.equals("String")) {
- bodyResource.addProperty(prop, val,
XSDDatatype.XSDstring);
- }
+ if (dataType.equals("String")) {
+ bodyResource.addProperty(prop, val,
XSDDatatype.XSDstring);
+ }
- } else {
- bodyResource.addProperty(prop, val);
+ } else {
+ bodyResource.addProperty(prop, val);
+ }
}
}
Modified:
branches/multi_valued/caboto/src/main/java/org/caboto/domain/Annotation.java
==============================================================================
---
branches/multi_valued/caboto/src/main/java/org/caboto/domain/Annotation.java
(original)
+++
branches/multi_valued/caboto/src/main/java/org/caboto/domain/Annotation.java
Thu Jul 9 06:37:42 2009
@@ -34,10 +34,12 @@
package org.caboto.domain;
import java.text.ParseException;
+import java.util.ArrayList;
import java.util.Date;
+import java.util.HashMap;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
-import java.util.HashMap;
import org.caboto.CabotoUtility;
import org.caboto.profile.Profile;
@@ -47,9 +49,9 @@
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
-import com.hp.hpl.jena.rdf.model.Property;
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;
/**
@@ -63,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;
@@ -106,14 +108,20 @@
Iterator<ProfileEntry> profileIter =
profile.getProfileEntries().iterator();
while (profileIter.hasNext()){
profileEntry=profileIter.next();
-
bodyValue=bodyResource.getProperty(model.createProperty(profileEntry.getPropertyType()));
- if (bodyValue!=null) {
- body.put(profileEntry.getId(),bodyValue.getString());
- } else {
+ 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());
+ }
+ }
}
}
@@ -158,11 +166,11 @@
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;
}
@@ -191,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/multi_valued/caboto/src/main/java/org/caboto/domain/AnnotationFactory.java
==============================================================================
---
branches/multi_valued/caboto/src/main/java/org/caboto/domain/AnnotationFactory.java
(original)
+++
branches/multi_valued/caboto/src/main/java/org/caboto/domain/AnnotationFactory.java
Thu Jul 9 06:37:42 2009
@@ -135,7 +135,7 @@
// 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/multi_valued/caboto/src/main/java/org/caboto/validation/AnnotationValidatorImpl.java
==============================================================================
---
branches/multi_valued/caboto/src/main/java/org/caboto/validation/AnnotationValidatorImpl.java
(original)
+++
branches/multi_valued/caboto/src/main/java/org/caboto/validation/AnnotationValidatorImpl.java
Thu Jul 9 06:37:42 2009
@@ -159,11 +159,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/multi_valued/caboto/src/test/java/org/caboto/dao/AnnotationDaoImplTest.java
==============================================================================
---
branches/multi_valued/caboto/src/test/java/org/caboto/dao/AnnotationDaoImplTest.java
(original)
+++
branches/multi_valued/caboto/src/test/java/org/caboto/dao/AnnotationDaoImplTest.java
Thu Jul 9 06:37:42 2009
@@ -52,7 +52,9 @@
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;
@@ -95,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/multi_valued/caboto/src/test/java/org/caboto/rest/resources/AboutResourceTest.java
==============================================================================
---
branches/multi_valued/caboto/src/test/java/org/caboto/rest/resources/AboutResourceTest.java
(original)
+++
branches/multi_valued/caboto/src/test/java/org/caboto/rest/resources/AboutResourceTest.java
Thu Jul 9 06:37:42 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/multi_valued/caboto/src/test/java/org/caboto/rest/resources/AbstractResourceTest.java
==============================================================================
---
branches/multi_valued/caboto/src/test/java/org/caboto/rest/resources/AbstractResourceTest.java
(original)
+++
branches/multi_valued/caboto/src/test/java/org/caboto/rest/resources/AbstractResourceTest.java
Thu Jul 9 06:37:42 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/multi_valued/caboto/src/test/java/org/caboto/validation/AnnotationValidationTest.java
==============================================================================
---
branches/multi_valued/caboto/src/test/java/org/caboto/validation/AnnotationValidationTest.java
(original)
+++
branches/multi_valued/caboto/src/test/java/org/caboto/validation/AnnotationValidationTest.java
Thu Jul 9 06:37:42 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);
@@ -194,7 +199,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);