use of nl.uva.cs.lobcder.resources.LogicalData in project lobcder by skoulouzis.
the class GraphPopulator method getLogicalDataByUid.
public LogicalData getLogicalDataByUid(Long UID, @Nonnull Connection connection) throws SQLException {
try (PreparedStatement ps = connection.prepareStatement("SELECT parentRef, ownerId, datatype, ldName, " + "createDate, modifiedDate, ldLength, contentTypesStr, pdriGroupRef, " + "isSupervised, checksum, lastValidationDate, lockTokenID, lockScope, " + "lockType, lockedByUser, lockDepth, lockTimeout, description, locationPreference, status " + "FROM ldata_table WHERE ldata_table.uid = ?")) {
ps.setLong(1, UID);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
LogicalData res = new LogicalData();
res.setUid(UID);
res.setParentRef(rs.getLong(1));
res.setOwner(rs.getString(2));
res.setType(rs.getString(3));
res.setName(rs.getString(4));
res.setCreateDate(rs.getTimestamp(5).getTime());
res.setModifiedDate(rs.getTimestamp(6).getTime());
res.setLength(rs.getLong(7));
res.setContentTypesAsString(rs.getString(8));
res.setPdriGroupId(rs.getLong(9));
res.setSupervised(rs.getBoolean(10));
res.setChecksum(rs.getString(11));
res.setLastValidationDate(rs.getLong(12));
res.setLockTokenID(rs.getString(13));
res.setLockScope(rs.getString(14));
res.setLockType(rs.getString(15));
res.setLockedByUser(rs.getString(16));
res.setLockDepth(rs.getString(17));
res.setLockTimeout(rs.getLong(18));
res.setDescription(rs.getString(19));
// res.setDataLocationPreference(rs.getString(20));
res.setStatus(rs.getString(21));
return res;
} else {
return null;
}
}
}
use of nl.uva.cs.lobcder.resources.LogicalData in project lobcder by skoulouzis.
the class DRIDataResource method setSupervised.
/**
* Sets supervised flag for a resource.
*
* @param uid the resource's id
* @param flag the flag
*/
@Path("{uid}/supervised/{flag}/")
@PUT
public void setSupervised(@PathParam("uid") Long uid, @PathParam("flag") Boolean flag) {
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.setLogicalDataSupervised(uid, flag, 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 getSupervised.
/**
* Gets supervised flag for a resource.
*
* @param uid the resource's id
* @return the supervised flag for a resource.
*/
@Path("{uid}/supervised/")
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public JAXBElement<Boolean> getSupervised(@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<Boolean>(new QName("supervised"), Boolean.class, res.getSupervised());
} 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 setChecksum.
/**
* Sets checksum property for an item
*
* @param uid the resource's id
* @param checksum the checksum. This value is not check if it's correct by
* lobcder
*/
@Path("{uid}/checksum/{checksum}/")
@PUT
public void setChecksum(@PathParam("uid") Long uid, @PathParam("checksum") String checksum) {
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.setFileChecksum(uid, checksum, 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 WebDataDirResource method createAndLock.
/**
* This means to just lock the name Not to create the resource.
*
* @param name
* @param timeout
* @param lockInfo
* @return
* @throws NotAuthorizedException
*/
@Override
public LockToken createAndLock(String name, LockTimeout timeout, LockInfo lockInfo) throws NotAuthorizedException {
try (Connection connection = getCatalogue().getConnection()) {
Path newPath = Path.path(getPath(), name);
// If the resource exists
LogicalData fileLogicalData = getCatalogue().getLogicalDataByPath(newPath, connection);
if (fileLogicalData != null) {
throw new PreConditionFailedException(new WebDataFileResource(fileLogicalData, Path.path(getPath(), name), getCatalogue(), authList));
}
LockToken lockToken = new LockToken(UUID.randomUUID().toString(), lockInfo, timeout);
return lockToken;
} catch (SQLException | PreConditionFailedException ex) {
Logger.getLogger(WebDataDirResource.class.getName()).log(Level.SEVERE, null, ex);
if (ex instanceof PreConditionFailedException) {
throw new RuntimeException(ex);
}
} catch (UnsupportedEncodingException ex) {
Logger.getLogger(WebDataDirResource.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
Aggregations