Revision: 1897
Author: [email protected]
Date: Mon Jun 7 06:48:38 2010
Log: Return response of addProject REST call to let caller now where to
find the created project.
http://code.google.com/p/simal/source/detail?r=1897
Modified:
/trunk/uk.ac.osswatch.simal.rest/src/main/java/uk/ac/osswatch/simal/rest/ProjectAPI.java
/trunk/uk.ac.osswatch.simal.rest/src/test/java/uk/ac/osswatch/simal/rest/TestProjectAPI.java
=======================================
---
/trunk/uk.ac.osswatch.simal.rest/src/main/java/uk/ac/osswatch/simal/rest/ProjectAPI.java
Tue Dec 15 16:42:26 2009
+++
/trunk/uk.ac.osswatch.simal.rest/src/main/java/uk/ac/osswatch/simal/rest/ProjectAPI.java
Mon Jun 7 06:48:38 2010
@@ -19,7 +19,10 @@
import uk.ac.osswatch.simal.SimalRepositoryFactory;
import uk.ac.osswatch.simal.model.IProject;
+import uk.ac.osswatch.simal.model.jena.Project;
+import uk.ac.osswatch.simal.rdf.SimalException;
import uk.ac.osswatch.simal.rdf.SimalRepositoryException;
+import uk.ac.osswatch.simal.rdf.io.RDFXMLUtils;
/**
* A class for handling all API calls relating to projects.
@@ -46,16 +49,22 @@
* @throws SimalAPIException
*/
public String execute() throws SimalAPIException {
+ String execResult = null;
+
if (command.isGetAllProjects()) {
- return getAllProjects(command);
+ execResult = getAllProjects(command);
} else if (command.isGetProject()) {
- return getProject(command);
+ execResult = getProject(command);
} else if (command.isAddProject()) {
- addProject(command);
- return null;
+ IProject newProject = addProject(command);
+ if (newProject instanceof Project) {
+ execResult = ((Project) newProject).generateURL();
+ }
} else {
throw new SimalAPIException("Unknown command: " + command);
}
+
+ return execResult;
}
/**
@@ -128,11 +137,20 @@
* @throws SimalAPIException
* if the project was not added for any reason
*/
- private void addProject(RESTCommand command) throws SimalAPIException {
+ private IProject addProject(RESTCommand command) throws
SimalAPIException {
+ IProject newProject = null;
+ String rdfXml = command.getParameter(RESTCommand.PARAM_RDF);
+
+ if(rdfXml == null) {
+ throw new SimalAPIException("Did not find RDF/XML data to add
project from.");
+ }
+
try {
- getRepository().add(command.getParameter(RESTCommand.PARAM_RDF));
- } catch (SimalRepositoryException e) {
+ newProject =
SimalRepositoryFactory.getProjectService().createProject(RDFXMLUtils.convertXmlStringToDom(rdfXml));
+ } catch (SimalException e) {
throw new SimalAPIException("Unable to add RDF data", e);
}
+
+ return newProject;
}
}
=======================================
---
/trunk/uk.ac.osswatch.simal.rest/src/test/java/uk/ac/osswatch/simal/rest/TestProjectAPI.java
Tue Dec 15 17:05:02 2009
+++
/trunk/uk.ac.osswatch.simal.rest/src/test/java/uk/ac/osswatch/simal/rest/TestProjectAPI.java
Mon Jun 7 06:48:38 2010
@@ -1,7 +1,7 @@
package uk.ac.osswatch.simal.rest;
/*
- * Copyright 2008 University of Oxford
+ * Copyright 2008,2010 University of Oxford
*
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
@@ -33,7 +33,7 @@
public class TestProjectAPI extends AbstractAPITest {
@Test
- public void addDOAP() throws SimalAPIException, URISyntaxException,
+ public void addIllegalDOAP() throws SimalAPIException,
URISyntaxException,
IOException {
RESTCommand command =
RESTCommand.createCommand(RESTCommand.PROJECT_ADD);
command.addParameter("rdf", "illegal RDF data");
@@ -42,7 +42,17 @@
handler.execute();
} catch (SimalAPIException e) {
// that's good, we don't expect to add invalid data
- }
+ return;
+ }
+ fail("Adding illegal RDF data didn't fail.");
+ }
+
+ @Test
+ public void addDOAP() throws SimalAPIException, URISyntaxException,
+ IOException {
+ RESTCommand command =
RESTCommand.createCommand(RESTCommand.PROJECT_ADD);
+ IAPIHandler handler = SimalHandlerFactory.createHandler(command,
getRepo());
+ String result = null;
InputStream fis =
this.getClass().getResourceAsStream("/doapTestFile.xml");
int x = fis.available();
@@ -53,13 +63,14 @@
command.addParameter(RESTCommand.PARAM_RDF, data);
handler = SimalHandlerFactory.createHandler(command, getRepo());
try {
- handler.execute();
+ result = handler.execute();
} catch (SimalAPIException e) {
fail("Exception thrown when adding project" + e.getMessage());
}
- // we don't bother testing to see if the project has been added here
- // that's the job of the repository tests.
+ if(result == null) {
+ fail("Adding a project did not return a result.");
+ }
}
@Test
--
You received this message because you are subscribed to the Google Groups "Simal
Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/simal-commits?hl=en.