Commit aab1919f authored by shake's avatar shake
Browse files

Restful services for irods settings

git-svn-id: https://subversion.umiacs.umd.edu/ace/trunk@211 f1b3a171-7291-4a19-a512-95ad0ad9394a
parent 4638fa5e
......@@ -216,11 +216,6 @@
<artifactId>irods-api</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.25</version>
</dependency>
<!--<dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>jackrabbit-core</artifactId>
......
......@@ -42,12 +42,15 @@ import javax.persistence.JoinColumn;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
/**
*
* @author toaster
*/
@Entity
@XmlRootElement
@Table(name = "irodssettings")
@NamedQuery(name = "IrodsSettings.getByCollection", query =
"SELECT i FROM IrodsSetting i WHERE i.collection = :coll")
......@@ -140,6 +143,7 @@ public class IrodsSetting implements Serializable {
this.collection = collection;
}
@XmlTransient
public Collection getCollection() {
return collection;
}
......
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.umiacs.ace.rest;
import com.sun.istack.logging.Logger;
import edu.umiacs.ace.driver.irods.IrodsSetting;
import edu.umiacs.ace.monitor.core.Collection;
import edu.umiacs.ace.util.PersistUtil;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.NoResultException;
import javax.persistence.Query;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
/**
*
* @author shake
*/
@Path("settings")
public class SettingsManagement {
private static final Logger LOG = Logger.getLogger(SettingsManagement.class);
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("irods/{collId}")
public Response iRODSModify(IrodsSetting is, @PathParam("collId") long collId) {
EntityManager em = PersistUtil.getEntityManager();
EntityTransaction trans = em.getTransaction();
trans.begin();
// check our collection first
Collection coll = em.find(Collection.class, collId);
if ( !coll.getStorage().equals("irods")) {
coll.setStorage("irods");
em.persist(coll);
}
Query q = em.createNamedQuery("IrodsSettings.getByCollection");
q.setParameter("coll", coll);
try {
// Make sure we aren't changing the collection
// and update the id just in case
IrodsSetting oldSetting = (IrodsSetting) q.getSingleResult();
if ( oldSetting.getCollection().getId() != collId ) {
return Response.notModified().build();
}
is.setId(oldSetting.getId());
} catch (NoResultException ex) {
LOG.info("Adding new irods settings for collection " + coll.getName());
} finally {
is.setCollection(coll);
em.merge(is);
trans.commit();
}
return Response.ok().build();
}
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("irods/{collId}")
public IrodsSetting getIRODSSettings(@PathParam("collId") long collId) {
EntityManager em = PersistUtil.getEntityManager();
Collection coll = em.find(Collection.class, collId);
Query q = em.createNamedQuery("IrodsSettings.getByCollection");
q.setParameter("coll", coll);
return (IrodsSetting) q.getSingleResult();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/ace-am-1.7.1-SNAPSHOT">
<Context path="/ace-am-1.8">
<Logger className="org.apache.catalina.logger.FileLogger" prefix="aceam." suffix=".log" timestamp="true"/>
<!-- Configuration for authentication. This information should not need to be
changed at all unless you have your own authentication provider-->
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment