use of nl.uva.cs.lobcder.resources.LogicalData in project lobcder by skoulouzis.
the class JDBCatalogue method copyFile.
public void copyFile(LogicalData toCopy, LogicalData newParent, String newName, MyPrincipal principal, Connection connection) throws SQLException {
try {
Permissions toCopyPerm = getPermissions(toCopy.getUid(), toCopy.getOwner(), connection);
Permissions newParentPerm = getPermissions(newParent.getUid(), newParent.getOwner(), connection);
Permissions permissionsForNew = new Permissions(principal, newParentPerm);
if (!toCopy.isFolder() && principal.canRead(toCopyPerm) && principal.canWrite(newParentPerm)) {
LogicalData newFileEntry = toCopy.clone();
newFileEntry.setUid(Long.valueOf(0));
newFileEntry.setOwner(principal.getUserId());
newFileEntry.setName(newName);
newFileEntry.setParentRef(newParent.getUid());
newFileEntry.setCreateDate(System.currentTimeMillis());
newFileEntry.setModifiedDate(System.currentTimeMillis());
newFileEntry = registerLogicalData(newFileEntry, connection);
setPermissions(newFileEntry.getUid(), permissionsForNew, connection);
try (Statement s = connection.createStatement()) {
s.executeUpdate("UPDATE pdrigroup_table SET refCount=refCount+1 WHERE pdriGroupId = " + newFileEntry.getPdriGroupId());
}
}
} catch (CloneNotSupportedException cns) {
throw new RuntimeException(cns);
}
}
use of nl.uva.cs.lobcder.resources.LogicalData in project lobcder by skoulouzis.
the class GraphPopulator method run.
@Override
public void run() {
try (Connection connection = datasource.getConnection()) {
LogicalData root = getLogicalDataByUid(Long.valueOf(1), connection);
ArrayList<Path> nodes = getNodes(Path.root, root, connection, null);
// String msg = "";
// for (Path d : nodes) {
// msg += d + "\n";
// }
// log.log(Level.INFO, "Nodes: {0}", msg);
Graph graph = populateGraph(nodes);
ArrayList<Vertex> transitions = getTransitions(connection, nodes);
graph = addEdges(graph, transitions);
this.graph = graph;
} catch (MalformedURLException | SQLException ex) {
Logger.getLogger(GraphPopulator.class.getName()).log(Level.SEVERE, null, ex);
}
}
use of nl.uva.cs.lobcder.resources.LogicalData in project lobcder by skoulouzis.
the class GraphPopulator method getChildrenByParentRef.
public Collection<LogicalData> getChildrenByParentRef(Long parentRef, @Nonnull Connection connection) throws SQLException {
try (PreparedStatement preparedStatement = connection.prepareStatement("SELECT uid, ownerId, datatype, ldName, createDate, modifiedDate, ldLength, " + "contentTypesStr, pdriGroupRef, isSupervised, checksum, lastValidationDate, " + "lockTokenID, lockScope, lockType, lockedByUser, lockDepth, lockTimeout, " + "description, locationPreference " + "FROM ldata_table WHERE ldata_table.parentRef = ?")) {
preparedStatement.setLong(1, parentRef);
ResultSet rs = preparedStatement.executeQuery();
LinkedList<LogicalData> res = new LinkedList<>();
while (rs.next()) {
LogicalData element = new LogicalData();
element.setUid(rs.getLong(1));
element.setParentRef(parentRef);
element.setOwner(rs.getString(2));
element.setType(rs.getString(3));
element.setName(rs.getString(4));
element.setCreateDate(rs.getTimestamp(5).getTime());
element.setModifiedDate(rs.getTimestamp(6).getTime());
element.setLength(rs.getLong(7));
element.setContentTypesAsString(rs.getString(8));
element.setPdriGroupId(rs.getLong(9));
element.setSupervised(rs.getBoolean(10));
element.setChecksum(rs.getString(11));
element.setLastValidationDate(rs.getLong(12));
element.setLockTokenID(rs.getString(13));
element.setLockScope(rs.getString(14));
element.setLockType(rs.getString(15));
element.setLockedByUser(rs.getString(16));
element.setLockDepth(rs.getString(17));
element.setLockTimeout(rs.getLong(18));
element.setDescription(rs.getString(19));
// element.setDataLocationPreference(rs.getString(20));
res.add(element);
}
return res;
}
}
use of nl.uva.cs.lobcder.resources.LogicalData in project lobcder by skoulouzis.
the class LDClustering method buildOrUpdateDataset.
private void buildOrUpdateDataset() throws SQLException, Exception {
if (type.equals(method)) {
getMethodInstances(Method.HEAD);
// addFeatures(connection, i, res.getUid());
} else {
try (Connection connection = getConnection()) {
try (PreparedStatement ps = connection.prepareStatement("SELECT uid, parentRef, ownerId, datatype, ldName, " + "createDate, modifiedDate, ldLength, contentTypesStr, pdriGroupRef, " + "isSupervised, checksum, lastValidationDate, lockTokenID, lockScope, " + "lockType, lockedByUser, lockDepth, lockTimeout, description, locationPreference, status " + "FROM ldata_table")) {
ResultSet rs = ps.executeQuery();
while (rs.next()) {
LogicalData res = new LogicalData();
res.setUid(rs.getLong(1));
res.setParentRef(rs.getLong(2));
res.setOwner(rs.getString(3));
res.setType(rs.getString(4));
res.setName(rs.getString(5));
res.setCreateDate(rs.getTimestamp(6).getTime());
res.setModifiedDate(rs.getTimestamp(7).getTime());
res.setLength(rs.getLong(8));
res.setContentTypesAsString(rs.getString(9));
res.setPdriGroupId(rs.getLong(10));
res.setSupervised(rs.getBoolean(11));
res.setChecksum(rs.getString(12));
res.setLastValidationDate(rs.getLong(13));
res.setLockTokenID(rs.getString(14));
res.setLockScope(rs.getString(15));
res.setLockType(rs.getString(16));
res.setLockedByUser(rs.getString(17));
res.setLockDepth(rs.getString(18));
res.setLockTimeout(rs.getLong(19));
res.setDescription(rs.getString(20));
// res.setDataLocationPreference(rs.getString(21));
res.setStatus(rs.getString(22));
ArrayList<MyInstance> ins = getInstances(res, null);
for (MyInstance i : ins) {
addFeatures(connection, i, res.getUid());
}
}
}
}
}
}
use of nl.uva.cs.lobcder.resources.LogicalData in project lobcder by skoulouzis.
the class LDClustering method getNextState.
@Override
public Vertex getNextState(Vertex currentState) {
ArrayList<Vertex> states = new ArrayList<>();
String rName = currentState.getResourceName();
if (!rName.endsWith("/")) {
rName += "/";
}
rName = rName.replaceFirst("/lobcder/dav/", "");
try (Connection connection = getConnection()) {
LogicalData data = getLogicalDataByPath(Path.path(rName), connection);
Instance instance = getInstances(data, currentState.getMethod()).get(0);
double[] features = instance.toDoubleArray();
switch(type) {
case state:
return getNextLobState(connection, features);
case resource:
return getNextResourceState(connection, features);
case method:
return getNextMethodState(connection, features);
default:
return getNextLobState(connection, features);
}
} catch (SQLException ex) {
Logger.getLogger(LDClustering.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
Aggregations