use of nl.uva.cs.lobcder.resources.LogicalData in project lobcder by skoulouzis.
the class DRIDataResource method getLastValidationDateDate.
/**
* Gets lastvalidationdate property for a resource in text format
*
* @param uid the resource's id
* @return the date last validated in text format
*/
@Path("{uid}/lastValidationDate/")
@GET
@Produces({ MediaType.TEXT_PLAIN, MediaType.TEXT_HTML })
public String getLastValidationDateDate(@PathParam("uid") Long uid) {
try (Connection cn = catalogue.getConnection()) {
LogicalData res = catalogue.getLogicalDataByUid(uid, cn);
if (res == null) {
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
Permissions p = catalogue.getPermissions(uid, res.getOwner(), cn);
if (!mp.canRead(p)) {
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
}
return new Date(res.getLastValidationDate() * 1000).toString();
} catch (SQLException ex) {
Logger.getLogger(DRIDataResource.class.getName()).log(Level.SEVERE, null, ex);
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
}
use of nl.uva.cs.lobcder.resources.LogicalData in project lobcder by skoulouzis.
the class DRIDataResource method setLastValidationDate.
/**
* Sets lastvalidationdate property for a resource
*
* @param uid the resource's id
* @param lastValidationDate the date last validated
*/
@Path("{uid}/lastValidationDate/{lastValidationDate}/")
@PUT
public void setLastValidationDate(@PathParam("uid") Long uid, @PathParam("lastValidationDate") Long lastValidationDate) {
try (Connection cn = catalogue.getConnection()) {
try {
LogicalData res = catalogue.getLogicalDataByUid(uid, cn);
if (res == null) {
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
Permissions p = catalogue.getPermissions(uid, res.getOwner(), cn);
if (!mp.canWrite(p)) {
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
}
catalogue.setLastValidationDate(uid, lastValidationDate, cn);
cn.commit();
} catch (SQLException ex) {
Logger.getLogger(DRIDataResource.class.getName()).log(Level.SEVERE, null, ex);
cn.rollback();
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
} catch (SQLException ex) {
Logger.getLogger(DRIDataResource.class.getName()).log(Level.SEVERE, null, ex);
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
}
use of nl.uva.cs.lobcder.resources.LogicalData in project lobcder by skoulouzis.
the class DRIDataResource method getLastValidationDate.
/**
* Gets lastvalidationdate property for a resource
*
* @param uid the resource's id
* @return the date last validated
*/
@Path("{uid}/lastValidationDate/")
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public JAXBElement<Long> getLastValidationDate(@PathParam("uid") Long uid) {
try (Connection cn = catalogue.getConnection()) {
LogicalData res = catalogue.getLogicalDataByUid(uid, cn);
if (res == null) {
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
Permissions p = catalogue.getPermissions(uid, res.getOwner(), cn);
if (!mp.canRead(p)) {
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
}
return new JAXBElement<Long>(new QName("lastValidationDate"), Long.class, res.getLastValidationDate());
} catch (SQLException ex) {
Logger.getLogger(DRIDataResource.class.getName()).log(Level.SEVERE, null, ex);
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
}
use of nl.uva.cs.lobcder.resources.LogicalData in project lobcder by skoulouzis.
the class DRIDataResource method getChecksum.
/**
* Gets checksum property for an item.
*
* @param uid the resource's id
* @return the checksum. This value is not check if it's correct by lobcder
*/
@Path("{uid}/checksum/")
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public JAXBElement<String> getChecksum(@PathParam("uid") Long uid) {
try (Connection cn = catalogue.getConnection()) {
LogicalData res = catalogue.getLogicalDataByUid(uid, cn);
if (res == null) {
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
Permissions p = catalogue.getPermissions(uid, res.getOwner(), cn);
if (!mp.canRead(p)) {
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
}
return new JAXBElement<String>(new QName("checksum"), String.class, res.getChecksum());
} catch (SQLException ex) {
Logger.getLogger(DRIDataResource.class.getName()).log(Level.SEVERE, null, ex);
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
}
use of nl.uva.cs.lobcder.resources.LogicalData in project lobcder by skoulouzis.
the class DRItemsResource method setSupervised.
/**
* Sets supervised flag for a resource.
*
* @param flag the flag
* @param path the resource's path
*/
@Path("supervised/{flag}")
@PUT
public void setSupervised(@PathParam("flag") Boolean flag, @QueryParam("path") String path) throws UnsupportedEncodingException {
try (Connection cn = catalogue.getConnection()) {
MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
if (mp.isAdmin()) {
try {
LogicalData logicalData;
if (path == null || path.isEmpty()) {
logicalData = catalogue.getLogicalDataByUid(1L, cn);
} else {
logicalData = catalogue.getLogicalDataByPath(io.milton.common.Path.path(path), cn);
}
catalogue.setLogicalDataSupervised(logicalData.getUid(), flag, cn);
if (logicalData.isFolder()) {
try (PreparedStatement ps1 = cn.prepareStatement("UPDATE ldata_table SET isSupervised=? WHERE parentRef = ?");
PreparedStatement ps2 = cn.prepareStatement("SELECT uid FROM ldata_table WHERE parentRef = ? AND datatype = '" + Constants.LOGICAL_FOLDER + "'")) {
setDirSupervised(logicalData.getUid(), flag, ps1, ps2);
}
}
cn.commit();
} catch (SQLException e) {
Logger.getLogger(DRItemsResource.class.getName()).log(Level.SEVERE, null, e);
cn.rollback();
}
} else {
Logger.getLogger(DRItemsResource.class.getName()).log(Level.WARNING, "NOT a superuser: want change DRI flag for {0}", path);
}
} catch (SQLException e) {
Logger.getLogger(DRItemsResource.class.getName()).log(Level.SEVERE, null, e);
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
}
Aggregations