|
From: <rit...@us...> - 2010-08-27 03:33:17
|
Revision: 79
http://andspidclient.svn.sourceforge.net/andspidclient/?rev=79&view=rev
Author: ritacsiro
Date: 2010-08-27 03:33:09 +0000 (Fri, 27 Aug 2010)
Log Message:
-----------
ANDSWRON-926:PID value not saved correctly if it's a URL string especially if it contains '?' and '&' .
Modified Paths:
--------------
trunk/src/main/java/au/csiro/pidclient/AndsPidClient.java
trunk/src/test/java/au/csiro/pidclient/TestAndsPidClient.java
Modified: trunk/src/main/java/au/csiro/pidclient/AndsPidClient.java
===================================================================
--- trunk/src/main/java/au/csiro/pidclient/AndsPidClient.java 2010-07-16 02:30:48 UTC (rev 78)
+++ trunk/src/main/java/au/csiro/pidclient/AndsPidClient.java 2010-08-27 03:33:09 UTC (rev 79)
@@ -39,6 +39,7 @@
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.HttpsURL;
+import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.httpclient.methods.StringRequestEntity;
@@ -317,8 +318,12 @@
this.validateMintHandleArguments(type, value);
- String queryString = MessageFormat.format("type={0}&value={1}", new Object[] { type.value(), value });
- return executeMethod(queryString, mintMethodName);
+ NameValuePair[] queryParams = {
+ new NameValuePair("type", type.value()),
+ new NameValuePair("value", value)
+ };
+
+ return executeMethod(queryParams, mintMethodName);
}
/**
@@ -389,9 +394,12 @@
this.validateMintHandleArguments(type, value);
- String queryString = MessageFormat.format("type={0}&index={1}&value={2}", new Object[] { type.value(), index,
- value });
- return executeMethod(queryString, mintMethodName);
+ NameValuePair[] queryParams = {
+ new NameValuePair("type", type.value()),
+ new NameValuePair("index", String.valueOf(index)),
+ new NameValuePair("value", value)
+ };
+ return executeMethod(queryParams, mintMethodName);
}
/**
@@ -469,9 +477,12 @@
new Object[] { (type == null) ? null : type.value(), value }));
}
- String queryString = MessageFormat.format("handle={0}&type={1}&value={2}", new Object[] { handle, type.value(),
- value });
- return executeMethod(queryString, addValueMethodName);
+ NameValuePair[] queryParams = {
+ new NameValuePair("type", type.value()),
+ new NameValuePair("handle", handle),
+ new NameValuePair("value", value)
+ };
+ return executeMethod(queryParams, addValueMethodName);
}
/**
@@ -551,9 +562,13 @@
new Object[] { (type == null) ? null : type.value(), value }));
}
- String queryString = MessageFormat.format("handle={0}&index={1}&type={2}&value={3}", new Object[] { handle,
- Integer.toString(index), type.value(), value });
- return executeMethod(queryString, addValueByIndexMethodName);
+ NameValuePair[] queryParams = {
+ new NameValuePair("handle", handle),
+ new NameValuePair("index", String.valueOf(index)),
+ new NameValuePair("type", type.value()),
+ new NameValuePair("value", value)
+ };
+ return executeMethod(queryParams, addValueByIndexMethodName);
}
/**
@@ -635,9 +650,12 @@
new Object[] { handle, newValue }));
}
- String queryString = MessageFormat.format("handle={0}&index={1}&value={2}", new Object[] { handle,
- Integer.toString(index), newValue });
- return executeMethod(queryString, modifyValueByIndexMethodName);
+ NameValuePair[] queryParams = {
+ new NameValuePair("index", String.valueOf(index)),
+ new NameValuePair("handle", handle),
+ new NameValuePair("value", newValue)
+ };
+ return executeMethod(queryParams, modifyValueByIndexMethodName);
}
/**
@@ -708,10 +726,11 @@
"The method deleteValueByIndex() can not be called with null or empty arguments:\n handle={0}\n",
new Object[] { handle }));
}
-
- String queryString = MessageFormat.format("handle={0}&index={1}", new Object[] { handle,
- Integer.toString(index) });
- return executeMethod(queryString, deleteValueByIndexMethodName);
+
+ NameValuePair[] queryParams = {
+ new NameValuePair("index", String.valueOf(index)),
+ new NameValuePair("handle", handle)};
+ return executeMethod(queryParams, deleteValueByIndexMethodName);
}
/**
@@ -768,8 +787,8 @@
public String listHandles() throws IllegalStateException, HttpException, IOException
{
this.validateState();
-
- return executeMethod("", listHandlesMethodName);
+ NameValuePair[] queryParams = {new NameValuePair()};
+ return executeMethod(queryParams, listHandlesMethodName);
}
/**
@@ -828,8 +847,8 @@
new Object[] { handle }));
}
- String queryString = MessageFormat.format("handle={0}", new Object[] { handle });
- return executeMethod(queryString, getHandleMethodName);
+ NameValuePair[] queryParams = {new NameValuePair("handle", handle)};
+ return executeMethod(queryParams, getHandleMethodName);
}
/**
@@ -865,8 +884,8 @@
/**
* Constructs and executes an HTTP POST call.
*
- * @param queryString
- * the query string to provide the POST call.
+ * @param queryParams
+ * the array of query parameters to provide the POST call.
* @param methodName
* the method to call.
* @return a formatted XML response.
@@ -875,10 +894,10 @@
* @throws HttpException
* thrown when attempting to execute method call.
*/
- private String executeMethod(String queryString, String methodName) throws HttpException, IOException
+ private String executeMethod(NameValuePair[] queryParams, String methodName) throws HttpException, IOException
{
HttpsURL url = new HttpsURL(/* String user */"", /* String password */"", this.getPidServiceHost(), this
- .getPidServicePort(), this.getPidServicePath(), queryString);
+ .getPidServicePort(), this.getPidServicePath());
// if no path has been specified (i.e. path value is just '/') then we have:
// http://test.org.au:80/mint?type=URL&value=<some value>
@@ -894,7 +913,7 @@
String identityXML = this.getRequestorIdentity().toXML(methodName);
- return executePostMethod(url.toString(), identityXML);
+ return executePostMethod(url.toString(), queryParams, identityXML);
}
@@ -905,6 +924,8 @@
*
* @param postMethodURL
* the URI of the RESTful ANDS Persistent Identifier web service.
+ * @param params
+ * the array of query parameters to provide the POST call.
* @param identityXML
* an XML fragment that details the identity of the caller.
* @return a formatted XML response.
@@ -913,7 +934,7 @@
* @throws HttpException
* thrown when attempting to execute method call.
*/
- private String executePostMethod(String postMethodURL, String identityXML) throws HttpException, IOException
+ private String executePostMethod(String postMethodURL, NameValuePair[] params, String identityXML) throws HttpException, IOException
{
LOG.debug("Post method URL: " + postMethodURL);
LOG.debug("Identity XML: " + identityXML);
@@ -933,7 +954,7 @@
RequestEntity entity = new StringRequestEntity(identityXML, "text/xml", "UTF-8");
client.getParams().setParameter("Content-Length", entity.getContentLength());
method.setRequestEntity(entity);
-
+ method.setQueryString(params);
int returnCode = client.executeMethod(method);
if (returnCode == HttpStatus.SC_NOT_IMPLEMENTED)
{
@@ -1030,7 +1051,7 @@
NodeList nodes = (NodeList) result;
for (int i = 0; i < nodes.getLength(); i++)
{
- return nodes.item(i).getTextContent();
+ return nodes.item(i).getTextContent();
}
return null;
}
@@ -1187,19 +1208,19 @@
{
errorMsg
.append("The appID of the caller has not been provided. " +
- "e.g. unique Id provided by ANDS upon IP registration.\n");
+ "e.g. unique Id provided by ANDS upon IP registration.\n");
}
if (getRequestorIdentity() == null || StringUtils.isEmpty(this.getRequestorIdentity().getIdentifier()))
{
errorMsg
.append("The identifier of the caller has not been provided. " +
- "e.g. identifier or name of the repository calling the service.\n");
+ "e.g. identifier or name of the repository calling the service.\n");
}
if (getRequestorIdentity() == null || StringUtils.isEmpty(this.getRequestorIdentity().getAuthDomain()))
{
errorMsg
.append("The authDomain of the caller has not been provided. " +
- "e.g. the domain of the organisation calling the service.");
+ "e.g. the domain of the organisation calling the service.");
}
// if we have error messages, throw the exception
if (errorMsg.length() != 0)
@@ -1207,6 +1228,7 @@
throw new IllegalStateException(errorMsg.toString());
}
}
+
/**
* Checks the arguments passed to the {@link #mintHandle(HandleType, String)} and the
Modified: trunk/src/test/java/au/csiro/pidclient/TestAndsPidClient.java
===================================================================
--- trunk/src/test/java/au/csiro/pidclient/TestAndsPidClient.java 2010-07-16 02:30:48 UTC (rev 78)
+++ trunk/src/test/java/au/csiro/pidclient/TestAndsPidClient.java 2010-08-27 03:33:09 UTC (rev 79)
@@ -415,8 +415,10 @@
int index = createDummyIndexValue(client); // get an index with a value associated with it
+ String goodValue = "http://javatest2.vm.csiro.au:8080/muradora/objectView.action?parentId=procite%3ApublicData&type=1&pid=csiro%3ADocument004";
+
AndsPidResponse response = client.modifyValueByIndexFormattedResponse(TESTING_HANDLE, index,
- "http://test.org.au/modifyValueByIndex");
+ goodValue);
// should succeed
assertTrue("Operation success expected, but response indicated failure", response.isSuccess());
@@ -432,7 +434,7 @@
{
found = true;
assertEquals("The value associated with index: " + index + " was not updated by modifyValueByIndex",
- property.getValue(), "http://test.org.au/modifyValueByIndex");
+ property.getValue(), goodValue);
}
}
if (!found)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <joh...@us...> - 2012-03-07 05:05:45
|
Revision: 98
http://andspidclient.svn.sourceforge.net/andspidclient/?rev=98&view=rev
Author: johnpage-09
Date: 2012-03-07 05:05:38 +0000 (Wed, 07 Mar 2012)
Log Message:
-----------
DMSTECH-2890: Functionality for updating a DOI.
https://jira.csiro.au/browse/DMSTECH-2890
Modified Paths:
--------------
trunk/src/main/java/au/csiro/doiclient/AndsDoiClient.java
trunk/src/test/java/au/csiro/doiclient/TestAndsDoiClient.java
Modified: trunk/src/main/java/au/csiro/doiclient/AndsDoiClient.java
===================================================================
--- trunk/src/main/java/au/csiro/doiclient/AndsDoiClient.java 2012-03-07 03:21:57 UTC (rev 97)
+++ trunk/src/main/java/au/csiro/doiclient/AndsDoiClient.java 2012-03-07 05:05:38 UTC (rev 98)
@@ -289,7 +289,8 @@
String queryString = MessageFormat.format("app_id={0}&url={1}", new Object[] {
getRequestorIdentity().getAppId(), url });
- return executeMethod(queryString, mintMethodName, true);
+
+ return executeMethod(queryString, mintMethodName, true, null);
}
@@ -323,11 +324,11 @@
// DOI should not be null
this.validateParameters(updateMethodName, doi, url);
- String queryString = MessageFormat.format("app_id={0}&url={1}&DOI={2}", new Object[] {
- getRequestorIdentity().getAppId(), url, doi });
+ String queryString = MessageFormat.format("app_id={0}&DOI={1}", new Object[] {
+ getRequestorIdentity().getAppId(), doi });
- return executeMethod(queryString, updateMethodName, updateMetdaData);
+ return executeMethod(queryString, updateMethodName, updateMetdaData, url);
}
/**
@@ -405,14 +406,16 @@
* the method to call.
* @param updateMetdaData
* flag indicating if the meta data needs to be generated.
+ * @param updateURL
+ * associated with a DOI that needs to be updated.
* @return a formatted XML response.
* @throws IOException
* thrown when attempting to read response.
* @throws HttpException
* thrown when attempting to execute method call.
*/
- private AndsDoiResponse executeMethod(String queryString, String methodName, boolean updateMetdaData)
- throws HttpException, IOException
+ private AndsDoiResponse executeMethod(String queryString, String methodName, boolean updateMetdaData,
+ String updateURL) throws HttpException, IOException
{
String metaDataXML = null;
@@ -422,40 +425,40 @@
HttpsURL url = new HttpsURL(this.getDoiServiceHost(), this.getDoiServicePath(), queryString, "");
- url.setPath(url.getPath() + "/" + getPhPMethod(methodName));
+ url.setPath(url.getPath() + "/" + getMethodName(methodName));
// Meta Data will need to be generated only if it is a call to MINT DOIs.
- // It becomes optional for Update calls.
+ // It becomes optional for update calls.
if (updateMetdaData)
{
metaDataXML = this.getRequestorIdentity().toXML(methodName);
}
- LOG.debug("Metadata XML generated " + metaDataXML);
+ LOG.debug("Metadata XML generated :->" + metaDataXML);
- return postDOIRequest(url.toString(), metaDataXML);
+ return postDOIRequest(url.toString(), metaDataXML, updateURL);
}
/**
*
- * Returns the php method name that needs to be invoked on the DOI service to complete the call.
+ * Returns the method name that needs to be invoked on the DOI service to complete the call.
*
- * @param methodName
+ * @param operation
* to be called
- * @return php method name
+ * @return method name
*/
- private String getPhPMethod(String methodName)
+ private String getMethodName(String operation)
{
- if (methodName.equals("mint"))
+ if (operation.equals("mint"))
{
return "doi_mint.php";
}
- else if (methodName.equals("update"))
+ else if (operation.equals("update"))
{
return "doi_update.php";
}
- return "";
+ return null;
}
@@ -469,14 +472,14 @@
* the URI of the RESTful ANDS Digital Object Identifier web service.
* @param metadata
* an XML fragment that details the meta data of the document for which the DOI is queried.
+ * @param updateURL
* @return
* @throws IOException
*/
- private static AndsDoiResponse postDOIRequest(String serviceUrl, String metadata) throws IOException
+ private static AndsDoiResponse postDOIRequest(String serviceUrl, String metadata, String updateURL)
+ throws IOException
{
LOG.debug("Post method URL: " + serviceUrl);
-
- LOG.debug("Metadata XML: " + metadata);
AndsDoiResponse doiResponse = null;
String data = null;
@@ -487,22 +490,29 @@
{
if (metadata != null)
{
- // Construct data
- data = "xml=" + URLEncoder.encode(metadata, "UTF-8");
+
}
// Send data
-
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setDoInput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
- if (data != null)
+ // Construct data
+
+ if (metadata != null)
{
+ data = "xml=" + URLEncoder.encode(metadata, "UTF-8");
wr.write(data);
}
+ if (updateURL != null)
+ {
+ data = "url=" + updateURL;
+ wr.write(data);
+ }
+
wr.flush();
doiResponse = new AndsDoiResponse();
Modified: trunk/src/test/java/au/csiro/doiclient/TestAndsDoiClient.java
===================================================================
--- trunk/src/test/java/au/csiro/doiclient/TestAndsDoiClient.java 2012-03-07 03:21:57 UTC (rev 97)
+++ trunk/src/test/java/au/csiro/doiclient/TestAndsDoiClient.java 2012-03-07 05:05:38 UTC (rev 98)
@@ -87,8 +87,10 @@
assertNotNull(mintDOIResponse.getDoi());
+ // ANDs DOI Test pre-fix will start with 10.5072
+ assertTrue(mintDOIResponse.getDoi().startsWith("10.5072"));
+ System.out.println("testMintDOI: DOI response is :->" + mintDOIResponse.getResponseBody());
-
}
@@ -97,7 +99,7 @@
*
* @throws Exception
*/
- public final void XXtestUpdateDOIURL() throws Exception
+ public final void XXtestUpdateDOIUrl() throws Exception
{
doiDTO = new DoiDTO();
populateDummydoiDTO(doiDTO);
@@ -110,7 +112,7 @@
AndsDoiResponse updateDOIResponse = client.updateDOI(mintDOIResponse.getDoi(),
"http://www.csiro.au/en/Portals/Events.aspx", false);
- System.out.println("Updated DOI response is :->" + updateDOIResponse.getResponseBody());
+ System.out.println("testUpdateDOIUrl: DOI response is :->" + updateDOIResponse.getResponseBody());
assertEquals(200, updateDOIResponse.getResponseCode());
@@ -119,8 +121,67 @@
}
+ /**
+ * Test updating the URL associated with a DOI
+ *
+ * @throws Exception
+ */
+ public final void XXtestUpdateDOIMetaData() throws Exception
+ {
+ doiDTO = new DoiDTO();
+ populateDummydoiDTO(doiDTO);
+ AndsDoiClient mintClient = new AndsDoiClient(ANDS_HOST, ANDS_PATH, APPID, IDENTIFIER, AUTHDOMAIN, doiDTO);
+
+ AndsDoiResponse mintDOIResponse = mintClient.mintDOI("http://csiro.au");
+
+ System.out.println("Minted DOI is :->" + mintDOIResponse.getDoi());
+
+ doiDTO.setCreator("Ponting,Ricky");
+
+ AndsDoiClient updateClient = new AndsDoiClient(ANDS_HOST, ANDS_PATH, APPID, IDENTIFIER, AUTHDOMAIN, doiDTO);
+ AndsDoiResponse updateDOIResponse = updateClient.updateDOI(mintDOIResponse.getDoi(), null, true);
+
+ System.out.println("testUpdateDOIMetaData: Updated DOI response is :->" + updateDOIResponse.getResponseBody());
+
+ assertEquals(200, updateDOIResponse.getResponseCode());
+
+ assertEquals(mintDOIResponse.getDoi(), updateDOIResponse.getDoi());
+ assertNotNull(updateDOIResponse.getDoi());
+
+ }
+
/**
+ * Test updating the URL associated with a DOI
+ *
+ * @throws Exception
+ */
+ public final void XXtestUpdateDOIUrlAndMetaData() throws Exception
+ {
+ doiDTO = new DoiDTO();
+ populateDummydoiDTO(doiDTO);
+ AndsDoiClient mintClient = new AndsDoiClient(ANDS_HOST, ANDS_PATH, APPID, IDENTIFIER, AUTHDOMAIN, doiDTO);
+
+ AndsDoiResponse mintDOIResponse = mintClient.mintDOI("http://csiro.au");
+
+ System.out.println("Minted DOI is :->" + mintDOIResponse.getDoi());
+
+ // Make a change in the DTO that will get translated into the meta-data
+ doiDTO.setCreator("Clarke,Michael");
+ AndsDoiClient updateClient = new AndsDoiClient(ANDS_HOST, ANDS_PATH, APPID, IDENTIFIER, AUTHDOMAIN, doiDTO);
+ AndsDoiResponse updateDOIResponse = updateClient.updateDOI(mintDOIResponse.getDoi(),
+ "http://www.csiro.au/en/Portals/Education.aspx", true);
+
+ System.out.println("testUpdateDOIMetaData: Updated DOI response is :->" + updateDOIResponse.getResponseBody());
+
+ assertEquals(200, updateDOIResponse.getResponseCode());
+
+ assertEquals(mintDOIResponse.getDoi(), updateDOIResponse.getDoi());
+ assertNotNull(updateDOIResponse.getDoi());
+
+ }
+
+ /**
* Create a ANDs Digital Identifier Client using CSIRO requester info
*
* @return a valid ANDDigital IdentiferIdentifierClient
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <joh...@us...> - 2012-03-07 05:56:36
|
Revision: 99
http://andspidclient.svn.sourceforge.net/andspidclient/?rev=99&view=rev
Author: johnpage-09
Date: 2012-03-07 05:56:29 +0000 (Wed, 07 Mar 2012)
Log Message:
-----------
DMSTECH-2890: Functionality to request DOI meta-data from ANDs.
https://jira.csiro.au/browse/DMSTECH-2890
Modified Paths:
--------------
trunk/src/main/java/au/csiro/doiclient/AndsDoiClient.java
trunk/src/main/resources/ands-doi-client.properties
trunk/src/test/java/au/csiro/doiclient/TestAndsDoiClient.java
Modified: trunk/src/main/java/au/csiro/doiclient/AndsDoiClient.java
===================================================================
--- trunk/src/main/java/au/csiro/doiclient/AndsDoiClient.java 2012-03-07 05:05:38 UTC (rev 98)
+++ trunk/src/main/java/au/csiro/doiclient/AndsDoiClient.java 2012-03-07 05:56:29 UTC (rev 99)
@@ -95,10 +95,9 @@
private static String updateMethodName;
/**
- * The name of the method (RESTful web service) to call when associating a new value into the index of an existing
- * handle.
+ * The name of the method (RESTful web service) to call when requesting the metadata associated with a DOI.
*/
- private static String addValueByIndexMethodName;
+ private static String doiMetadataRequest;
/**
* The name of the method (RESTful web service) to call when modifying an existing handle.
@@ -195,7 +194,7 @@
applicationName = props.getProperty("application.name");
mintMethodName = props.getProperty("method.mint");
updateMethodName = props.getProperty("method.update");
- addValueByIndexMethodName = props.getProperty("method.addValueByIndex");
+ doiMetadataRequest = props.getProperty("method.doi");
modifyValueByIndexMethodName = props.getProperty("method.modifyValueByIndex");
deleteValueByIndexMethodName = props.getProperty("method.deleteValueByIndex");
listHandlesMethodName = props.getProperty("method.listHandles");
@@ -331,7 +330,36 @@
return executeMethod(queryString, updateMethodName, updateMetdaData, url);
}
+
/**
+ * Responsible for requesting the meta-data for a given DOI.
+ * <p>
+ *
+ * @param doi
+ * DOI for which the meta-data is requested.
+ * @throws IllegalStateException
+ * thrown if the parameters need to call the ANDS DOI service have not been provided.
+ * @throws IllegalArgumentException
+ * thrown when method is called with invalid arguments.
+ * @throws IOException
+ * thrown when attempting to read response.
+ * @throws HttpException
+ * thrown when attempting to execute method call.
+ */
+ public AndsDoiResponse requestMetaDatatDOI(String doi) throws HttpException, IOException
+ {
+ this.validateState();
+
+ // DOI should not be null
+ this.validateParameters(doiMetadataRequest, doi, null);
+
+ String queryString = MessageFormat.format("DOI={0}", new Object[] { doi });
+
+ return executeMethod(queryString, doiMetadataRequest, false, null);
+
+ }
+
+ /**
* Checks that this class is in a valid state to call the ANDS DOI service.
*
* @throws IllegalStateException
@@ -388,7 +416,7 @@
new Object[] { values[1] }));
}
- if (values[0].equals("update") && StringUtils.isEmpty(values[1]))
+ if (((values[0].equals("update")) || (values[0].equals("doi"))) && StringUtils.isEmpty(values[1]))
{
throw new IllegalArgumentException(MessageFormat.format(
"The method updateDOI() can only be called if the arguement is non-empty:values={1}\n",
@@ -419,14 +447,15 @@
{
String metaDataXML = null;
+ String requestType = getRequestType(methodName);
LOG.debug("ExecuteMethod : Query String : ->" + queryString);
LOG.debug("ExecuteMethod : Method Name : ->" + methodName);
HttpsURL url = new HttpsURL(this.getDoiServiceHost(), this.getDoiServicePath(), queryString, "");
-
url.setPath(url.getPath() + "/" + getMethodName(methodName));
+
// Meta Data will need to be generated only if it is a call to MINT DOIs.
// It becomes optional for update calls.
if (updateMetdaData)
@@ -435,8 +464,22 @@
}
LOG.debug("Metadata XML generated :->" + metaDataXML);
+ return doiRequest(url.toString(), metaDataXML, updateURL, requestType);
+ }
- return postDOIRequest(url.toString(), metaDataXML, updateURL);
+ /**
+ * Returns the Request Type : GET or POST
+ *
+ * @param methodName
+ * call that is to be made to the DOI service.
+ * @return requestType GET or POST.
+ */
+ private String getRequestType(String methodName)
+ {
+ if ((methodName.equals("mint")) || (methodName.equals("update")))
+ return "POST";
+ else
+ return "GET";
}
/**
@@ -457,6 +500,10 @@
{
return "doi_update.php";
}
+ else if (operation.equals("doi"))
+ {
+ return "doi_xml.php";
+ }
return null;
}
@@ -473,10 +520,13 @@
* @param metadata
* an XML fragment that details the meta data of the document for which the DOI is queried.
* @param updateURL
+ * URL for the DOI that needs to be updated.
+ * @param requestType
+ * POST or GET
* @return
* @throws IOException
*/
- private static AndsDoiResponse postDOIRequest(String serviceUrl, String metadata, String updateURL)
+ private static AndsDoiResponse doiRequest(String serviceUrl, String metadata, String updateURL, String requestType)
throws IOException
{
LOG.debug("Post method URL: " + serviceUrl);
@@ -494,7 +544,7 @@
}
// Send data
- conn.setRequestMethod("POST");
+ conn.setRequestMethod(requestType);
conn.setDoOutput(true);
conn.setDoInput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
@@ -694,4 +744,5 @@
}
+
}
Modified: trunk/src/main/resources/ands-doi-client.properties
===================================================================
--- trunk/src/main/resources/ands-doi-client.properties 2012-03-07 05:05:38 UTC (rev 98)
+++ trunk/src/main/resources/ands-doi-client.properties 2012-03-07 05:56:29 UTC (rev 99)
@@ -18,10 +18,10 @@
application.name=${pom.name}
application.version=${pom.version}
-# RESTful ANDS Digital Idenfier Service web service URIs
+# RESTful ANDS Digital Identifier Service web service URIs
method.mint=mint
method.update=update
-method.addValueByIndex=addValueByIndex
+method.doi=doi
method.modifyValueByIndex=modifyValueByIndex
method.deleteValueByIndex=deleteValueByIndex
method.listHandles=listHandles
Modified: trunk/src/test/java/au/csiro/doiclient/TestAndsDoiClient.java
===================================================================
--- trunk/src/test/java/au/csiro/doiclient/TestAndsDoiClient.java 2012-03-07 05:05:38 UTC (rev 98)
+++ trunk/src/test/java/au/csiro/doiclient/TestAndsDoiClient.java 2012-03-07 05:56:29 UTC (rev 99)
@@ -93,7 +93,33 @@
}
+ /**
+ * Test minting a DOI
+ *
+ * @throws Exception
+ */
+ public final void testDOIRequestMetaData() throws Exception
+ {
+ doiDTO = new DoiDTO();
+ populateDummydoiDTO(doiDTO);
+ AndsDoiClient client = new AndsDoiClient(ANDS_HOST, ANDS_PATH, APPID, IDENTIFIER, AUTHDOMAIN, doiDTO);
+ AndsDoiResponse mintDOIResponse = client.mintDOI("http://csiro.au");
+
+ assertEquals(200, mintDOIResponse.getResponseCode());
+
+ assertNotNull(mintDOIResponse.getDoi());
+
+ // ANDs DOI Test pre-fix will start with 10.5072
+ assertTrue(mintDOIResponse.getDoi().startsWith("10.5072"));
+
+ AndsDoiResponse metadaDataDOIResponse = client.requestMetaDatatDOI(mintDOIResponse.getDoi());
+
+ System.out.println("testDOIRequestMetaData: DOI response is :->" + metadaDataDOIResponse.getResponseBody());
+
+
+ }
+
/**
* Test updating the URL associated with a DOI
*
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <joh...@us...> - 2012-03-08 05:15:57
|
Revision: 101
http://andspidclient.svn.sourceforge.net/andspidclient/?rev=101&view=rev
Author: johnpage-09
Date: 2012-03-08 05:15:50 +0000 (Thu, 08 Mar 2012)
Log Message:
-----------
DMSTECH-2890: Functionality for updating the DOI element in the metadata xml.
Modified Paths:
--------------
trunk/src/main/java/au/csiro/doiclient/AndsDoiClient.java
trunk/src/main/java/au/csiro/doiclient/utils/DoiMetaDataGenerator.java
trunk/src/test/java/au/csiro/doiclient/utils/TestDoiMetaDataGenerator.java
Modified: trunk/src/main/java/au/csiro/doiclient/AndsDoiClient.java
===================================================================
--- trunk/src/main/java/au/csiro/doiclient/AndsDoiClient.java 2012-03-08 04:39:03 UTC (rev 100)
+++ trunk/src/main/java/au/csiro/doiclient/AndsDoiClient.java 2012-03-08 05:15:50 UTC (rev 101)
@@ -294,7 +294,7 @@
/**
- * Responsible for the Updating a DOI.
+ * Responsible for the updating a DOI.
* <p>
* DOI being updated must belong to the client requesting the update. The update service point allows clients to
* update their DOIs in 3 ways. Clients can update the URL only, metadata only, or both the URL and metadata
@@ -346,7 +346,7 @@
* @throws HttpException
* thrown when attempting to execute method call.
*/
- public AndsDoiResponse requestMetaDatatDOI(String doi) throws HttpException, IOException
+ public AndsDoiResponse requestMetaDataOfDOI(String doi) throws HttpException, IOException
{
this.validateState();
Modified: trunk/src/main/java/au/csiro/doiclient/utils/DoiMetaDataGenerator.java
===================================================================
--- trunk/src/main/java/au/csiro/doiclient/utils/DoiMetaDataGenerator.java 2012-03-08 04:39:03 UTC (rev 100)
+++ trunk/src/main/java/au/csiro/doiclient/utils/DoiMetaDataGenerator.java 2012-03-08 05:15:50 UTC (rev 101)
@@ -4,8 +4,6 @@
package au.csiro.doiclient.utils;
import java.io.IOException;
-import java.util.Iterator;
-import java.util.List;
import org.jdom.Document;
import org.jdom.JDOMException;
@@ -28,6 +26,12 @@
/**
* Constant giving the xpath of the creator name
*/
+ private static final String IDENTIFIER_NAME_XPATH = "/xsi:resource/xsi:identifier";
+
+
+ /**
+ * Constant giving the xpath of the creator name
+ */
private static final String CREATOR_NAME_XPATH = "/xsi:resource/xsi:creators/xsi:creator/xsi:creatorName";
/**
@@ -64,8 +68,6 @@
{
Document document = ConverterUtils.getXmlDocument("DoiMetadataTemplate.xml");
- // ConverterUtils.addElementValue(document, NAME_SPACE, CREATOR_NAME_XPATH, doiDto.getCreators().get(0));
-
ConverterUtils.updateElementValues(document, NAME_SPACE, CREATOR_NAME_XPATH, doiDto.getCreators());
ConverterUtils.updateElementValue(document, NAME_SPACE, DoiMetaDataGenerator.TITLE_NAME_XPATH,
@@ -78,30 +80,29 @@
return ConverterUtils.outputTheXml(document);
}
+
/**
+ * Sets the DOI value returned by the mint call and generates the meta-data xml.
*
- * @param doiDto
- * @param document
+ * @param doi
+ * The Digital Object Identifier that needs to be set into the xml.
+ * @param xmlDocument
+ * XML document that neews to be updated.
+ * @throws IOException
+ * if the XML Document access fails
* @throws JDOMException
+ * when invalid XML parsing/access occurs
*/
- private static void updateCreatorNames(DoiDTO doiDto, Document document) throws JDOMException
+ public static String updateDOI(String doi, String xmlDocument) throws JDOMException, IOException
{
+ Document document = ConverterUtils.xmlToDoc(xmlDocument);
+ ConverterUtils.updateElementValue(document, NAME_SPACE, IDENTIFIER_NAME_XPATH, doi);
- List<String> creators = doiDto.getCreators();
- int counter = 1;
- for (Iterator<String> iterator = creators.iterator(); iterator.hasNext();)
- {
- String creatorName = (String) iterator.next();
- String xPath = DoiMetaDataGenerator.CREATOR_NAME_XPATH + "[" + counter + "]";
- ConverterUtils.updateElementValue(document, NAME_SPACE, xPath, creatorName);
+ return ConverterUtils.outputTheXml(document);
- counter++;
+ }
- }
- }
-
-
}
Modified: trunk/src/test/java/au/csiro/doiclient/utils/TestDoiMetaDataGenerator.java
===================================================================
--- trunk/src/test/java/au/csiro/doiclient/utils/TestDoiMetaDataGenerator.java 2012-03-08 04:39:03 UTC (rev 100)
+++ trunk/src/test/java/au/csiro/doiclient/utils/TestDoiMetaDataGenerator.java 2012-03-08 05:15:50 UTC (rev 101)
@@ -33,6 +33,9 @@
*/
private static final String CREATOR_NAME_XPATH = "/xsi:resource/xsi:creators/xsi:creator/xsi:creatorName";
+ /** Constant giving the xpath of the identifier name **/
+ private static final String IDENTIFIER_NAME_XPATH = "/xsi:resource/xsi:identifier";
+
/* (non-Javadoc)
* @see junit.framework.TestCase#setUp()
*/
@@ -98,4 +101,30 @@
}
+ /**
+ * Tests the updation of the Identifier
+ *
+ * @throws Exception
+ */
+ public final void testUpdateDOI() throws Exception
+ {
+ String doi = "10.5072/08/4F5838BF44E5A";
+
+ String doiMetaDataXML = DoiMetaDataGenerator.createDoiMetaDataXML(doiDTO);
+ assertNotNull(doiMetaDataXML);
+
+ String updatedMetaData = DoiMetaDataGenerator.updateDOI(doi, doiMetaDataXML);
+ assertNotNull(updatedMetaData);
+ System.out.println("Meta-Data : \n" + updatedMetaData);
+
+ Document document = ConverterUtils.xmlToDoc(updatedMetaData);
+ XPath xPath = XPath.newInstance(IDENTIFIER_NAME_XPATH);
+ xPath.addNamespace("xsi", document.getRootElement().getNamespaceURI());
+ List nodes = xPath.selectNodes(document);
+
+ assertEquals(1, nodes.size());
+
+ assertEquals("identifier", ((Element) nodes.get(0)).getName());
+ assertEquals("10.5072/08/4F5838BF44E5A", ((Element) nodes.get(0)).getText());
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <joh...@us...> - 2012-03-16 01:51:37
|
Revision: 139
http://andspidclient.svn.sourceforge.net/andspidclient/?rev=139&view=rev
Author: johnpage-09
Date: 2012-03-16 01:51:30 +0000 (Fri, 16 Mar 2012)
Log Message:
-----------
DMSTECH-2890: Moved location of the DOI Meta Data template to the properties file.
Modified Paths:
--------------
trunk/src/main/java/au/csiro/doiclient/AndsDoiClient.java
trunk/src/main/java/au/csiro/doiclient/business/AndsDoiIdentity.java
trunk/src/main/java/au/csiro/doiclient/utils/DoiMetaDataGenerator.java
trunk/src/main/resources/ands-doi-client.properties
trunk/src/test/java/au/csiro/doiclient/utils/TestDoiMetaDataGenerator.java
Modified: trunk/src/main/java/au/csiro/doiclient/AndsDoiClient.java
===================================================================
--- trunk/src/main/java/au/csiro/doiclient/AndsDoiClient.java 2012-03-15 09:19:38 UTC (rev 138)
+++ trunk/src/main/java/au/csiro/doiclient/AndsDoiClient.java 2012-03-16 01:51:30 UTC (rev 139)
@@ -37,6 +37,7 @@
import org.apache.commons.httpclient.HttpsURL;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
+import org.jdom.JDOMException;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -44,6 +45,7 @@
import au.csiro.doiclient.business.AndsDoiIdentity;
import au.csiro.doiclient.business.DoiDTO;
+import au.csiro.doiclient.utils.DoiMetaDataGenerator;
import au.csiro.pidclient.AndsPidClient.HandleType;
@@ -120,6 +122,10 @@
*/
private static String deactivateDoi;
+ /**
+ * The path to the DOI meta-data template.
+ */
+ private static String metadataTemplatePath;
/**
* Represents the identity information of the caller.
@@ -139,6 +145,11 @@
/**
+ * The creator of the Digital Object
+ */
+ private DoiDTO doiDTO;
+
+ /**
* Loads the specified properties file.
*/
private static void loadProperties()
@@ -153,6 +164,7 @@
doiMetadataRequest = props.getProperty("method.doi");
activateDoi = props.getProperty("method.activate");
deactivateDoi = props.getProperty("method.deactivate");
+ metadataTemplatePath = props.getProperty("ands-doi.template");
}
catch (IOException e)
{
@@ -187,7 +199,8 @@
public AndsDoiClient(String doiServiceHost, String doiServicePath, String appId,
String identifier, String authDomain, DoiDTO doiDTO)
{
- this(doiServiceHost, doiServicePath, new AndsDoiIdentity(appId, identifier, authDomain, doiDTO));
+ this(doiServiceHost, doiServicePath, new AndsDoiIdentity(appId, identifier, authDomain));
+ this.doiDTO = doiDTO;
}
@@ -476,13 +489,13 @@
if (methodName.equals(mintMethodName))
{
- metaDataXML = this.getRequestorIdentity().generateMetaDataXMLFromDTO();
+ metaDataXML = generateMetaDataXMLFromDTO();
}
// Updates the meta-data xml with the parameters set in the DTO.
if (methodName.equals(updateMethodName) && (!StringUtils.isEmpty(existingMetaDataXML)))
{
- metaDataXML = this.getRequestorIdentity().updateMetaDataXMLFromDTO(existingMetaDataXML);
+ metaDataXML = updateMetaDataXMLFromDTO(existingMetaDataXML);
}
@@ -754,6 +767,78 @@
}
+ /**
+ * @return the doiDTO
+ */
+ public DoiDTO getDoiDTO()
+ {
+ return doiDTO;
+ }
+ /**
+ * @param doiDTO
+ * the doiDTO to set
+ */
+ public void setDoiDTO(DoiDTO doiDTO)
+ {
+ this.doiDTO = doiDTO;
+ }
+ /**
+ * Formats the DOI meta-data information into a XML format that the ANDS Digital Object Identifier service
+ * understands.
+ *
+ * @return String representation of the XML metadata.
+ *
+ */
+ @SuppressWarnings(value = "all")
+ public String generateMetaDataXMLFromDTO()
+ {
+ String doiMetaDataXML = null;
+
+ try
+ {
+ doiMetaDataXML = DoiMetaDataGenerator.createDoiMetaDataXML(metadataTemplatePath, getDoiDTO());
+ }
+ catch (IOException e)
+ {
+ LOG.error("Error in generating DOI Metadata for " + getDoiDTO().getTitle(), e);
+ }
+ catch (JDOMException ex)
+ {
+ LOG.error("Error in generating DOI Metadata for " + getDoiDTO().getTitle(), ex);
+ }
+
+ return doiMetaDataXML;
+
+ }
+
+ /**
+ * Updates the meta-data xml associated with the DOI.
+ *
+ * @param existingMetaDataXML
+ * existing metadata of the DOI.
+ * @return String representation of the updated XML metadata.
+ */
+ public String updateMetaDataXMLFromDTO(String existingMetaDataXML)
+ {
+ String doiMetaDataXML = null;
+
+ try
+ {
+ doiMetaDataXML = DoiMetaDataGenerator.updateDoiMetaDataXML(getDoiDTO(), existingMetaDataXML);
+ }
+ catch (IOException e)
+ {
+ LOG.error("Error in generating DOI Metadata for " + getDoiDTO().getTitle(), e);
+ }
+ catch (JDOMException ex)
+ {
+ LOG.error("Error in generating DOI Metadata for " + getDoiDTO().getTitle(), ex);
+ }
+
+ return doiMetaDataXML;
+ }
+
+
}
Modified: trunk/src/main/java/au/csiro/doiclient/business/AndsDoiIdentity.java
===================================================================
--- trunk/src/main/java/au/csiro/doiclient/business/AndsDoiIdentity.java 2012-03-15 09:19:38 UTC (rev 138)
+++ trunk/src/main/java/au/csiro/doiclient/business/AndsDoiIdentity.java 2012-03-16 01:51:30 UTC (rev 139)
@@ -15,15 +15,9 @@
*/
package au.csiro.doiclient.business;
-import java.io.IOException;
-import org.apache.log4j.Logger;
-import org.jdom.JDOMException;
-import au.csiro.doiclient.utils.DoiMetaDataGenerator;
-
-
/**
* Represents the identify information required when calling the ANDS Digital Object Identifier service.
*
@@ -50,16 +44,8 @@
*/
private String authDomain;
- /**
- * The creator of the Digital Object
- */
- private DoiDTO doiDTO;
- /**
- * Constant that defines the logger to be used.
- */
- private static final Logger LOG = Logger.getLogger(AndsDoiIdentity.class.getName());
/**
* Default constructor
@@ -80,13 +66,11 @@
* the domain of the organisation calling the service.
*/
@SuppressWarnings(value = "all")
- public AndsDoiIdentity(String appId, String identifier, String authDomain, DoiDTO doiDTO)
+ public AndsDoiIdentity(String appId, String identifier, String authDomain)
{
this.setAppId(appId);
this.setIdentifier(identifier);
this.setAuthDomain(authDomain);
- this.setDoiDTO(doiDTO);
-
}
/**
@@ -140,80 +124,9 @@
this.authDomain = authDomain;
}
- /**
- * @return the doiDTO
- */
- public DoiDTO getDoiDTO()
- {
- return doiDTO;
- }
- /**
- * @param doiDTO
- * the doiDTO to set
- */
- public void setDoiDTO(DoiDTO doiDTO)
- {
- this.doiDTO = doiDTO;
- }
- /**
- * Formats the DOI meta-data information into a XML format that the ANDS Digital Object Identifier service
- * understands.
- *
- * @return String representation of the XML metadata.
- *
- */
- @SuppressWarnings(value = "all")
- public String generateMetaDataXMLFromDTO()
- {
- String doiMetaDataXML = null;
-
- try
- {
- doiMetaDataXML = DoiMetaDataGenerator.createDoiMetaDataXML(getDoiDTO());
- }
- catch (IOException e)
- {
- LOG.error("Error in generating DOI Metadata for " + getDoiDTO().getTitle(), e);
- }
- catch (JDOMException ex)
- {
- LOG.error("Error in generating DOI Metadata for " + getDoiDTO().getTitle(), ex);
- }
-
- return doiMetaDataXML;
-
- }
-
- /**
- * Updates the meta-data xml associated with the DOI.
- *
- * @param existingMetaDataXML
- * existing metadata of the DOI.
- * @return String representation of the updated XML metadata.
- */
- public String updateMetaDataXMLFromDTO(String existingMetaDataXML)
- {
- String doiMetaDataXML = null;
-
- try
- {
- doiMetaDataXML = DoiMetaDataGenerator.updateDoiMetaDataXML(getDoiDTO(), existingMetaDataXML);
- }
- catch (IOException e)
- {
- LOG.error("Error in generating DOI Metadata for " + getDoiDTO().getTitle(), e);
- }
- catch (JDOMException ex)
- {
- LOG.error("Error in generating DOI Metadata for " + getDoiDTO().getTitle(), ex);
- }
-
- return doiMetaDataXML;
- }
-
/*
* (non-Javadoc)
*
Modified: trunk/src/main/java/au/csiro/doiclient/utils/DoiMetaDataGenerator.java
===================================================================
--- trunk/src/main/java/au/csiro/doiclient/utils/DoiMetaDataGenerator.java 2012-03-15 09:19:38 UTC (rev 138)
+++ trunk/src/main/java/au/csiro/doiclient/utils/DoiMetaDataGenerator.java 2012-03-16 01:51:30 UTC (rev 139)
@@ -51,28 +51,30 @@
private static final String CREATOR_NAME_XPATH = "/xsi:resource/xsi:creators/xsi:creator/xsi:creatorName";
/**
- * Constant giving the xpath of the object title name
+ * Constant giving the xPath of the object title name
*/
private static final String TITLE_NAME_XPATH = "/xsi:resource/xsi:titles/xsi:title";
/**
- * Constant giving the xpath of the publisher name
+ * Constant giving the xPath of the publisher name
*/
private static final String PUBLISHER_NAME_XPATH = "/xsi:resource/xsi:publisher";
/**
- * Constant giving the xpath of the publication year
+ * Constant giving the xPath of the publication year
*/
private static final String PUBLICATIONYEAR_NAME_XPATH = "/xsi:resource/xsi:publicationYear";
/**
- * Constant giving the xpath of the Creator Name
+ * Constant giving the xPath of the Creator Name
*/
private static final String NAME_SPACE = "xsi";
/**
* Create a String representation of a DOIMetaData XML document from an DoiDTO bean using a template.
*
- * @param doiDto
+ * @param metaDataTempalatePath
+ * path to the meta-data template.
+ * @param doiDTO
* the bean representation of an OPAL record to be converted to a VOResource XML document
* @return a String representation of the DOIMetaData XML
* @throws IOException
@@ -80,18 +82,19 @@
* @throws JDOMException
* when invalid XML parsing/access occurs
*/
- public static String createDoiMetaDataXML(DoiDTO doiDto) throws IOException, JDOMException
+ public static String createDoiMetaDataXML(String metaDataTempalatePath, DoiDTO doiDTO) throws IOException,
+ JDOMException
{
- Document document = ConverterUtils.getXmlDocument("DoiMetadataTemplate.xml");
+ Document document = ConverterUtils.getXmlDocument(metaDataTempalatePath);
- ConverterUtils.updateElementValues(document, NAME_SPACE, CREATOR_NAME_XPATH, doiDto.getCreators());
+ ConverterUtils.updateElementValues(document, NAME_SPACE, CREATOR_NAME_XPATH, doiDTO.getCreators());
ConverterUtils.updateElementValue(document, NAME_SPACE, DoiMetaDataGenerator.TITLE_NAME_XPATH,
- doiDto.getTitle());
+ doiDTO.getTitle());
ConverterUtils.updateElementValue(document, NAME_SPACE, DoiMetaDataGenerator.PUBLISHER_NAME_XPATH,
- doiDto.getPublisher());
+ doiDTO.getPublisher());
ConverterUtils.updateElementValue(document, NAME_SPACE, DoiMetaDataGenerator.PUBLICATIONYEAR_NAME_XPATH,
- doiDto.getPublicationYear());
+ doiDTO.getPublicationYear());
return ConverterUtils.outputTheXml(document);
}
Modified: trunk/src/main/resources/ands-doi-client.properties
===================================================================
--- trunk/src/main/resources/ands-doi-client.properties 2012-03-15 09:19:38 UTC (rev 138)
+++ trunk/src/main/resources/ands-doi-client.properties 2012-03-16 01:51:30 UTC (rev 139)
@@ -14,13 +14,11 @@
# limitations under the License.
#
-# application.properties
-application.name=${pom.name}
-application.version=${pom.version}
-
# RESTful ANDS Digital Identifier Service web service URIs
method.mint=doi_mint.php
method.update=doi_update.php
method.doi=doi_xml.php
method.activate=doi_activate.php
method.deactivate=doi_deactivate.php
+
+ands-doi.template=DoiMetadataTemplate.xml
Modified: trunk/src/test/java/au/csiro/doiclient/utils/TestDoiMetaDataGenerator.java
===================================================================
--- trunk/src/test/java/au/csiro/doiclient/utils/TestDoiMetaDataGenerator.java 2012-03-15 09:19:38 UTC (rev 138)
+++ trunk/src/test/java/au/csiro/doiclient/utils/TestDoiMetaDataGenerator.java 2012-03-16 01:51:30 UTC (rev 139)
@@ -46,6 +46,9 @@
/** Constant giving the xpath of the identifier name **/
private static final String IDENTIFIER_NAME_XPATH = "/xsi:resource/xsi:identifier";
+ /** Constant giving the path to the meta-data template **/
+ String metadataTemplatePath = "DoiMetadataTemplate.xml";
+
/* (non-Javadoc)
* @see junit.framework.TestCase#setUp()
*/
@@ -97,7 +100,8 @@
*/
public final void testCreateDoiMetaDataXML() throws Exception
{
- String doiMetaDataXML = DoiMetaDataGenerator.createDoiMetaDataXML(populateDummydoiDTO());
+
+ String doiMetaDataXML = DoiMetaDataGenerator.createDoiMetaDataXML(metadataTemplatePath, populateDummydoiDTO());
assertNotNull(doiMetaDataXML);
Document document = ConverterUtils.xmlToDoc(doiMetaDataXML);
@@ -121,7 +125,7 @@
{
String doi = "10.5072/08/4F5838BF44E5A";
- String doiMetaDataXML = DoiMetaDataGenerator.createDoiMetaDataXML(populateDummydoiDTO());
+ String doiMetaDataXML = DoiMetaDataGenerator.createDoiMetaDataXML(metadataTemplatePath, populateDummydoiDTO());
assertNotNull(doiMetaDataXML);
String updatedMetaData = DoiMetaDataGenerator.updateDOI(doi, doiMetaDataXML);
@@ -148,7 +152,7 @@
{
DoiDTO dto = populateDummydoiDTO();
- String doiMetaDataXML = DoiMetaDataGenerator.createDoiMetaDataXML(dto);
+ String doiMetaDataXML = DoiMetaDataGenerator.createDoiMetaDataXML(metadataTemplatePath, dto);
String doi = "10.5072/08/4F5838BF44E5A";
List<String> creators = dto.getCreators();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jav...@us...> - 2012-08-02 02:17:14
|
Revision: 171
http://andspidclient.svn.sourceforge.net/andspidclient/?rev=171&view=rev
Author: javinovich
Date: 2012-08-02 02:17:06 +0000 (Thu, 02 Aug 2012)
Log Message:
-----------
DMSTECH-3773:
- Update DOI client to be compliant with XML interface for ANDS DOI Service 1.1
- XML request used in minting and updating DOI is now validated against DataCite Metadata Schema v 2.2 before being sent to ANDS DOI service.
- Response codes are now used to determine if an operation completed successfully.
Modified Paths:
--------------
trunk/src/main/java/au/csiro/doiclient/AndsDoiClient.java
trunk/src/main/java/au/csiro/doiclient/AndsDoiResponse.java
trunk/src/main/java/au/csiro/doiclient/utils/DoiMetaDataGenerator.java
trunk/src/main/resources/DoiMetadataTemplate.xml
trunk/src/test/java/au/csiro/doiclient/utils/TestDoiMetaDataGenerator.java
Added Paths:
-----------
trunk/src/main/resources/schema/
trunk/src/main/resources/schema/include/
trunk/src/main/resources/schema/include/datacite-contributorType-v2.xsd
trunk/src/main/resources/schema/include/datacite-dateType-v2.xsd
trunk/src/main/resources/schema/include/datacite-descriptionType-v2.xsd
trunk/src/main/resources/schema/include/datacite-relatedIdentifierType-v2.xsd
trunk/src/main/resources/schema/include/datacite-relationType-v2.xsd
trunk/src/main/resources/schema/include/datacite-resourceType-v2.xsd
trunk/src/main/resources/schema/include/datacite-titleType-v2.xsd
trunk/src/main/resources/schema/metadata.xsd
Modified: trunk/src/main/java/au/csiro/doiclient/AndsDoiClient.java
===================================================================
--- trunk/src/main/java/au/csiro/doiclient/AndsDoiClient.java 2012-07-30 07:46:49 UTC (rev 170)
+++ trunk/src/main/java/au/csiro/doiclient/AndsDoiClient.java 2012-08-02 02:17:06 UTC (rev 171)
@@ -15,6 +15,11 @@
*/
package au.csiro.doiclient;
+import au.csiro.doiclient.business.AndsDoiIdentity;
+import au.csiro.doiclient.business.DoiDTO;
+import au.csiro.doiclient.utils.DoiMetaDataGenerator;
+import au.csiro.doiclient.utils.HttpUtil;
+import au.csiro.pidclient.AndsPidClient.HandleType;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
@@ -22,14 +27,16 @@
import java.net.URLEncoder;
import java.text.MessageFormat;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
-
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.HttpURL;
import org.apache.commons.httpclient.HttpsURL;
import org.apache.commons.httpclient.NameValuePair;
@@ -38,12 +45,6 @@
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
-import au.csiro.doiclient.business.AndsDoiIdentity;
-import au.csiro.doiclient.business.DoiDTO;
-import au.csiro.doiclient.utils.DoiMetaDataGenerator;
-import au.csiro.doiclient.utils.HttpUtil;
-import au.csiro.pidclient.AndsPidClient.HandleType;
-
/**
* This is the main interface to the ANDS DOI Client library. It allows the caller to interact with the <a
* href="http://www.ands.org.au/services/doi-m2m-identifiers.html">Digital Object IDentifier Service</a> provided by the
@@ -66,8 +67,22 @@
* </UL>
* <p>
* This class has methods for (a)minting DOIs, (b)updating DOIs, (c) activating and deactivating DOIs.
+ * </p>
+ * <b>Debug:</b>
+ * <p>
+ * The methods requestMetaDataOfDOI, mintDOI, activateDOI, deactivateDOI and upDateDOI have an optional debug parameter.
+ * This is only meant to be used to diagnose problems while calling the ANDS web services.
+ * </p>
+ * <p>
+ * When activating the debug flag you must also activate this class logger (LOG) to print trace statements. The output
+ * from this logger will generally be requested when opening a ticket with the ANDS service desk.
+ * </p>
+ * <p>
+ * <b>Warning:</b> Enabling the debug flag will most likely break the method calls, as the response format
+ * won't be XML as it is expected under normal operation.
+ * Don't rely in the responses coming from the method calls when debug is enabled.
+ * </p>
*
- * </p>
* Copyright 2012, CSIRO Australia All rights reserved.
*
* @author Robert Bridle on 05/02/2010
@@ -77,7 +92,9 @@
public class AndsDoiClient
{
/**
- * Constant that defines the logger to be used.
+ * The logger used by this class.
+ *
+ * It's name is au.csiro.doiclient.AndsDoiClient
*/
public static final Logger LOG = Logger.getLogger(AndsDoiClient.class.getName());
@@ -150,6 +167,10 @@
/**
+ * The list of valid success response codes
+ */
+ private static final List<String> successCodes = Arrays.asList("MT001", "MT002", "MT003", "MT004");
+ /**
* Loads the specified properties file.
*/
static
@@ -375,7 +396,9 @@
* @param doi
* that needs to be updated.
* @param updatedUrl
- * the url pointing to the landing page of the data collection.
+ * The url pointing to the landing page of the data collection.
+ * It is very important that the base domain for updatedUrl is the list of registered
+ * domains in ANDS otherwise the method will fail
* @param doiDTO
* doiDTO with the values for the meta-data update.
* @param debug
@@ -415,7 +438,7 @@
AndsDoiResponse existingMetaDataXML = requestMetaDataOfDOI(doi);
return executeMethod(params, updateMethodName,
- existingMetaDataXML.getMetaData(), doiDTO);
+ existingMetaDataXML.getMessage(), doiDTO);
}
/**
@@ -687,8 +710,8 @@
if (LOG.isDebugEnabled())
{
- LOG.debug("ExecuteMethod : Query String : ->" + queryStringParams);
- LOG.debug("ExecuteMethod : Method Name : ->" + methodName);
+ LOG.debug("Query String: " + queryStringParams);
+ LOG.debug("Method Name: " + methodName);
}
HttpsURL url = new HttpsURL(this.getDoiServiceHost(), this.getDoiServicePort(), this.getDoiServicePath());
@@ -814,6 +837,11 @@
}
doiResponse = new AndsDoiResponse();
doiResponse.setMessage(outputBuffer.toString());
+ if(LOG.isTraceEnabled())
+ {
+ LOG.trace("Response Message:" + doiResponse.getMessage());
+ }
+
setResponseFlag(method.getStatusCode(), doiResponse);
}
finally
@@ -840,36 +868,26 @@
}
/**
- * Sets a boolean flag indicating success or failure based on the returned code.
+ * Sets the success flag in doiResponse indicating success or failure based on httpResponseCode
+ * and doiResponse.getResponseCode()
+ * If the response code is HttpStatus.SC_OK and doiResponse.getResponseCode() is one of "MT001", "MT002", "MT003",
+ * "MT004" then doiResponse.isSuccess will be true, otherwise it will be false
*
- * @param responseCode
- * code returned from the web service invocation.
- * @param responseMessage
- * message returned from the web service invocation.
+ * @param httpResponseCode
+ * http code returned from the web service invocation.
* @param doiResponse
- * response to be sent back to the client.
+ * contains the response code and success flag
*
*/
- private static void setResponseFlag(int responseCode, AndsDoiResponse doiResponse)
+ private static void setResponseFlag(int httpResponseCode, AndsDoiResponse doiResponse)
{
- switch (responseCode)
+ if(httpResponseCode == HttpStatus.SC_OK)
{
- case 200:
- if ((doiResponse.getMessage().contains("successfully"))
- || doiResponse.getMessage().contains("<?xml version="))
- {
- doiResponse.setSuccess(true);
- }
- else
- {
- doiResponse.setSuccess(false);
- }
- break;
- case 415:
- case 500:
- default:
+ doiResponse.setSuccess(
+ successCodes.contains(doiResponse.getResponseCode()));
+ } else
+ {
doiResponse.setSuccess(false);
- break;
}
}
@@ -972,5 +990,4 @@
{
this.metadataTemplatePath = metadataTemplatePath;
}
-
}
Modified: trunk/src/main/java/au/csiro/doiclient/AndsDoiResponse.java
===================================================================
--- trunk/src/main/java/au/csiro/doiclient/AndsDoiResponse.java 2012-07-30 07:46:49 UTC (rev 170)
+++ trunk/src/main/java/au/csiro/doiclient/AndsDoiResponse.java 2012-08-02 02:17:06 UTC (rev 171)
@@ -43,6 +43,11 @@
* Whether an ANDS DOI service call was successful.
*/
private boolean success;
+
+ /**
+ * Any of the response codes from Cite My Data M2M service
+ */
+ private String responseCode;
/**
@@ -93,9 +98,10 @@
/**
* ANDs has requested us to change the schema version to 2.1 for all meta-data sent to ANDs even though they send
* meta-data pertaining to version 2.2 in a GET Meta-data request.
- *
+ * @deprecated The version received should be used as it is to call back ANDS DOI services
* @return the metaData if it has been retrieved, null otherwise
*/
+ @Deprecated
public String getMetaData()
{
if (getMessage() != null)
@@ -106,7 +112,6 @@
{
return null;
}
-
}
/**
@@ -132,20 +137,71 @@
*/
private void extractDOI()
{
- doi = null;
if (isSuccess())
{
- int startIndex = getMessage().indexOf("DOI");
- int endIndex = getMessage().indexOf("was");
+ doi = extractElementFromXmlMessage("doi");
+ }
+ }
+
+ /**
+ * Extracts the response code into responseCode from the DOI service response body, if no response code could be extracted
+ * from the response body then null is set
+ */
+ private void extractResponseCode()
+ {
+ responseCode = extractElementFromXmlMessage("responsecode");
+ }
- if (startIndex > 0 && endIndex > 0)
+
+ /**
+ * Very basic parser to extract values for xml elements inside getMessage()
+ * @param elementName The XML Element name we want to extract
+ * @return the value for elementName or null if not found
+ */
+ private String extractElementFromXmlMessage(String elementName)
+ {
+ String xmlPrefix = "<" + elementName + ">";
+ String xmlPostfix = "</" + elementName + ">";
+
+ String value = null;
+ int startIndex = getMessage().indexOf(xmlPrefix);
+ int endIndex = getMessage().indexOf(xmlPostfix);
+
+ if (startIndex > 0 && endIndex > 0)
+ {
+ try
{
- doi = getMessage().substring(startIndex + 3, endIndex).trim();
+ value = getMessage().substring(startIndex + xmlPrefix.length() , endIndex).trim();
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ return null;
}
}
+ return value;
}
+
+ /**
+ * @return the responseCode
+ */
+ public String getResponseCode()
+ {
+ extractResponseCode();
+ return responseCode;
+ }
+
+
+ /**
+ * @param responseCode the responseCode to set
+ */
+ public void setResponseCode(String responseCode)
+ {
+ this.responseCode = responseCode;
+ }
+
+
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@@ -157,12 +213,13 @@
if (doi != null)
builder.append("doi=").append(doi).append(", ");
builder.append("success=").append(success).append(", ");
+ if (responseCode != null)
+ builder.append("responseCode=").append(responseCode).append(", ");
if (message != null)
- builder.append("\nmessage=").append(message);
- builder.append("\n]");
+ builder.append("\nmessage=\n").append(message);
+ builder.append("]");
return builder.toString();
}
-
}
Modified: trunk/src/main/java/au/csiro/doiclient/utils/DoiMetaDataGenerator.java
===================================================================
--- trunk/src/main/java/au/csiro/doiclient/utils/DoiMetaDataGenerator.java 2012-07-30 07:46:49 UTC (rev 170)
+++ trunk/src/main/java/au/csiro/doiclient/utils/DoiMetaDataGenerator.java 2012-08-02 02:17:06 UTC (rev 171)
@@ -1,5 +1,5 @@
/**
- * Copyright 2012, CSIRO Australia.
+ * Copyright 2010, CSIRO Australia.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,6 +18,10 @@
*/
package au.csiro.doiclient.utils;
+import java.io.StringReader;
+
+import org.jdom.input.SAXBuilder;
+
import java.io.IOException;
import java.io.InputStream;
@@ -73,6 +77,9 @@
/** Constant giving the path to the meta-data template **/
private static final String metadataTemplatePath = "/DoiMetadataTemplate.xml";
+
+ /** Constant giving the path to the local copy of DataCite Metadata Schema **/
+ private static final String SCHEMA_LOCALTION = "/schema/metadata.xsd";
/**
* Constant that defines the logger to be used.
@@ -89,14 +96,21 @@
* if the XML Document access fails
* @throws JDOMException
* when invalid XML parsing/access occurs
+ * @throws IllegalArgumentException If a parameter in doiDTO would violate the restrictions set on
+ * <a href="http://schema.datacite.org/meta/kernel-2.2/index.html">DataCite Metadata Schema v 2.2</a>
*/
public static String createDoiMetaDataXML(DoiDTO doiDTO) throws IOException,
JDOMException
{
InputStream is = DoiMetaDataGenerator.class.getResourceAsStream(metadataTemplatePath);
+
+
+
+ SAXBuilder builder = createValidationSAXBuilder(SCHEMA_LOCALTION);
- Document document = ConverterUtils.getXmlDocument(is, "DoiMetadataTemplate.xml");
+ // Implicit validation, it should not happen if the template is properly built
+ Document document = builder.build(is);
ConverterUtils.updateElementValues(document, NAME_SPACE, CREATOR_NAME_XPATH, doiDTO.getCreators());
@@ -107,10 +121,39 @@
ConverterUtils.updateElementValue(document, NAME_SPACE, DoiMetaDataGenerator.PUBLICATIONYEAR_NAME_XPATH,
doiDTO.getPublicationYear());
- return ConverterUtils.outputTheXml(document);
+ String result = ConverterUtils.outputTheXml(document);
+
+ try
+ {
+ document = builder.build(new StringReader(result));
+ }
+ catch (JDOMException e)
+ {
+ throw new IllegalArgumentException("It is most likely that one parameter in DoiDTO is invalid", e);
+ }
+
+ return result;
}
/**
+ * @param schemaLocation
+ * @return
+ */
+ private static SAXBuilder createValidationSAXBuilder(String schemaLocation)
+ {
+ java.net.URL url =
+ DoiMetaDataGenerator.class.getResource(schemaLocation);
+
+ SAXBuilder builder = new SAXBuilder(true);
+ builder.setFeature("http://apache.org/xml/features/validation/schema", true);
+
+ builder.setProperty(
+ "http://apache.org/xml/properties/schema/external-schemaLocation",
+ url.toString());
+ return builder;
+ }
+
+ /**
* Updates a String representation of a DOIMetaData XML document from an DoiDTO bean using an existing metadata
* document.
*
@@ -126,8 +169,12 @@
JDOMException
{
- Document document = ConverterUtils.xmlToDoc(metaDataDocument);
+ SAXBuilder builder = createValidationSAXBuilder(SCHEMA_LOCALTION);
+ // Implicit validation, it should not happen if the template is properly built
+ Document document = builder.build(new StringReader(metaDataDocument));
+
+
if ((doiDto.getCreators() != null) && (doiDto.getCreators().size() > 0))
{
ConverterUtils.updateElementValues(document, NAME_SPACE, CREATOR_NAME_XPATH, doiDto.getCreators());
@@ -155,8 +202,19 @@
{
ConverterUtils.updateElementValue(document, NAME_SPACE, IDENTIFIER_NAME_XPATH, doiDto.getIdentifier());
}
+
+ String result = ConverterUtils.outputTheXml(document);
- return ConverterUtils.outputTheXml(document);
+ try
+ {
+ document = builder.build(new StringReader(result));
+ }
+ catch (JDOMException e)
+ {
+ throw new IllegalArgumentException("It is most likely that one parameter in DoiDTO is invalid", e);
+ }
+
+ return result;
}
Modified: trunk/src/main/resources/DoiMetadataTemplate.xml
===================================================================
--- trunk/src/main/resources/DoiMetadataTemplate.xml 2012-07-30 07:46:49 UTC (rev 170)
+++ trunk/src/main/resources/DoiMetadataTemplate.xml 2012-08-02 02:17:06 UTC (rev 171)
@@ -15,10 +15,10 @@
limitations under the License.
-->
-<resource xmlns="http://datacite.org/schema/kernel-2.1"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://datacite.org/schema/kernel-2.1
-http://schema.datacite.org/meta/kernel-2.1/metadata.xsd">
+<resource xmlns="http://datacite.org/schema/kernel-2.2"
+xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+xsi:schemaLocation="http://datacite.org/schema/kernel-2.2
+http://schema.datacite.org/meta/kernel-2.2/metadata.xsd">
<identifier identifierType="DOI">10.2312/meyniana.2005.57.101</identifier>
<creators>
<creator>
Added: trunk/src/main/resources/schema/include/datacite-contributorType-v2.xsd
===================================================================
--- trunk/src/main/resources/schema/include/datacite-contributorType-v2.xsd (rev 0)
+++ trunk/src/main/resources/schema/include/datacite-contributorType-v2.xsd 2012-08-02 02:17:06 UTC (rev 171)
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Version 1.0 - Created 2011-01-13 - FZ, TIB, Germany -->
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://datacite.org/schema/kernel-2.2" targetNamespace="http://datacite.org/schema/kernel-2.2" elementFormDefault="qualified">
+ <xs:simpleType name="contributorType">
+ <xs:annotation>
+ <xs:documentation>The type of contributor of the resource.</xs:documentation>
+ </xs:annotation>
+ <xs:restriction base="xs:string">
+ <xs:enumeration value="ContactPerson"/>
+ <xs:enumeration value="DataCollector"/>
+ <xs:enumeration value="DataManager"/>
+ <xs:enumeration value="Distributor"/>
+ <xs:enumeration value="Editor"/>
+ <xs:enumeration value="Funder"/>
+ <xs:enumeration value="HostingInstitution"/>
+ <xs:enumeration value="Producer"/>
+ <xs:enumeration value="ProjectLeader"/>
+ <xs:enumeration value="ProjectMember"/>
+ <xs:enumeration value="RegistrationAgency"/>
+ <xs:enumeration value="RegistrationAuthority"/>
+ <xs:enumeration value="RelatedPerson"/>
+ <xs:enumeration value="RightsHolder"/>
+ <xs:enumeration value="Researcher"/>
+ <xs:enumeration value="Sponsor"/>
+ <xs:enumeration value="Supervisor"/>
+ <xs:enumeration value="WorkPackageLeader"/>
+ </xs:restriction>
+ </xs:simpleType>
+</xs:schema>
Added: trunk/src/main/resources/schema/include/datacite-dateType-v2.xsd
===================================================================
--- trunk/src/main/resources/schema/include/datacite-dateType-v2.xsd (rev 0)
+++ trunk/src/main/resources/schema/include/datacite-dateType-v2.xsd 2012-08-02 02:17:06 UTC (rev 171)
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Version 1.0 - Created 2011-01-13 - FZ, TIB, Germany -->
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://datacite.org/schema/kernel-2.2" targetNamespace="http://datacite.org/schema/kernel-2.2" elementFormDefault="qualified">
+ <xs:simpleType name="dateType">
+ <xs:annotation>
+ <xs:documentation>The type of date. To indicate a date period, provide two dates, specifying the StartDate and the EndDate. To indicate the end of an embargo period, use Available. To indicate the start of an embargo period, use Submitted or Accepted, as appropriate.</xs:documentation>
+ </xs:annotation>
+ <xs:restriction base="xs:string">
+ <xs:enumeration value="Accepted"/><!--The date that the publisher accepted the resource into their system.-->
+ <xs:enumeration value="Available"/><!--The date the resource is made publicly available. May be a range.-->
+ <xs:enumeration value="Copyrighted"/><!--The specific, documented date at which the resource receives a copyrighted status, if applicable.-->
+ <xs:enumeration value="Created"/><!--The date the resource itself was put together; this could be a date range or a single date for a final component, e.g., the finalised file with all of the data.-->
+ <xs:enumeration value="EndDate"/><!--Use if any other date type covers a range-->
+ <xs:enumeration value="Issued"/><!--The date that the resource is published or distributed e.g. to a data center.-->
+ <xs:enumeration value="StartDate"/><!--Use if any other date type covers a range.-->
+ <xs:enumeration value="Submitted"/><!--The date the creator submits the resource to the publisher. This could be different from Accepted if the publisher then applies a selection process.-->
+ <xs:enumeration value="Updated"/><!--The date of the last update to the resource, when the resource is being added to. May be a range.-->
+ <xs:enumeration value="Valid"/><!--The date or date range during which the dataset or resources are accurate. May be a range.-->
+ </xs:restriction>
+ </xs:simpleType>
+</xs:schema>
Added: trunk/src/main/resources/schema/include/datacite-descriptionType-v2.xsd
===================================================================
--- trunk/src/main/resources/schema/include/datacite-descriptionType-v2.xsd (rev 0)
+++ trunk/src/main/resources/schema/include/datacite-descriptionType-v2.xsd 2012-08-02 02:17:06 UTC (rev 171)
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Version 1.0 - Created 2011-01-13 - FZ, TIB, Germany -->
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://datacite.org/schema/kernel-2.2" targetNamespace="http://datacite.org/schema/kernel-2.2" elementFormDefault="qualified">
+ <xs:simpleType name="descriptionType">
+ <xs:annotation>
+ <xs:documentation>The type of the description.</xs:documentation>
+ </xs:annotation>
+ <xs:restriction base="xs:string">
+ <xs:enumeration value="Abstract"/>
+ <xs:enumeration value="SeriesInformation"/>
+ <xs:enumeration value="TableOfContents"/>
+ <xs:enumeration value="Other"/>
+ </xs:restriction>
+ </xs:simpleType>
+</xs:schema>
Added: trunk/src/main/resources/schema/include/datacite-relatedIdentifierType-v2.xsd
===================================================================
--- trunk/src/main/resources/schema/include/datacite-relatedIdentifierType-v2.xsd (rev 0)
+++ trunk/src/main/resources/schema/include/datacite-relatedIdentifierType-v2.xsd 2012-08-02 02:17:06 UTC (rev 171)
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Version 1.0 - Created 2011-01-13 - FZ, TIB, Germany -->
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://datacite.org/schema/kernel-2.2" targetNamespace="http://datacite.org/schema/kernel-2.2" elementFormDefault="qualified">
+ <xs:simpleType name="relatedIdentifierType">
+ <xs:annotation>
+ <xs:documentation>The type of the RelatedIdentifier.</xs:documentation>
+ </xs:annotation>
+ <xs:restriction base="xs:string">
+ <xs:enumeration value="ARK"/>
+ <xs:enumeration value="DOI"/>
+ <xs:enumeration value="EAN13"/>
+ <xs:enumeration value="EISSN"/>
+ <xs:enumeration value="Handle"/>
+ <xs:enumeration value="ISBN"/>
+ <xs:enumeration value="ISSN"/>
+ <xs:enumeration value="ISTC"/>
+ <xs:enumeration value="LISSN"/>
+ <xs:enumeration value="LSID"/>
+ <xs:enumeration value="PURL"/>
+ <xs:enumeration value="UPC"/>
+ <xs:enumeration value="URL"/>
+ <xs:enumeration value="URN"/>
+ </xs:restriction>
+ </xs:simpleType>
+</xs:schema>
Added: trunk/src/main/resources/schema/include/datacite-relationType-v2.xsd
===================================================================
--- trunk/src/main/resources/schema/include/datacite-relationType-v2.xsd (rev 0)
+++ trunk/src/main/resources/schema/include/datacite-relationType-v2.xsd 2012-08-02 02:17:06 UTC (rev 171)
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Version 1.0 - Created 2011-01-13 - FZ, TIB, Germany -->
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://datacite.org/schema/kernel-2.2" targetNamespace="http://datacite.org/schema/kernel-2.2" elementFormDefault="qualified">
+ <xs:simpleType name="relationType">
+ <xs:annotation>
+ <xs:documentation>Description of the relationship of the resource being registered (A) and the related resource (B).</xs:documentation>
+ </xs:annotation>
+ <xs:restriction base="xs:string">
+ <xs:enumeration value="IsCitedBy"/><!--indicates that B includes A in a citation-->
+ <xs:enumeration value="Cites"/><!--indicates that A includes B in a citation-->
+ <xs:enumeration value="IsSupplementTo"/><!--indicates that A is a supplement to B-->
+ <xs:enumeration value="IsSupplementedBy"/><!--indicates that B is a supplement to A-->
+ <xs:enumeration value="IsContinuedBy"/><!--indicates A is continued by the work B-->
+ <xs:enumeration value="Continues"/><!--indicates A is a continuation of the work B-->
+ <xs:enumeration value="IsNewVersionOf"/><!--indicates B is a new edition of A, where the new edition has been modified or updated-->
+ <xs:enumeration value="IsPreviousVersionOf"/><!--indicates B is a previous edition of A-->
+ <xs:enumeration value="IsPartOf"/><!--indicates A is a portion of B-->
+ <xs:enumeration value="HasPart"/><!--indicates A includes the part B-->
+ <xs:enumeration value="IsReferencedBy"/><!--indicates A is used as a source of information by B-->
+ <xs:enumeration value="References"/><!--indicates B is used as a source of information for A-->
+ <xs:enumeration value="IsDocumentedBy"/><!--indicates B is documentation about/explaining A-->
+ <xs:enumeration value="Documents"/><!--indicates A is documentation about/explaining B-->
+ <xs:enumeration value="IsCompiledBy"/><!--indicates B is used to compile or create A-->
+ <xs:enumeration value="Compiles"/><!--indicates B is the result of a compile or creation event using A-->
+ <xs:enumeration value="IsVariantFormOf"/><!--indicates B is a variant or different form of A, e.g. calculated or calibrated form or different packaging-->
+ <xs:enumeration value="IsOriginalFormOf"/><!--indicates B is the original form of A-->
+ </xs:restriction>
+ </xs:simpleType>
+</xs:schema>
Added: trunk/src/main/resources/schema/include/datacite-resourceType-v2.xsd
===================================================================
--- trunk/src/main/resources/schema/include/datacite-resourceType-v2.xsd (rev 0)
+++ trunk/src/main/resources/schema/include/datacite-resourceType-v2.xsd 2012-08-02 02:17:06 UTC (rev 171)
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Version 1.0 - Created 2011-01-13 - FZ, TIB, Germany -->
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://datacite.org/schema/kernel-2.2" targetNamespace="http://datacite.org/schema/kernel-2.2" elementFormDefault="qualified">
+ <xs:simpleType name="resourceType">
+ <xs:annotation>
+ <xs:documentation>The general type of a resource.</xs:documentation>
+ </xs:annotation>
+ <xs:restriction base="xs:string">
+ <xs:enumeration value="Collection"/>
+ <xs:enumeration value="Dataset"/>
+ <xs:enumeration value="Event"/>
+ <xs:enumeration value="Film"/>
+ <xs:enumeration value="Image"/>
+ <xs:enumeration value="InteractiveResource"/>
+ <xs:enumeration value="Model"/>
+ <xs:enumeration value="PhysicalObject"/>
+ <xs:enumeration value="Service"/>
+ <xs:enumeration value="Software"/>
+ <xs:enumeration value="Sound"/>
+ <xs:enumeration value="Text"/>
+ </xs:restriction>
+ </xs:simpleType>
+</xs:schema>
Added: trunk/src/main/resources/schema/include/datacite-titleType-v2.xsd
===================================================================
--- trunk/src/main/resources/schema/include/datacite-titleType-v2.xsd (rev 0)
+++ trunk/src/main/resources/schema/include/datacite-titleType-v2.xsd 2012-08-02 02:17:06 UTC (rev 171)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Version 1.0 - Created 2011-01-13 - FZ, TIB, Germany --><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://datacite.org/schema/kernel-2.2" targetNamespace="http://datacite.org/schema/kernel-2.2" elementFormDefault="qualified">
+ <xs:simpleType name="titleType">
+ <xs:restriction base="xs:string">
+ <xs:enumeration value="AlternativeTitle"/>
+ <xs:enumeration value="Subtitle"/>
+ <xs:enumeration value="TranslatedTitle"/>
+ </xs:restriction>
+ </xs:simpleType>
+</xs:schema>
Added: trunk/src/main/resources/schema/metadata.xsd
===================================================================
--- trunk/src/main/resources/schema/metadata.xsd (rev 0)
+++ trunk/src/main/resources/schema/metadata.xsd 2012-08-02 02:17:06 UTC (rev 171)
@@ -0,0 +1,316 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Revision ...
[truncated message content] |
|
From: <viv...@us...> - 2016-10-10 06:54:31
|
Revision: 191
http://sourceforge.net/p/andspidclient/code/191
Author: vivekpulukuri
Date: 2016-10-10 06:54:28 +0000 (Mon, 10 Oct 2016)
Log Message:
-----------
Add Support for minting DOI's for grey literature
EPR-547
Modified Paths:
--------------
trunk/src/main/java/au/csiro/doiclient/business/DoiDTO.java
trunk/src/main/java/au/csiro/doiclient/utils/ConverterUtils.java
trunk/src/main/java/au/csiro/doiclient/utils/DoiMetaDataGenerator.java
trunk/src/main/resources/DoiMetadataTemplate.xml
trunk/src/test/java/au/csiro/doiclient/utils/TestDoiMetaDataGenerator.java
Modified: trunk/src/main/java/au/csiro/doiclient/business/DoiDTO.java
===================================================================
--- trunk/src/main/java/au/csiro/doiclient/business/DoiDTO.java 2016-03-04 03:36:17 UTC (rev 190)
+++ trunk/src/main/java/au/csiro/doiclient/business/DoiDTO.java 2016-10-10 06:54:28 UTC (rev 191)
@@ -61,6 +61,17 @@
/** Primary language of the resource. Allowed values from: ISO 639-2/B, ISO 639-3 **/
private String language;
+
+ /**
+ * Type of resource such as datasets and collections
+ * associated workflows, software, models, grey literature
+ */
+ private String resourceType;
+
+ /**
+ * Resource type description
+ */
+ private String resourceTypeDescription;
/**
* @return the title
@@ -179,7 +190,27 @@
{
this.identifier = identifier;
}
+
+ public String getResourceType()
+ {
+ return resourceType;
+ }
+ public void setResourceType(String resourceType)
+ {
+ this.resourceType = resourceType;
+ }
+
+ public String getResourceTypeDescription()
+ {
+ return resourceTypeDescription;
+ }
+
+ public void setResourceTypeDescription(String resourceTypeDescription)
+ {
+ this.resourceTypeDescription = resourceTypeDescription;
+ }
+
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@@ -202,10 +233,12 @@
if (subject != null)
builder.append("subject=").append(subject).append(", ");
if (language != null)
- builder.append("language=").append(language);
+ builder.append("language=").append(language).append(", ");
+ if (resourceType != null)
+ builder.append("resourceType=").append(resourceType).append(", ");
+ if (resourceTypeDescription != null)
+ builder.append("resourceTypeDescription=").append(resourceTypeDescription);
builder.append("]");
return builder.toString();
- }
-
-
+ }
}
Modified: trunk/src/main/java/au/csiro/doiclient/utils/ConverterUtils.java
===================================================================
--- trunk/src/main/java/au/csiro/doiclient/utils/ConverterUtils.java 2016-03-04 03:36:17 UTC (rev 190)
+++ trunk/src/main/java/au/csiro/doiclient/utils/ConverterUtils.java 2016-10-10 06:54:28 UTC (rev 191)
@@ -23,6 +23,7 @@
import java.util.List;
import java.util.Map;
+import org.jdom.Attribute;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
@@ -106,6 +107,32 @@
Element theElement = (Element) xPath.selectSingleNode(document);
theElement.setText(stripNonValidXMLCharacters(value));
}
+
+ /**
+ * Update an existing XML element within an XML document using XPath.
+ *
+ * @param document
+ * the existing XML document to update
+ * @param nameSpace
+ * Namespace associated with the element
+ * @param element
+ * the element XPath that needs to be updated
+ * @param name
+ * the attribute name
+ * @param value
+ * the new value of the element
+ * @throws JDOMException
+ * when invalid XML parsing/access occurs
+ */
+ public static void updateAttribute (Document document, String nameSpace, String element,
+ String name, String value) throws JDOMException
+ {
+ XPath xPath = XPath.newInstance(element);
+ xPath.addNamespace(nameSpace, document.getRootElement().getNamespaceURI());
+ Element theElement = (Element) xPath.selectSingleNode(document);
+ Attribute attr = theElement.getAttribute(name);
+ attr.setValue(stripNonValidXMLCharacters(value));
+ }
/**
* Update an existing XML element within an XML document using XPath.
Modified: trunk/src/main/java/au/csiro/doiclient/utils/DoiMetaDataGenerator.java
===================================================================
--- trunk/src/main/java/au/csiro/doiclient/utils/DoiMetaDataGenerator.java 2016-03-04 03:36:17 UTC (rev 190)
+++ trunk/src/main/java/au/csiro/doiclient/utils/DoiMetaDataGenerator.java 2016-10-10 06:54:28 UTC (rev 191)
@@ -72,6 +72,16 @@
private static final String PUBLICATIONYEAR_NAME_XPATH = "/xsi:resource/xsi:publicationYear";
/**
+ * Constant giving the xPath of the Resource type
+ */
+ private static final String RESOURCETYPE_NAME_XPATH = "/xsi:resource/xsi:resourceType";
+
+ /**
+ * Constant giving the xPath of the Resource type
+ */
+ private static final String RESOURCETYPE_GENERAL = "resourceTypeGeneral";
+
+ /**
* Constant giving the xPath of the Creator Name
*/
private static final String NAME_SPACE = "xsi";
@@ -120,8 +130,12 @@
ConverterUtils.updateElementValue(document, NAME_SPACE, DoiMetaDataGenerator.PUBLISHER_NAME_XPATH,
doiDTO.getPublisher());
ConverterUtils.updateElementValue(document, NAME_SPACE, DoiMetaDataGenerator.PUBLICATIONYEAR_NAME_XPATH,
- doiDTO.getPublicationYear());
-
+ doiDTO.getPublicationYear());
+ ConverterUtils.updateElementValue(document, NAME_SPACE, DoiMetaDataGenerator.RESOURCETYPE_NAME_XPATH,
+ doiDTO.getResourceTypeDescription());
+ ConverterUtils.updateAttribute (document, NAME_SPACE, DoiMetaDataGenerator.RESOURCETYPE_NAME_XPATH,
+ RESOURCETYPE_GENERAL, doiDTO.getResourceType());
+
String result = ConverterUtils.outputTheXml(document);
try
Modified: trunk/src/main/resources/DoiMetadataTemplate.xml
===================================================================
--- trunk/src/main/resources/DoiMetadataTemplate.xml 2016-03-04 03:36:17 UTC (rev 190)
+++ trunk/src/main/resources/DoiMetadataTemplate.xml 2016-10-10 06:54:28 UTC (rev 191)
@@ -32,5 +32,6 @@
Institut für Geowissenschaften, Christian-Albrechts-Universität, Kiel
</publisher>
<publicationYear>2005</publicationYear>
+<resourceType resourceTypeGeneral="Collection">Grey literature</resourceType>
</resource>
\ No newline at end of file
Modified: trunk/src/test/java/au/csiro/doiclient/utils/TestDoiMetaDataGenerator.java
===================================================================
--- trunk/src/test/java/au/csiro/doiclient/utils/TestDoiMetaDataGenerator.java 2016-03-04 03:36:17 UTC (rev 190)
+++ trunk/src/test/java/au/csiro/doiclient/utils/TestDoiMetaDataGenerator.java 2016-10-10 06:54:28 UTC (rev 191)
@@ -76,6 +76,8 @@
doiDTO.setTitle("A conceptual sediment budget for the Vietnam Shelf");
doiDTO.setPublicationYear("2001");
doiDTO.setPublisher("CSIRO");
+ doiDTO.setResourceType("Text");
+ doiDTO.setResourceTypeDescription("Reports");
return doiDTO;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2018-11-21 04:55:14
|
Revision: 202
http://sourceforge.net/p/andspidclient/code/202
Author: chris-trapani
Date: 2018-11-21 04:43:12 +0000 (Wed, 21 Nov 2018)
Log Message:
-----------
set area for geolocation correctly.
remove unused global on test class
Modified Paths:
--------------
trunk/src/main/java/au/csiro/doiclient/business/GeoLocation.java
trunk/src/test/java/au/csiro/doiclient/utils/TestDoiMetaDataGenerator.java
Modified: trunk/src/main/java/au/csiro/doiclient/business/GeoLocation.java
===================================================================
--- trunk/src/main/java/au/csiro/doiclient/business/GeoLocation.java 2018-11-20 23:25:44 UTC (rev 201)
+++ trunk/src/main/java/au/csiro/doiclient/business/GeoLocation.java 2018-11-21 04:43:12 UTC (rev 202)
@@ -44,16 +44,14 @@
* East
* @param w
* West
- * @param locationType
- * The location type
*/
- public GeoLocation(String n, String s, String e, String w, LocationType locationType)
+ public GeoLocation(String n, String s, String e, String w)
{
this.north = n;
this.east = e;
this.south = s;
this.west = w;
- this.locationType = locationType;
+ this.locationType = LocationType.AREA;
}
/**
@@ -63,14 +61,12 @@
* The latitude
* @param longitude
* The longitude
- * @param locationType
- * The location type
*/
- public GeoLocation(String latitude, String longitude, LocationType locationType)
+ public GeoLocation(String latitude, String longitude)
{
this.latitude = latitude;
this.longitude = longitude;
- this.locationType = locationType;
+ this.locationType = LocationType.POINT;
}
public LocationType getLocationType()
Modified: trunk/src/test/java/au/csiro/doiclient/utils/TestDoiMetaDataGenerator.java
===================================================================
--- trunk/src/test/java/au/csiro/doiclient/utils/TestDoiMetaDataGenerator.java 2018-11-20 23:25:44 UTC (rev 201)
+++ trunk/src/test/java/au/csiro/doiclient/utils/TestDoiMetaDataGenerator.java 2018-11-21 04:43:12 UTC (rev 202)
@@ -74,9 +74,6 @@
* Constant giving the xPath of the subject type
*/
private static final String SUBJECT_XPATH = "/xsi:resource/xsi:subjects/xsi:subject";
-
- /** Constant giving the path to the meta-data template **/
- String metadataTemplatePath = "DoiMetadataTemplate.xml";
/**
* Populates a DTO with values that will passed on the DOIMetaDataTemplate.
@@ -114,14 +111,14 @@
// add geo points
List<GeoLocation> geoLocations = new ArrayList<>();
- GeoLocation gl = new GeoLocation("-35.307380", "149.098210", GeoLocation.LocationType.POINT);
+ GeoLocation gl = new GeoLocation("-35.307380", "149.098210");
geoLocations.add(gl);
- GeoLocation gl1 = new GeoLocation("-37.307380", "155.098210", GeoLocation.LocationType.POINT);
+ GeoLocation gl1 = new GeoLocation("-37.307380", "155.098210");
geoLocations.add(gl1);
// add geo area
- GeoLocation gl2 = new GeoLocation("-16.0", "-22.0", "145.0", "139.7", GeoLocation.LocationType.AREA);
+ GeoLocation gl2 = new GeoLocation("-16.0", "-22.0", "145.0", "139.7");
geoLocations.add(gl2);
doiDTO.setGeoLocations(geoLocations);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2018-11-21 04:55:14
|
Revision: 199
http://sourceforge.net/p/andspidclient/code/199
Author: chris-trapani
Date: 2018-11-21 04:42:25 +0000 (Wed, 21 Nov 2018)
Log Message:
-----------
update file version annotations
Modified Paths:
--------------
trunk/src/main/java/au/csiro/doiclient/AndsDoiClient.java
trunk/src/main/java/au/csiro/doiclient/AndsDoiResponse.java
trunk/src/main/java/au/csiro/doiclient/business/AndsDoiIdentity.java
trunk/src/main/java/au/csiro/doiclient/business/Creator.java
trunk/src/main/java/au/csiro/doiclient/business/Description.java
trunk/src/main/java/au/csiro/doiclient/business/DoiDTO.java
trunk/src/main/java/au/csiro/doiclient/business/GeoLocation.java
trunk/src/main/java/au/csiro/doiclient/business/RelatedIdentifier.java
trunk/src/main/java/au/csiro/doiclient/business/Subject.java
trunk/src/main/java/au/csiro/doiclient/utils/ConverterUtils.java
trunk/src/main/java/au/csiro/doiclient/utils/DoiMetaDataGenerator.java
trunk/src/main/java/au/csiro/doiclient/utils/HttpUtil.java
trunk/src/main/java/au/csiro/pidclient/AndsPidClient.java
trunk/src/main/java/au/csiro/pidclient/CustomHttpsSocketFactory.java
trunk/src/test/java/au/csiro/doiclient/utils/TestDoiMetaDataGenerator.java
Modified: trunk/src/main/java/au/csiro/doiclient/AndsDoiClient.java
===================================================================
--- trunk/src/main/java/au/csiro/doiclient/AndsDoiClient.java 2018-11-19 00:44:47 UTC (rev 198)
+++ trunk/src/main/java/au/csiro/doiclient/AndsDoiClient.java 2018-11-21 04:42:25 UTC (rev 199)
@@ -90,7 +90,7 @@
*
* @author Robert Bridle on 05/02/2010
* @author John Page on 03/03/2012
- * @version $Revision: 180 $Date: $
+ * @version $Revision$ $Date$
*/
public class AndsDoiClient
{
Modified: trunk/src/main/java/au/csiro/doiclient/AndsDoiResponse.java
===================================================================
--- trunk/src/main/java/au/csiro/doiclient/AndsDoiResponse.java 2018-11-19 00:44:47 UTC (rev 198)
+++ trunk/src/main/java/au/csiro/doiclient/AndsDoiResponse.java 2018-11-21 04:42:25 UTC (rev 199)
@@ -23,7 +23,7 @@
*
* @author John Page on 06/03/2012
*
- * @version $Revision: 171 $ $Date: 2012-08-02 12:17:06 +1000 (Thu, 02 Aug 2012) $
+ * @version $Revision$ $Date$
*/
public class AndsDoiResponse
{
Modified: trunk/src/main/java/au/csiro/doiclient/business/AndsDoiIdentity.java
===================================================================
--- trunk/src/main/java/au/csiro/doiclient/business/AndsDoiIdentity.java 2018-11-19 00:44:47 UTC (rev 198)
+++ trunk/src/main/java/au/csiro/doiclient/business/AndsDoiIdentity.java 2018-11-21 04:42:25 UTC (rev 199)
@@ -25,7 +25,7 @@
*
* @author John Page on 03/03/2012
*
- * @version $Revision: 142 $Date: $
+ * @version $Revision$ $Date$
*/
public class AndsDoiIdentity
{
Modified: trunk/src/main/java/au/csiro/doiclient/business/Creator.java
===================================================================
--- trunk/src/main/java/au/csiro/doiclient/business/Creator.java 2018-11-19 00:44:47 UTC (rev 198)
+++ trunk/src/main/java/au/csiro/doiclient/business/Creator.java 2018-11-21 04:42:25 UTC (rev 199)
@@ -10,7 +10,7 @@
* Copyright 2012, CSIRO Australia All rights reserved.
*
* @author Chris Trapani on 13/11/2018
- * @version $Revision: 191 $Date: $
+ * @version $Revision$ $Date$
*/
public class Creator
{
Modified: trunk/src/main/java/au/csiro/doiclient/business/Description.java
===================================================================
--- trunk/src/main/java/au/csiro/doiclient/business/Description.java 2018-11-19 00:44:47 UTC (rev 198)
+++ trunk/src/main/java/au/csiro/doiclient/business/Description.java 2018-11-21 04:42:25 UTC (rev 199)
@@ -8,7 +8,7 @@
* Copyright 2012, CSIRO Australia All rights reserved.
*
* @author Chris Trapani on 13/11/2018
- * @version $Revision: 191 $Date: $
+ * @version $Revision$ $Date$
*/
public class Description
{
Modified: trunk/src/main/java/au/csiro/doiclient/business/DoiDTO.java
===================================================================
--- trunk/src/main/java/au/csiro/doiclient/business/DoiDTO.java 2018-11-19 00:44:47 UTC (rev 198)
+++ trunk/src/main/java/au/csiro/doiclient/business/DoiDTO.java 2018-11-21 04:42:25 UTC (rev 199)
@@ -28,7 +28,7 @@
* Copyright 2012, CSIRO Australia All rights reserved.
*
* @author John Page on 03/03/2012
- * @version $Revision: 191 $Date: $
+ * @version $Revision$ $Date$
*/
public class DoiDTO implements Serializable
{
Modified: trunk/src/main/java/au/csiro/doiclient/business/GeoLocation.java
===================================================================
--- trunk/src/main/java/au/csiro/doiclient/business/GeoLocation.java 2018-11-19 00:44:47 UTC (rev 198)
+++ trunk/src/main/java/au/csiro/doiclient/business/GeoLocation.java 2018-11-21 04:42:25 UTC (rev 199)
@@ -8,7 +8,7 @@
* Copyright 2012, CSIRO Australia All rights reserved.
*
* @author Chris Trapani on 13/11/2018
- * @version $Revision: 191 $Date: $
+ * @version $Revision$ $Date$
*/
public class GeoLocation
{
Modified: trunk/src/main/java/au/csiro/doiclient/business/RelatedIdentifier.java
===================================================================
--- trunk/src/main/java/au/csiro/doiclient/business/RelatedIdentifier.java 2018-11-19 00:44:47 UTC (rev 198)
+++ trunk/src/main/java/au/csiro/doiclient/business/RelatedIdentifier.java 2018-11-21 04:42:25 UTC (rev 199)
@@ -6,7 +6,7 @@
* Copyright 2012, CSIRO Australia All rights reserved.
*
* @author Chris Trapani on 13/11/2018
- * @version $Revision: 191 $Date: $
+ * @version $Revision$ $Date$
*/
public class RelatedIdentifier
{
Modified: trunk/src/main/java/au/csiro/doiclient/business/Subject.java
===================================================================
--- trunk/src/main/java/au/csiro/doiclient/business/Subject.java 2018-11-19 00:44:47 UTC (rev 198)
+++ trunk/src/main/java/au/csiro/doiclient/business/Subject.java 2018-11-21 04:42:25 UTC (rev 199)
@@ -8,7 +8,7 @@
* Copyright 2012, CSIRO Australia All rights reserved.
*
* @author Chris Trapani on 13/11/2018
- * @version $Revision: 191 $Date: $
+ * @version $Revision$ $Date$
*/
public class Subject
{
Modified: trunk/src/main/java/au/csiro/doiclient/utils/ConverterUtils.java
===================================================================
--- trunk/src/main/java/au/csiro/doiclient/utils/ConverterUtils.java 2018-11-19 00:44:47 UTC (rev 198)
+++ trunk/src/main/java/au/csiro/doiclient/utils/ConverterUtils.java 2018-11-21 04:42:25 UTC (rev 199)
@@ -50,7 +50,7 @@
* Copyright 2012, CSIRO Australia All rights reserved.
*
* @author Martin Pienaar on 22/07/2012
- * @version $Revision: 191 $ $Date: 2016-10-10 17:54:28 +1100 (Mon, 10 Oct 2016) $
+ * @version $Revision$ $Date$
*/
public class ConverterUtils
{
Modified: trunk/src/main/java/au/csiro/doiclient/utils/DoiMetaDataGenerator.java
===================================================================
--- trunk/src/main/java/au/csiro/doiclient/utils/DoiMetaDataGenerator.java 2018-11-19 00:44:47 UTC (rev 198)
+++ trunk/src/main/java/au/csiro/doiclient/utils/DoiMetaDataGenerator.java 2018-11-21 04:42:25 UTC (rev 199)
@@ -40,7 +40,7 @@
* Copyright 2012, CSIRO Australia All rights reserved.
*
* @author John Page on 03/03/2011
- * @version $Revision: 191 $Date: $
+ * @version $Revision$ $Date$
*/
public class DoiMetaDataGenerator
{
Modified: trunk/src/main/java/au/csiro/doiclient/utils/HttpUtil.java
===================================================================
--- trunk/src/main/java/au/csiro/doiclient/utils/HttpUtil.java 2018-11-19 00:44:47 UTC (rev 198)
+++ trunk/src/main/java/au/csiro/doiclient/utils/HttpUtil.java 2018-11-21 04:42:25 UTC (rev 199)
@@ -30,7 +30,7 @@
* All rights reserved.
*
* @author Simon Bear on 15/05/2012
- * @version $Revision: 155 $ $Date: 2012-05-16 12:25:34 +1000 (Wed, 16 May 2012) $
+ * @version $Revision$ $Date$
*/
public class HttpUtil
{
Modified: trunk/src/main/java/au/csiro/pidclient/AndsPidClient.java
===================================================================
--- trunk/src/main/java/au/csiro/pidclient/AndsPidClient.java 2018-11-19 00:44:47 UTC (rev 198)
+++ trunk/src/main/java/au/csiro/pidclient/AndsPidClient.java 2018-11-21 04:42:25 UTC (rev 199)
@@ -89,7 +89,7 @@
* Copyright 2012, CSIRO Australia All rights reserved.
*
* @author Robert Bridle on 05/02/2010
- * @version $Revision: 7131 $ $Date: 2010-06-09 14:25:15 +1000 (Wed, 09 Jun 2010) $
+ * @version $Revision$ $Date$
*/
public class AndsPidClient
{
Modified: trunk/src/main/java/au/csiro/pidclient/CustomHttpsSocketFactory.java
===================================================================
--- trunk/src/main/java/au/csiro/pidclient/CustomHttpsSocketFactory.java 2018-11-19 00:44:47 UTC (rev 198)
+++ trunk/src/main/java/au/csiro/pidclient/CustomHttpsSocketFactory.java 2018-11-21 04:42:25 UTC (rev 199)
@@ -33,7 +33,7 @@
* Copyright 2016, CSIRO Australia All rights reserved.
*
* @author John Page on 18/02/2016
- * @version $Revision: 181 $ $Date: 2016-02-19 13:40:28 +1100 (Fri, 19 Feb 2016) $
+ * @version $Revision$ $Date$
*/
public class CustomHttpsSocketFactory implements SecureProtocolSocketFactory
{
Modified: trunk/src/test/java/au/csiro/doiclient/utils/TestDoiMetaDataGenerator.java
===================================================================
--- trunk/src/test/java/au/csiro/doiclient/utils/TestDoiMetaDataGenerator.java 2018-11-19 00:44:47 UTC (rev 198)
+++ trunk/src/test/java/au/csiro/doiclient/utils/TestDoiMetaDataGenerator.java 2018-11-21 04:42:25 UTC (rev 199)
@@ -36,7 +36,7 @@
* Copyright 2012, CSIRO Australia All rights reserved.
*
* @author John Page on 6/03/2012
- * @version $Revision: 192 $Date: $
+ * @version $Revision$ $Date$
*/
public class TestDoiMetaDataGenerator extends TestCase
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2018-12-06 23:40:49
|
Revision: 207
http://sourceforge.net/p/andspidclient/code/207
Author: chris-trapani
Date: 2018-12-06 23:40:47 +0000 (Thu, 06 Dec 2018)
Log Message:
-----------
DMSTECH-9633: preserve dto order for contruibutors.
Modified Paths:
--------------
trunk/src/main/java/au/csiro/doiclient/utils/ConverterUtils.java
trunk/src/test/java/au/csiro/doiclient/utils/TestDoiMetaDataGenerator.java
Modified: trunk/src/main/java/au/csiro/doiclient/utils/ConverterUtils.java
===================================================================
--- trunk/src/main/java/au/csiro/doiclient/utils/ConverterUtils.java 2018-12-02 23:21:16 UTC (rev 206)
+++ trunk/src/main/java/au/csiro/doiclient/utils/ConverterUtils.java 2018-12-06 23:40:47 UTC (rev 207)
@@ -454,7 +454,7 @@
creator.getAffiliation());
Element grandParent = baseElement.getParentElement();
- grandParent.getParentElement().addContent(1, newCreatorNode);
+ grandParent.getParentElement().addContent(counter+1, newCreatorNode);
}
}
else
@@ -509,7 +509,7 @@
baseElement.setAttribute(DoiMetaDataGenerator.DESCRIPTION_TYPE, firstNode.getDescriptionType());
}
- baseElement.getParentElement().addContent(1, newNode);
+ baseElement.getParentElement().addContent(counter+1, newNode);
}
}
else
@@ -634,7 +634,7 @@
clonedParentElement.detach();
Element grandParent = parent.getParentElement();
- grandParent.addContent(1, clonedParentElement);
+ grandParent.addContent(counter+1, clonedParentElement);
}
}
Modified: trunk/src/test/java/au/csiro/doiclient/utils/TestDoiMetaDataGenerator.java
===================================================================
--- trunk/src/test/java/au/csiro/doiclient/utils/TestDoiMetaDataGenerator.java 2018-12-02 23:21:16 UTC (rev 206)
+++ trunk/src/test/java/au/csiro/doiclient/utils/TestDoiMetaDataGenerator.java 2018-12-06 23:40:47 UTC (rev 207)
@@ -147,16 +147,16 @@
private List<Creator> createDummyCreators()
{
List<Creator> creators = new ArrayList<Creator>();
- creators.add(new Creator("John", "Smith"));
- creators.add(new Creator("Matt", "Green"));
- creators.add(new Creator("Alison", "Chapman"));
- creators.add(new Creator("Rahul", "Gandhi"));
- creators.add(new Creator("Rahul", "Dravid"));
- creators.add(new Creator("David", "Phillips"));
Creator c = new Creator();
c.setCreatorName("CSIRO");
c.setNameType("Organizational");
creators.add(c);
+ creators.add(new Creator("David", "Phillips"));
+ creators.add(new Creator("Rahul", "Gandhi"));
+ creators.add(new Creator("Alison", "Chapman"));
+ creators.add(new Creator("Matt", "Green"));
+ creators.add(new Creator("Rahul", "Dravid"));
+ creators.add(new Creator("John", "Smith"));
return creators;
}
@@ -207,10 +207,10 @@
assertEquals("creatorName", ((Element) nodes.get(0)).getName());
assertEquals("CSIRO", ((Element) nodes.get(0)).getText());
assertEquals("Phillips, David", ((Element) nodes.get(1)).getText());
- assertEquals("Dravid, Rahul", ((Element) nodes.get(2)).getText());
- assertEquals("Gandhi, Rahul", ((Element) nodes.get(3)).getText());
- assertEquals("Chapman, Alison", ((Element) nodes.get(4)).getText());
- assertEquals("Green, Matt", ((Element) nodes.get(5)).getText());
+ assertEquals("Gandhi, Rahul", ((Element) nodes.get(2)).getText());
+ assertEquals("Chapman, Alison", ((Element) nodes.get(3)).getText());
+ assertEquals("Green, Matt", ((Element) nodes.get(4)).getText());
+ assertEquals("Dravid, Rahul", ((Element) nodes.get(5)).getText());
assertEquals("Smith, John", ((Element) nodes.get(6)).getText());
XPath resourceTypeXPath = XPath.newInstance(RESOURCETYPE_NAME_XPATH);
@@ -452,7 +452,7 @@
List<Creator> creators = dto.getCreators();
creators.remove(3);
creators.remove(4);
- dto.getCreators().get(0).setFirstName("changed");
+ dto.getCreators().get(1).setFirstName("changed");
dto.setCreators(creators);
@@ -488,10 +488,10 @@
assertEquals("creatorName", ((Element) nodes.get(0)).getName());
assertEquals("CSIRO", ((Element) nodes.get(0)).getText());
- assertEquals("Dravid, Rahul", ((Element) nodes.get(1)).getText());
- assertEquals("Chapman, Alison", ((Element) nodes.get(2)).getText());
+ assertEquals("Phillips, changed", ((Element) nodes.get(1)).getText());
+ assertEquals("Gandhi, Rahul", ((Element) nodes.get(2)).getText());
assertEquals("Green, Matt", ((Element) nodes.get(3)).getText());
- assertEquals("Smith, changed", ((Element) nodes.get(4)).getText());
+ assertEquals("Smith, John", ((Element) nodes.get(4)).getText());
assertEquals("creatorName", ((Element) nodes.get(0)).getName());
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2018-12-11 04:34:54
|
Revision: 211
http://sourceforge.net/p/andspidclient/code/211
Author: chris-trapani
Date: 2018-12-11 04:34:52 +0000 (Tue, 11 Dec 2018)
Log Message:
-----------
DMSTECH-9641 unit test fix + some code clean up checkstyle & findbugs
Modified Paths:
--------------
trunk/src/main/java/au/csiro/doiclient/business/Creator.java
trunk/src/main/java/au/csiro/doiclient/business/Description.java
trunk/src/main/java/au/csiro/doiclient/business/GeoLocation.java
trunk/src/main/java/au/csiro/doiclient/business/RelatedIdentifier.java
trunk/src/main/java/au/csiro/doiclient/business/Subject.java
trunk/src/main/java/au/csiro/doiclient/utils/ConverterUtils.java
trunk/src/main/java/au/csiro/pidclient/AndsPidClient.java
trunk/src/main/java/au/csiro/pidclient/AndsPidResponse.java
trunk/src/main/java/au/csiro/pidclient/CustomHttpsSocketFactory.java
trunk/src/test/java/au/csiro/doiclient/utils/TestDoiMetaDataGenerator.java
Modified: trunk/src/main/java/au/csiro/doiclient/business/Creator.java
===================================================================
--- trunk/src/main/java/au/csiro/doiclient/business/Creator.java 2018-12-11 03:31:27 UTC (rev 210)
+++ trunk/src/main/java/au/csiro/doiclient/business/Creator.java 2018-12-11 04:34:52 UTC (rev 211)
@@ -1,5 +1,7 @@
package au.csiro.doiclient.business;
+import java.io.Serializable;
+
import org.apache.commons.lang.StringUtils;
/**
@@ -12,8 +14,11 @@
* @author Chris Trapani on 13/11/2018
* @version $Revision$ $Date$
*/
-public class Creator
+public class Creator implements Serializable
{
+ /** Generated serial version **/
+ private static final long serialVersionUID = 6854351518485871962L;
+
private String firstName;
private String lastName;
private String nameType;
@@ -36,10 +41,11 @@
* @param lastName
* The last name
*/
- public Creator(String firstName, String lastName)
+ public Creator(String firstName, String lastName, String nameType)
{
this.firstName = firstName;
this.lastName = lastName;
+ this.nameType = nameType;
}
/**
Modified: trunk/src/main/java/au/csiro/doiclient/business/Description.java
===================================================================
--- trunk/src/main/java/au/csiro/doiclient/business/Description.java 2018-12-11 03:31:27 UTC (rev 210)
+++ trunk/src/main/java/au/csiro/doiclient/business/Description.java 2018-12-11 04:34:52 UTC (rev 211)
@@ -1,5 +1,7 @@
package au.csiro.doiclient.business;
+import java.io.Serializable;
+
/**
* Class representing a Creator.
*
@@ -10,8 +12,11 @@
* @author Chris Trapani on 13/11/2018
* @version $Revision$ $Date$
*/
-public class Description
+public class Description implements Serializable
{
+ /** Generated serial version **/
+ private static final long serialVersionUID = 2792195337953631667L;
+
/**
* Description.
*/
Modified: trunk/src/main/java/au/csiro/doiclient/business/GeoLocation.java
===================================================================
--- trunk/src/main/java/au/csiro/doiclient/business/GeoLocation.java 2018-12-11 03:31:27 UTC (rev 210)
+++ trunk/src/main/java/au/csiro/doiclient/business/GeoLocation.java 2018-12-11 04:34:52 UTC (rev 211)
@@ -1,5 +1,7 @@
package au.csiro.doiclient.business;
+import java.io.Serializable;
+
/**
* Class representing a Creator.
*
@@ -10,8 +12,11 @@
* @author Chris Trapani on 13/11/2018
* @version $Revision$ $Date$
*/
-public class GeoLocation
+public class GeoLocation implements Serializable
{
+ /** Generated serial version **/
+ private static final long serialVersionUID = 4236374370542494432L;
+
/**
* Geo Location type
*/
Modified: trunk/src/main/java/au/csiro/doiclient/business/RelatedIdentifier.java
===================================================================
--- trunk/src/main/java/au/csiro/doiclient/business/RelatedIdentifier.java 2018-12-11 03:31:27 UTC (rev 210)
+++ trunk/src/main/java/au/csiro/doiclient/business/RelatedIdentifier.java 2018-12-11 04:34:52 UTC (rev 211)
@@ -1,5 +1,7 @@
package au.csiro.doiclient.business;
+import java.io.Serializable;
+
/**
* Class representing an Related identifier.
*
@@ -8,8 +10,11 @@
* @author Chris Trapani on 13/11/2018
* @version $Revision$ $Date$
*/
-public class RelatedIdentifier
+public class RelatedIdentifier implements Serializable
{
+ /** Generated serial version **/
+ private static final long serialVersionUID = -3661963648667782037L;
+
private String relatedIdentifierType;
private String relationType;
private String value;
Modified: trunk/src/main/java/au/csiro/doiclient/business/Subject.java
===================================================================
--- trunk/src/main/java/au/csiro/doiclient/business/Subject.java 2018-12-11 03:31:27 UTC (rev 210)
+++ trunk/src/main/java/au/csiro/doiclient/business/Subject.java 2018-12-11 04:34:52 UTC (rev 211)
@@ -1,5 +1,7 @@
package au.csiro.doiclient.business;
+import java.io.Serializable;
+
/**
* Class representing a Creator.
*
@@ -10,8 +12,11 @@
* @author Chris Trapani on 13/11/2018
* @version $Revision$ $Date$
*/
-public class Subject
+public class Subject implements Serializable
{
+ /** Generated serial version **/
+ private static final long serialVersionUID = 8619853034995761718L;
+
private String subject;
private String subjectScheme;
private String schemeURI;
Modified: trunk/src/main/java/au/csiro/doiclient/utils/ConverterUtils.java
===================================================================
--- trunk/src/main/java/au/csiro/doiclient/utils/ConverterUtils.java 2018-12-11 03:31:27 UTC (rev 210)
+++ trunk/src/main/java/au/csiro/doiclient/utils/ConverterUtils.java 2018-12-11 04:34:52 UTC (rev 211)
@@ -429,6 +429,7 @@
firstNode.getAffiliation());
detachExistingNodes(xPath, document);
+
for (int counter = 1; counter < creators.size(); counter++)
{
Element newCreatorNode = (Element) immutableclonedParentElement.clone();
@@ -436,7 +437,7 @@
Creator creator = creators.get(counter);
childElement.setText(stripNonValidXMLCharacters(creator.getCreatorName()));
-
+ childElement.setAttribute(DoiMetaDataGenerator.NAME_TYPE, creator.getNameType());
setElementValueForParent(document, newCreatorNode, DoiMetaDataGenerator.GIVEN_NAME,
creator.getFirstName());
setElementValueForParent(document, newCreatorNode, DoiMetaDataGenerator.FAMILY_NAME,
@@ -445,7 +446,6 @@
creator.getNameIdentifier());
setElementValueForParent(document, newCreatorNode, DoiMetaDataGenerator.AFFILIATION,
creator.getAffiliation());
- newCreatorNode.setAttribute(DoiMetaDataGenerator.NAME_TYPE, creator.getNameType());
Element grandParent = baseElement.getParentElement();
grandParent.getParentElement().addContent(counter+1, newCreatorNode);
Modified: trunk/src/main/java/au/csiro/pidclient/AndsPidClient.java
===================================================================
--- trunk/src/main/java/au/csiro/pidclient/AndsPidClient.java 2018-12-11 03:31:27 UTC (rev 210)
+++ trunk/src/main/java/au/csiro/pidclient/AndsPidClient.java 2018-12-11 04:34:52 UTC (rev 211)
@@ -1164,7 +1164,7 @@
Node node = (Node) nodes.item(i).getAttributes().item(j);
triple[j] = node.getNodeValue();
}
- properties.add(new AndsPidResponseProperty(Integer.valueOf(triple[0]), triple[1], triple[2]));
+ properties.add(new AndsPidResponseProperty(Integer.parseInt(triple[0]), triple[1], triple[2]));
}
return properties;
}
Modified: trunk/src/main/java/au/csiro/pidclient/AndsPidResponse.java
===================================================================
--- trunk/src/main/java/au/csiro/pidclient/AndsPidResponse.java 2018-12-11 03:31:27 UTC (rev 210)
+++ trunk/src/main/java/au/csiro/pidclient/AndsPidResponse.java 2018-12-11 04:34:52 UTC (rev 211)
@@ -21,6 +21,8 @@
import java.util.List;
+import org.apache.commons.collections4.CollectionUtils;
+
import au.csiro.pidclient.business.AndsPidResponseProperty;
/**
@@ -127,12 +129,7 @@
*/
public String getHandle()
{
- for(String handle : this.getHandles())
- {
- // return the first element in this list in proper sequence.
- return handle;
- }
- return AndsPidResponse.NO_HANDLE_FOUND;
+ return CollectionUtils.isEmpty(handles) ? AndsPidResponse.NO_HANDLE_FOUND : this.getHandles().get(0);
}
/**
Modified: trunk/src/main/java/au/csiro/pidclient/CustomHttpsSocketFactory.java
===================================================================
--- trunk/src/main/java/au/csiro/pidclient/CustomHttpsSocketFactory.java 2018-12-11 03:31:27 UTC (rev 210)
+++ trunk/src/main/java/au/csiro/pidclient/CustomHttpsSocketFactory.java 2018-12-11 04:34:52 UTC (rev 211)
@@ -66,11 +66,8 @@
return sslSocket;
}
- /*
- * (non-Javadoc)
- *
- * @see org.apache.commons.httpclient.protocol.ProtocolSocketFactory#createSocket(java.lang.String, int,
- * java.net.InetAddress, int)
+ /**
+ * {@inheritDoc}
*/
public Socket createSocket(String host, int port, InetAddress localAddress, int localPort) throws IOException,
UnknownHostException
@@ -78,11 +75,8 @@
return acceptOnlyTLS12(base.createSocket(host, port, localAddress, localPort));
}
- /*
- * (non-Javadoc)
- *
- * @see org.apache.commons.httpclient.protocol.ProtocolSocketFactory#createSocket(java.lang.String, int,
- * java.net.InetAddress, int, org.apache.commons.httpclient.params.HttpConnectionParams)
+ /**
+ * {@inheritDoc}
*/
public Socket createSocket(String host, int port, InetAddress localAddress, int localPort,
HttpConnectionParams params) throws IOException, UnknownHostException, ConnectTimeoutException
@@ -90,10 +84,8 @@
return acceptOnlyTLS12(base.createSocket(host, port, localAddress, localPort, params));
}
- /*
- * (non-Javadoc)
- *
- * @see org.apache.commons.httpclient.protocol.ProtocolSocketFactory#createSocket(java.lang.String, int)
+ /**
+ * {@inheritDoc}
*/
public Socket createSocket(String host, int port) throws IOException, UnknownHostException
{
@@ -100,11 +92,8 @@
return acceptOnlyTLS12(base.createSocket(host, port));
}
- /*
- * (non-Javadoc)
- *
- * @see org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory#createSocket(java.net.Socket,
- * java.lang.String, int, boolean)
+ /**
+ * {@inheritDoc}
*/
public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException,
UnknownHostException
Modified: trunk/src/test/java/au/csiro/doiclient/utils/TestDoiMetaDataGenerator.java
===================================================================
--- trunk/src/test/java/au/csiro/doiclient/utils/TestDoiMetaDataGenerator.java 2018-12-11 03:31:27 UTC (rev 210)
+++ trunk/src/test/java/au/csiro/doiclient/utils/TestDoiMetaDataGenerator.java 2018-12-11 04:34:52 UTC (rev 211)
@@ -151,12 +151,12 @@
c.setCreatorName("CSIRO");
c.setNameType("Organizational");
creators.add(c);
- creators.add(new Creator("David", "Phillips"));
- creators.add(new Creator("Rahul", "Gandhi"));
- creators.add(new Creator("Alison", "Chapman"));
- creators.add(new Creator("Matt", "Green"));
- creators.add(new Creator("Rahul", "Dravid"));
- creators.add(new Creator("John", "Smith"));
+ creators.add(new Creator("David", "Phillips", "Personal"));
+ creators.add(new Creator("Rahul", "Gandhi", "Personal"));
+ creators.add(new Creator("Alison", "Chapman", "Personal"));
+ creators.add(new Creator("Matt", "Green", "Personal"));
+ creators.add(new Creator("Rahul", "Dravid", "Personal"));
+ creators.add(new Creator("John", "Smith", "Personal"));
return creators;
}
@@ -367,7 +367,8 @@
}
catch (IllegalArgumentException ex)
{
- // This is expected
+ assertTrue(ex instanceof IllegalArgumentException);
+ assertEquals(ex.getMessage(),"It is most likely that one parameter in DoiDTO is invalid");
}
doiDTO = populateDummydoiDTO();
@@ -378,9 +379,10 @@
DoiMetaDataGenerator.createDoiMetaDataXML(doiDTO);
fail("Validation for Title passed even when we expected to fail");
}
- catch (IllegalArgumentException ex)
+ catch (Exception ex)
{
- // This is expected
+ assertTrue(ex instanceof IllegalArgumentException);
+ assertEquals(ex.getMessage(),"It is most likely that one parameter in DoiDTO is invalid");
}
doiDTO = populateDummydoiDTO();
@@ -393,7 +395,8 @@
}
catch (IllegalArgumentException ex)
{
- // This is expected
+ assertTrue(ex instanceof IllegalArgumentException);
+ assertEquals(ex.getMessage(),"It is most likely that one parameter in DoiDTO is invalid");
}
doiDTO = populateDummydoiDTO();
@@ -406,7 +409,8 @@
}
catch (IllegalArgumentException ex)
{
- // This is expected
+ assertTrue(ex instanceof IllegalArgumentException);
+ assertEquals(ex.getMessage(),"It is most likely that one parameter in DoiDTO is invalid");
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2019-02-04 03:23:08
|
Revision: 215
http://sourceforge.net/p/andspidclient/code/215
Author: chris-trapani
Date: 2019-02-04 03:23:05 +0000 (Mon, 04 Feb 2019)
Log Message:
-----------
EPR-5168 DOI minting fails when creator type is not set.
Modified Paths:
--------------
trunk/src/main/java/au/csiro/doiclient/business/Creator.java
trunk/src/main/java/au/csiro/doiclient/utils/ConverterUtils.java
trunk/src/test/java/au/csiro/doiclient/utils/TestDoiMetaDataGenerator.java
Modified: trunk/src/main/java/au/csiro/doiclient/business/Creator.java
===================================================================
--- trunk/src/main/java/au/csiro/doiclient/business/Creator.java 2018-12-11 04:34:18 UTC (rev 214)
+++ trunk/src/main/java/au/csiro/doiclient/business/Creator.java 2019-02-04 03:23:05 UTC (rev 215)
@@ -34,7 +34,7 @@
}
/**
- * Create Creator from first and last name.
+ * Create Creator from first and last name and name type.
*
* @param firstName
* The first name
@@ -49,6 +49,20 @@
this.lastName = lastName;
this.nameType = nameType;
}
+
+ /**
+ * Create Creator from first and last name.
+ *
+ * @param firstName
+ * The first name
+ * @param lastName
+ * The last name
+ */
+ public Creator(String firstName, String lastName)
+ {
+ this.firstName = firstName;
+ this.lastName = lastName;
+ }
/**
* Get creator name, If not specified then last name + first name is returned.
Modified: trunk/src/main/java/au/csiro/doiclient/utils/ConverterUtils.java
===================================================================
--- trunk/src/main/java/au/csiro/doiclient/utils/ConverterUtils.java 2018-12-11 04:34:18 UTC (rev 214)
+++ trunk/src/main/java/au/csiro/doiclient/utils/ConverterUtils.java 2019-02-04 03:23:05 UTC (rev 215)
@@ -416,7 +416,7 @@
if (StringUtils.isNotEmpty(firstNode.getNameType()))
{
- updateAttribute(document, nameSpace, element, DoiMetaDataGenerator.NAME_TYPE, firstNode.getNameType());
+ baseElement.setAttribute(DoiMetaDataGenerator.NAME_TYPE, firstNode.getNameType());
}
setElementValueForParent(document, baseElement.getParentElement(), DoiMetaDataGenerator.GIVEN_NAME,
@@ -437,7 +437,10 @@
Creator creator = creators.get(counter);
childElement.setText(stripNonValidXMLCharacters(creator.getCreatorName()));
- childElement.setAttribute(DoiMetaDataGenerator.NAME_TYPE, creator.getNameType());
+ if (StringUtils.isNotEmpty(creator.getNameType()))
+ {
+ childElement.setAttribute(DoiMetaDataGenerator.NAME_TYPE, firstNode.getNameType());
+ }
setElementValueForParent(document, newCreatorNode, DoiMetaDataGenerator.GIVEN_NAME,
creator.getFirstName());
setElementValueForParent(document, newCreatorNode, DoiMetaDataGenerator.FAMILY_NAME,
Modified: trunk/src/test/java/au/csiro/doiclient/utils/TestDoiMetaDataGenerator.java
===================================================================
--- trunk/src/test/java/au/csiro/doiclient/utils/TestDoiMetaDataGenerator.java 2018-12-11 04:34:18 UTC (rev 214)
+++ trunk/src/test/java/au/csiro/doiclient/utils/TestDoiMetaDataGenerator.java 2019-02-04 03:23:05 UTC (rev 215)
@@ -78,13 +78,16 @@
/**
* Populates a DTO with values that will passed on the DOIMetaDataTemplate.
*
- * @param doiDTO
+ * @param withNameTypes
+ * for name type values to be populated pass in true
+ * @return doiDTO
* DTO with the values for the DOIMetaDataTemplate.
*/
- private DoiDTO populateDummydoiDTO()
+ private DoiDTO populateDummydoiDTO(boolean withNameTypes)
{
DoiDTO doiDTO = new DoiDTO();
- List<Creator> creators = createDummyCreators();
+ List<Creator> creators = withNameTypes? createDummyCreators(): createDummyCreatorsWithoutNameType();
+
// creators
doiDTO.setCreators(creators);
@@ -159,6 +162,22 @@
creators.add(new Creator("John", "Smith", "Personal"));
return creators;
}
+
+
+ private List<Creator> createDummyCreatorsWithoutNameType()
+ {
+ List<Creator> creators = new ArrayList<Creator>();
+ Creator c = new Creator();
+ c.setCreatorName("CSIRO");
+ creators.add(c);
+ creators.add(new Creator("David", "Phillips"));
+ creators.add(new Creator("Rahul", "Gandhi"));
+ creators.add(new Creator("Alison", "Chapman"));
+ creators.add(new Creator("Matt", "Green"));
+ creators.add(new Creator("Rahul", "Dravid"));
+ creators.add(new Creator("John", "Smith"));
+ return creators;
+ }
private DoiDTO populateDummydoiDTOMinimal()
@@ -194,8 +213,8 @@
*/
public final void testCreateDoiMetaDataXML() throws Exception
{
- String doiMetaDataXML = DoiMetaDataGenerator.createDoiMetaDataXML(populateDummydoiDTO());
- assertNotNull(doiMetaDataXML);
+ String doiMetaDataXML = DoiMetaDataGenerator.createDoiMetaDataXML(populateDummydoiDTO(true));
+ assertNotNull(doiMetaDataXML);
Document document = ConverterUtils.xmlToDoc(doiMetaDataXML);
XPath xPath = XPath.newInstance(CREATOR_NAME_XPATH);
@@ -205,6 +224,7 @@
assertEquals(7, nodes.size());
assertEquals("creatorName", ((Element) nodes.get(0)).getName());
+ assertEquals("Organizational",((Element) nodes.get(0)).getAttributeValue("nameType"));
assertEquals("CSIRO", ((Element) nodes.get(0)).getText());
assertEquals("Phillips, David", ((Element) nodes.get(1)).getText());
assertEquals("Gandhi, Rahul", ((Element) nodes.get(2)).getText());
@@ -212,6 +232,27 @@
assertEquals("Green, Matt", ((Element) nodes.get(4)).getText());
assertEquals("Dravid, Rahul", ((Element) nodes.get(5)).getText());
assertEquals("Smith, John", ((Element) nodes.get(6)).getText());
+
+ String doiMetaDataNoNameTypeXML = DoiMetaDataGenerator.createDoiMetaDataXML(populateDummydoiDTO(false));
+ assertNotNull(doiMetaDataNoNameTypeXML);
+ Document documentNoNameType = ConverterUtils.xmlToDoc(doiMetaDataNoNameTypeXML);
+ XPath xPathNoNameType = XPath.newInstance(CREATOR_NAME_XPATH);
+ xPathNoNameType.addNamespace("xsi", documentNoNameType.getRootElement().getNamespaceURI());
+ @SuppressWarnings("rawtypes")
+ List nodesx = xPathNoNameType.selectNodes(documentNoNameType);
+ assertEquals(7, nodesx.size());
+ assertEquals("Personal",((Element) nodesx.get(0)).getAttributeValue("nameType"));
+ assertEquals("creatorName", ((Element) nodesx.get(0)).getName());
+ assertEquals("CSIRO", ((Element) nodesx.get(0)).getText());
+
+ assertEquals("Phillips, David", ((Element) nodesx.get(1)).getText());
+ //nameType is from template even though its no set in creator object
+ assertEquals("Personal", ((Element) nodesx.get(1)).getAttributeValue("nameType"));
+ assertEquals("Gandhi, Rahul", ((Element) nodesx.get(2)).getText());
+ assertEquals("Chapman, Alison", ((Element) nodesx.get(3)).getText());
+ assertEquals("Green, Matt", ((Element) nodesx.get(4)).getText());
+ assertEquals("Dravid, Rahul", ((Element) nodesx.get(5)).getText());
+ assertEquals("Smith, John", ((Element) nodesx.get(6)).getText());
XPath resourceTypeXPath = XPath.newInstance(RESOURCETYPE_NAME_XPATH);
resourceTypeXPath.addNamespace("xsi", document.getRootElement().getNamespaceURI());
@@ -358,7 +399,7 @@
*/
public final void testCreateDoiMetaDataXMLWithInvalidData() throws Exception
{
- DoiDTO doiDTO = populateDummydoiDTO();
+ DoiDTO doiDTO = populateDummydoiDTO(true);
doiDTO.setPublicationYear("234");
try
{
@@ -371,7 +412,7 @@
assertEquals(ex.getMessage(),"It is most likely that one parameter in DoiDTO is invalid");
}
- doiDTO = populateDummydoiDTO();
+ doiDTO = populateDummydoiDTO(true);
doiDTO.setTitle(null);
try
@@ -385,7 +426,7 @@
assertEquals(ex.getMessage(),"It is most likely that one parameter in DoiDTO is invalid");
}
- doiDTO = populateDummydoiDTO();
+ doiDTO = populateDummydoiDTO(true);
doiDTO.getCreators().clear();
try
@@ -399,7 +440,7 @@
assertEquals(ex.getMessage(),"It is most likely that one parameter in DoiDTO is invalid");
}
- doiDTO = populateDummydoiDTO();
+ doiDTO = populateDummydoiDTO(true);
doiDTO.setPublisher(null);
try
@@ -423,7 +464,7 @@
{
String doi = "10.5072/08/4F5838BF44E5A";
- String doiMetaDataXML = DoiMetaDataGenerator.createDoiMetaDataXML(populateDummydoiDTO());
+ String doiMetaDataXML = DoiMetaDataGenerator.createDoiMetaDataXML(populateDummydoiDTO(true));
assertNotNull(doiMetaDataXML);
String updatedMetaData = DoiMetaDataGenerator.updateDOI(doi, doiMetaDataXML);
@@ -450,7 +491,7 @@
public final void testUpdate() throws Exception
{
- DoiDTO dto = populateDummydoiDTO();
+ DoiDTO dto = populateDummydoiDTO(true);
String doiMetaDataXML = DoiMetaDataGenerator.createDoiMetaDataXML(dto);
List<Creator> creators = dto.getCreators();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|