use of nl.uva.cs.lobcder.resources.LogicalData in project lobcder by skoulouzis.
the class JDBCatalogue method setLockDepth.
public void setLockDepth(Long uid, String lockDepth, Connection connection) throws SQLException {
try (PreparedStatement ps = connection.prepareStatement("UPDATE ldata_table SET lockDepth = ? WHERE uid = ?")) {
ps.setString(1, lockDepth);
ps.setLong(2, uid);
ps.executeUpdate();
}
LogicalData cached = getFromLDataCache(uid, null);
if (cached != null) {
cached.setLockDepth(lockDepth);
putToLDataCache(cached, null);
}
}
use of nl.uva.cs.lobcder.resources.LogicalData in project lobcder by skoulouzis.
the class JDBCatalogue method setLockTimeout.
public void setLockTimeout(Long uid, Long lockTimeout, Connection connection) throws SQLException {
try (PreparedStatement ps = connection.prepareStatement("UPDATE ldata_table SET lockTimeout = ? WHERE uid = ?")) {
ps.setLong(1, lockTimeout);
ps.setLong(2, uid);
ps.executeUpdate();
}
LogicalData cached = getFromLDataCache(uid, null);
if (cached != null) {
cached.setLockTimeout(lockTimeout);
putToLDataCache(cached, null);
}
}
use of nl.uva.cs.lobcder.resources.LogicalData in project lobcder by skoulouzis.
the class JDBCatalogue method setDescription.
/*
public LinkedList<LogicalData> queryLogicalData(MultivaluedMap<String, String> queryParameters, Connection connection) throws CatalogueException {
Statement s = null;
boolean connectionIsProvided = (connection == null) ? false : true;
boolean connectionAutocommit = false;
try {
if (connection == null) {
connection = getConnection();
connection.setAutoCommit(false);
} else {
connectionAutocommit = connection.getAutoCommit();
connection.setAutoCommit(false);
}
s = connection.createStatement();
boolean where = false;
StringBuilder query = new StringBuilder("SELECT uid, ownerId, datatype, "
+ "ld_name, parent, createDate, modifiedDate, ld_length, "
+ "contentTypesStr, pdriGroupId, isSupervised, checksum, "
+ "lastValidationDate, lockTokenID, lockScope, "
+ "lockType, lockedByUser, lockDepth, lockTimeout, description "
+ "FROM ldata_table");
if (queryParameters.containsKey("path") && queryParameters.get("path").iterator().hasNext()) {
String path = queryParameters.get("path").iterator().next();
if (!path.equals("/")) {
query.append(where ? " AND" : " WHERE").append(" parent LIKE '").append(path).append("%'");
where = true;
}
queryParameters.remove("path");
}
if (queryParameters.containsKey("mStartDate") && queryParameters.get("mStartDate").iterator().hasNext()
&& queryParameters.containsKey("mEndDate") && queryParameters.get("mEndDate").iterator().hasNext()) {
String mStartDate = Long.valueOf(queryParameters.get("mStartDate").iterator().next()).toString();
String mEndDate = Long.valueOf(queryParameters.get("mEndDate").iterator().next()).toString();
query.append(where ? " AND" : " WHERE").append(" modifiedDate BETWEEN FROM_UNIXTIME(").append(mStartDate).append(") AND FROM_UNIXTIME(").append(mEndDate).append(")");
where = true;
queryParameters.remove("mStartDate");
queryParameters.remove("mEndDate");
} else if (queryParameters.containsKey("mStartDate") && queryParameters.get("mStartDate").iterator().hasNext()) {
String mStartDate = Long.valueOf(queryParameters.get("mStartDate").iterator().next()).toString();
query.append(where ? " AND" : " WHERE").append(" modifiedDate >= UNIXTIME(").append(mStartDate).append(")");
where = true;
queryParameters.remove("mStartDate");
} else if (queryParameters.containsKey("mEndDate") && queryParameters.get("mEndDate").iterator().hasNext()) {
String mEndDate = Long.valueOf(queryParameters.get("mEndDate").iterator().next()).toString();
query.append(where ? " AND" : " WHERE").append(" modifiedDate <= UNIXTIME(").append(mEndDate).append(")");
where = true;
queryParameters.remove("mEndDate");
}
if (queryParameters.containsKey("isSupervised") && queryParameters.get("isSupervised").iterator().hasNext()) {
String isSupervised = Boolean.valueOf(queryParameters.get("isSupervised").iterator().next()).toString();
query.append(where ? " AND" : " WHERE").append(" isSupervised = ").append(isSupervised);
where = true;
queryParameters.remove("isSupervised");
}
JDBCatalogue.log.fine("queryLogicalData() SQL: " + query.toString());
ResultSet rs = s.executeQuery(query.toString());
LinkedList<LogicalData> ld_list = new LinkedList<LogicalData>();
while (rs.next()) {
LogicalData element = new LogicalData(this);
element.setUID(rs.getLong(1));
element.setOwner(rs.getString(2));
element.setType(rs.getString(3));
element.setName(rs.getString(4));
element.setParent(rs.getString(5));
element.setCreateDate(rs.getTimestamp(6).getTime());
element.setModifiedDate(rs.getTimestamp(7).getTime());
element.setLength(rs.getLong(8));
element.setContentTypesAsString(rs.getString(9));
element.setPdriGroupId(rs.getLong(10));
element.setSupervised(rs.getBoolean(11));
element.setChecksum(rs.getLong(12));
element.setLastValidationDate(rs.getLong(13));
// element.setLockTokenID(rs.getString(14));
// element.setLockScope(rs.getString(15));
// element.setLockType(rs.getString(16));
// element.setLockedByUser(rs.getString(17));
// element.setLockDepth(rs.getString(18));
// element.setLockTimeout(rs.getLong(19));
element.setDescription(rs.getString(14));
ld_list.add(element);
}
s.close();
return ld_list;
} catch (Exception e) {
try {
if (s != null && !s.isClosed()) {
s.close();
s = null;
}
if (!connectionIsProvided && !connection.isClosed()) {
connection.rollback();
connection.close();
}
} catch (SQLException ex) {
Logger.getLogger(JDBCatalogue.class.getName()).log(Level.SEVERE, null, ex);
}
throw new CatalogueException(e.getMessage());
} finally {
try {
if (s != null && !s.isClosed()) {
s.close();
}
if (!connectionIsProvided && !connection.isClosed()) {
connection.commit();
connection.close();
}
if (connectionIsProvided && !connection.isClosed()) {
connection.setAutoCommit(connectionAutocommit);
}
} catch (SQLException ex) {
Logger.getLogger(JDBCatalogue.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
*/
public void setDescription(Long uid, String description, Connection connection) throws SQLException {
try (PreparedStatement ps = connection.prepareStatement("UPDATE ldata_table SET description = ? WHERE uid = ?")) {
ps.setString(1, description);
ps.setLong(2, uid);
ps.executeUpdate();
}
LogicalData cached = getFromLDataCache(uid, null);
if (cached != null) {
cached.setDescription(description);
putToLDataCache(cached, null);
}
}
use of nl.uva.cs.lobcder.resources.LogicalData in project lobcder by skoulouzis.
the class JDBCatalogue method setLockByUser.
public void setLockByUser(Long uid, String lockedByUser, Connection connection) throws SQLException {
try (PreparedStatement ps = connection.prepareStatement("UPDATE ldata_table SET lockedByUser = ? WHERE uid = ?")) {
ps.setString(1, lockedByUser);
ps.setLong(2, uid);
ps.executeUpdate();
}
LogicalData cached = getFromLDataCache(uid, null);
if (cached != null) {
cached.setLockedByUser(lockedByUser);
putToLDataCache(cached, null);
}
}
use of nl.uva.cs.lobcder.resources.LogicalData in project lobcder by skoulouzis.
the class Archive method getZip.
/**
* Generates a zip archive of folder
*
* @param path the folder name
* @return the stream of the archive
*/
@GET
@Path("/getzip/{name:.+}")
public Response getZip(@PathParam("name") String path) {
class Folder {
private String path;
private LogicalData logicalData;
private Folder(String path, LogicalData logicalData) {
this.path = path;
this.logicalData = logicalData;
}
/**
* @return the path
*/
public String getPath() {
return path;
}
/**
* @param path the path to set
*/
public void setPath(String path) {
this.path = path;
}
/**
* @return the logicalData
*/
public LogicalData getLogicalData() {
return logicalData;
}
/**
* @param logicalData the logicalData to set
*/
public void setLogicalData(LogicalData logicalData) {
this.logicalData = logicalData;
}
}
final String rootPath;
if (path.endsWith("/")) {
rootPath = path.substring(0, path.length() - 1);
} else {
rootPath = path;
}
int index = rootPath.lastIndexOf('/');
final String rootName;
if (index != -1) {
rootName = rootPath.substring(index + 1);
} else {
rootName = rootPath;
}
if (rootName.isEmpty()) {
throw new WebApplicationException(Response.Status.NOT_ACCEPTABLE);
}
final MyPrincipal principal = (MyPrincipal) request.getAttribute("myprincipal");
final JDBCatalogue catalogue = getCatalogue();
StreamingOutput result = new StreamingOutput() {
@Override
public void write(OutputStream out) throws IOException, WebApplicationException {
Stack<Folder> folders;
try (Connection connection = catalogue.getConnection()) {
LogicalData rootElement = catalogue.getLogicalDataByPath(io.milton.common.Path.path(rootPath), connection);
if (rootElement == null) {
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
try (ZipOutputStream zip = new ZipOutputStream(out)) {
ZipEntry ze;
folders = new Stack<>();
Permissions p = catalogue.getPermissions(rootElement.getUid(), rootElement.getOwner(), connection);
if (principal.canRead(p)) {
if (rootElement.isFolder()) {
folders.add(new Folder(rootName, rootElement));
} else {
ze = new ZipEntry(rootName);
zip.putNextEntry(ze);
List<PDRIDescr> pdris = catalogue.getPdriDescrByGroupId(rootElement.getPdriGroupId());
copyStream(pdris, zip);
zip.closeEntry();
getCatalogue().addViewForRes(rootElement.getUid());
}
}
while (!folders.isEmpty()) {
Folder folder = folders.pop();
ze = new ZipEntry(folder.getPath() + "/");
ze.setTime(folder.getLogicalData().getModifiedDate());
zip.putNextEntry(ze);
getCatalogue().addViewForRes(folder.getLogicalData().getUid());
for (LogicalData ld : catalogue.getChildrenByParentRef(folder.getLogicalData().getUid(), connection)) {
Permissions entry_p = catalogue.getPermissions(ld.getUid(), ld.getOwner(), connection);
if (principal.canRead(entry_p)) {
if (ld.isFolder()) {
folders.push(new Folder(folder.getPath() + "/" + ld.getName(), ld));
} else {
ze = new ZipEntry(folder.getPath() + "/" + ld.getName());
ze.setTime(ld.getModifiedDate());
zip.putNextEntry(ze);
copyStream(catalogue.getPdriDescrByGroupId(ld.getPdriGroupId()), zip);
zip.closeEntry();
getCatalogue().addViewForRes(ld.getUid());
}
}
}
}
}
} catch (Exception e) {
if (e instanceof WebApplicationException) {
throw (WebApplicationException) e;
} else {
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
}
}
};
Response.ResponseBuilder response = Response.ok(result, "application/zip");
return response.header("Content-Disposition", "attachment; filename=" + rootName + ".zip").build();
}
Aggregations