Skip to content
Snippets Groups Projects
Commit 1710a94e authored by sveseli's avatar sveseli
Browse files

introduced experiment DS rest api

parent 78e36395
No related branches found
No related tags found
No related merge requests found
......@@ -666,8 +666,7 @@ public class DmRestApi {
//client.login("sveseli", "sveseli");
HashMap<String, String> data = new HashMap<>();
//data.put("parentDirectory", "/");
String drawing = client.invokeGetRequest("/pdmLink/drawings/D14100201-113160.asm");
System.out.println("Drawing: \n" + drawing);
client.invokeGetRequest("/experiment/e1");
} catch (DmException ex) {
System.out.println("Sorry: " + ex);
}
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package gov.anl.aps.dm.api;
import gov.anl.aps.dm.common.exceptions.ConfigurationError;
import gov.anl.aps.dm.common.exceptions.DmException;
import gov.anl.aps.dm.common.exceptions.InvalidArgument;
import gov.anl.aps.dm.common.exceptions.ObjectNotFound;
import gov.anl.aps.dm.common.objects.DmObjectFactory;
import gov.anl.aps.dm.common.objects.Experiment;
import gov.anl.aps.dm.common.utilities.ArgumentUtility;
import java.util.HashMap;
/**
*
* @author sveseli
*/
public class ExperimentDsApi extends DmRestApi {
/**
* Constructor.
*
* @throws ConfigurationError if web service URL property is malformed or
* null
*/
public ExperimentDsApi() throws ConfigurationError {
super();
}
/**
* Constructor.
*
* @param webServiceUrl web service URL
* @throws ConfigurationError if web service URL is malformed or null
*/
public ExperimentDsApi(String webServiceUrl) throws ConfigurationError {
super(webServiceUrl);
}
/**
* Update experiment (group users, etc.).
*
* @param experimentName experiment name
* @return Experiment object
* @throws InvalidArgument if provided name is empty or null
* @throws ObjectNotFound when specified experiment does not exist
* @throws DmException in case of all other errors
*/
public Experiment updateExperiment(String experimentName) throws InvalidArgument, ObjectNotFound, DmException {
ArgumentUtility.verifyNonEmptyString("Experiment name", experimentName);
String requestUrl = "/experiments/update";
HashMap<String, String> requestData = new HashMap<>();
requestData.put("name", ArgumentUtility.encode(experimentName));
String jsonString = invokeSessionPutRequest(requestUrl, requestData);
Experiment experiment = (Experiment) DmObjectFactory.createDmObject(jsonString, Experiment.class);
return experiment;
}
/*
* Main method, used for simple testing.
*
* @param args main arguments
*/
public static void main(String[] args) {
try {
ExperimentDsApi client = new ExperimentDsApi("https://dmstorage.svdev.net:22236/dm");
client.login("dm", "dm");
Experiment experiment = client.updateExperiment("e1");
System.out.println("Updated experiment: \n" + experiment);
} catch (DmException ex) {
System.out.println("Sorry: " + ex);
}
}
}
......@@ -19,9 +19,8 @@ public class DmStatus {
public static final int DM_INVALID_REQUEST = 11;
public static final int DM_INVALID_SESSION = 12;
public static final int DM_COMMAND_FAILED = 13;
public static final int DM_OBJECT_ALREADY_EXISTS = 14;
public static final int DM_OBJECT_NOT_FOUND = 15;
public static final int DM_OBJECT_NOT_FOUND = 14;
public static final int DM_OBJECT_ALREADY_EXISTS = 15;
public static final int DM_INVALID_OBJECT_STATE = 16;
public static final int DM_IMAGE_PROCESSING_FAILED = 17;
public static final int DM_EXTERNAL_SERVICE_ERROR = 18;
public static final int DM_FILE_PROCESSING_ERROR = 17;
}
......@@ -35,12 +35,21 @@ public class DmExceptionFactory {
case DmStatus.DM_COMMUNICATION_ERROR:
exc = new CommunicationError();
break;
case DmStatus.DM_CONFIGURATION_ERROR:
exc = new ConfigurationError();
break;
case DmStatus.DM_INTERNAL_ERROR:
exc = new InternalError();
break;
case DmStatus.DM_DB_ERROR:
exc = new DbError();
break;
case DmStatus.DM_INVALID_ARGUMENT:
exc = new InvalidArgument();
break;
case DmStatus.DM_INVALID_REQUEST:
exc = new InvalidRequest();
break;
case DmStatus.DM_INVALID_SESSION:
exc = new InvalidSession();
break;
......@@ -50,6 +59,12 @@ public class DmExceptionFactory {
case DmStatus.DM_OBJECT_NOT_FOUND:
exc = new ObjectNotFound();
break;
case DmStatus.DM_INVALID_OBJECT_STATE:
exc = new InvalidObjectState();
break;
case DmStatus.DM_TIMEOUT_ERROR:
exc = new TimeoutError();
break;
default:
exc = (DmException) Class.forName(fullType).newInstance();
}
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package gov.anl.aps.dm.common.objects;
/**
* Experiment class.
*/
public class Experiment extends DmObject {
public Experiment() {
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment