use of org.structr.net.repository.RepositoryObject in project structr by structr.
the class Peer method getContentHash.
public byte[] getContentHash() {
MessageDigest digest = null;
try {
digest = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException nex) {
logger.warn("", nex);
}
if (digest != null) {
final long t0 = System.currentTimeMillis();
final List<RepositoryObject> objects = new LinkedList<>(repository.getObjects());
Collections.sort(objects, new UuidComparator());
for (final RepositoryObject node : objects) {
final String uuid = node.getUuid();
final String type = node.getType();
final String last = node.getLastModificationTime().toString();
digest.update(uuid.getBytes(utf8));
digest.update(type.getBytes(utf8));
digest.update(last.getBytes(utf8));
}
final long t1 = System.currentTimeMillis();
if ((t1 - t0) > 100) {
System.out.println("Creation of content hash took " + (System.currentTimeMillis() - t0) + " ms!");
}
return digest.digest();
} else {
System.out.println("Cannot create hash value, algorithms not available.");
}
return new byte[0];
}
use of org.structr.net.repository.RepositoryObject in project structr by structr.
the class GetHistory method onMessage.
@Override
public void onMessage(Peer peer, PeerInfo sender) {
if (peer.getUuid().equals(recipient)) {
final RepositoryObject obj = peer.getRepository().getObject(objectId);
if (obj != null) {
final PseudoTime lastModified = obj.getLastModificationTime();
if (lastModified.before(instant)) {
final Map<String, Object> data = obj.getProperties(instant);
peer.log("History(", objectId, ")");
peer.broadcast(new History(peer.getUuid(), getSender(), objectId, obj.getType(), obj.getUserId(), obj.getCreationTime(), lastModified, data));
} else {
peer.log("GetHistory(", objectId, "): not modified");
}
} else {
peer.log("GetHistory(", objectId, "): object not found");
}
}
}
use of org.structr.net.repository.RepositoryObject in project structr by structr.
the class Update method onMessage.
@Override
public void onMessage(final Peer peer, final PeerInfo sender) {
final Repository repository = peer.getRepository();
final RepositoryObject obj = repository.getObject(objectId);
if (obj != null) {
repository.update(obj, type, objectId, userId, lastModified, data);
} else {
repository.objectCreated(objectId, type, getSender(), userId, created, lastModified, data);
}
}
use of org.structr.net.repository.RepositoryObject in project structr by structr.
the class PeerToPeerService method update.
public void update(final SharedNodeInterface sharedNode) {
final RepositoryObject obj = repository.getObject(sharedNode.getUuid());
if (obj != null) {
final PseudoTime time = sharedNode.getLastModificationPseudoTime();
final Map<String, Object> data = sharedNode.getData();
final String type = sharedNode.getType();
final String user = sharedNode.getUserId();
logger.info("Shared node with UUID {} UPDATED in Structr at {}", new Object[] { sharedNode.getUuid(), time.toString() });
repository.update(obj, type, peer.getUuid(), user, time, data);
}
}
use of org.structr.net.repository.RepositoryObject in project structr by structr.
the class PeerToPeerService method setProperty.
public void setProperty(final String uuid, final String key, final Object value) throws FrameworkException {
logger.info("Attempting to modify shared node with UUID {}: {} = {} in Structr", new Object[] { uuid, key, value });
final RepositoryObject sharedObject = repository.getObject(uuid);
if (sharedObject != null) {
try (final RemoteTransaction tx = peer.beginTx(sharedObject)) {
tx.setProperty(sharedObject, key, value);
tx.commit();
} catch (Exception ex) {
System.out.println("timeout");
throw new FrameworkException(500, ex.getMessage());
}
} else {
System.out.println("No such object " + uuid);
}
}
Aggregations