Search in sources :

Example 1 with RepositoryObject

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];
}
Also used : RepositoryObject(org.structr.net.repository.RepositoryObject) DefaultRepositoryObject(org.structr.net.repository.DefaultRepositoryObject) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageDigest(java.security.MessageDigest) LinkedList(java.util.LinkedList)

Example 2 with RepositoryObject

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");
        }
    }
}
Also used : PseudoTime(org.structr.net.data.time.PseudoTime) RepositoryObject(org.structr.net.repository.RepositoryObject) RepositoryObject(org.structr.net.repository.RepositoryObject)

Example 3 with RepositoryObject

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);
    }
}
Also used : Repository(org.structr.net.repository.Repository) RepositoryObject(org.structr.net.repository.RepositoryObject)

Example 4 with RepositoryObject

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);
    }
}
Also used : PseudoTime(org.structr.net.data.time.PseudoTime) RepositoryObject(org.structr.net.repository.RepositoryObject) RepositoryObject(org.structr.net.repository.RepositoryObject) GraphObject(org.structr.core.GraphObject)

Example 5 with RepositoryObject

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);
    }
}
Also used : RemoteTransaction(org.structr.net.data.RemoteTransaction) RepositoryObject(org.structr.net.repository.RepositoryObject) FrameworkException(org.structr.common.error.FrameworkException) FrameworkException(org.structr.common.error.FrameworkException) IOException(java.io.IOException)

Aggregations

RepositoryObject (org.structr.net.repository.RepositoryObject)14 DefaultRepositoryObject (org.structr.net.repository.DefaultRepositoryObject)4 GraphObject (org.structr.core.GraphObject)3 PseudoTime (org.structr.net.data.time.PseudoTime)3 IOException (java.io.IOException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 FrameworkException (org.structr.common.error.FrameworkException)2 RemoteTransaction (org.structr.net.data.RemoteTransaction)2 Repository (org.structr.net.repository.Repository)2 MessageDigest (java.security.MessageDigest)1 LinkedList (java.util.LinkedList)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 App (org.structr.core.app.App)1 StructrApp (org.structr.core.app.StructrApp)1 Tx (org.structr.core.graph.Tx)1 PropertyKey (org.structr.core.property.PropertyKey)1 TimeoutException (org.structr.net.data.TimeoutException)1 Inventory (org.structr.net.protocol.Inventory)1 ConfigurationProvider (org.structr.schema.ConfigurationProvider)1