Search in sources :

Example 11 with RepositoryObject

use of org.structr.net.repository.RepositoryObject in project structr by structr.

the class History method onMessage.

@Override
public void onMessage(Peer peer, PeerInfo sender) {
    if (peer.getUuid().equals(recipient)) {
        final Repository repository = peer.getRepository();
        if (!repository.contains(objectId)) {
            repository.objectCreated(objectId, type, getSender(), userId, creationTime, lastModified, data);
        } else {
            // store history
            final RepositoryObject obj = repository.getObject(objectId);
            if (obj != null) {
                final String transactionId = UUID.randomUUID().toString().replaceAll("\\-", "");
                for (final Entry<String, Object> entry : data.entrySet()) {
                    obj.setProperty(lastModified, transactionId, entry.getKey(), entry.getValue());
                }
                repository.complete(transactionId);
            }
        }
    }
}
Also used : Repository(org.structr.net.repository.Repository) RepositoryObject(org.structr.net.repository.RepositoryObject) RepositoryObject(org.structr.net.repository.RepositoryObject)

Example 12 with RepositoryObject

use of org.structr.net.repository.RepositoryObject in project structr by structr.

the class Inventory method onMessage.

@Override
public void onMessage(Peer peer, PeerInfo sender) {
    if (!peer.getUuid().equals(getSender())) {
        final RepositoryObject obj = peer.getRepository().getObject(objectId);
        if (obj == null || obj.getLastModificationTime().before(lastModificationDate)) {
            peer.log("GetHistory(", objectId, ")");
            peer.broadcast(new GetHistory(peer.getUuid(), getSender(), objectId, PseudoTime.now(peer)));
        }
    }
}
Also used : RepositoryObject(org.structr.net.repository.RepositoryObject)

Example 13 with RepositoryObject

use of org.structr.net.repository.RepositoryObject in project structr by structr.

the class PeerToPeerService method onCreate.

@Override
public void onCreate(final RepositoryObject object, final Map<String, Object> data) {
    logger.info("New object with UUID {} created in repository", object.getUuid());
    final ConfigurationProvider config = StructrApp.getConfiguration();
    final Class type = config.getNodeEntityClass(object.getType());
    if (type != null) {
        final App app = StructrApp.getInstance(getUserContext(object));
        try (final Tx tx = app.tx()) {
            // create new node
            final SharedNodeInterface newNode = app.create(type, new NodeAttribute<>(GraphObject.id, object.getUuid()), new NodeAttribute<>(SharedNodeInterface.lastModifiedPseudoTime, object.getLastModificationTime().toString()), new NodeAttribute<>(SharedNodeInterface.createdPseudoTime, object.getCreationTime().toString()));
            // store data
            for (final Entry<String, Object> entry : data.entrySet()) {
                final PropertyKey key = StructrApp.key(type, entry.getKey());
                if (key != null) {
                    newNode.setProperty(app, key, entry.getValue());
                }
            }
            // add listener to store future updates
            object.addListener(new ObjectUpdater(object.getUuid()));
            tx.success();
        } catch (FrameworkException fex) {
            logger.warn("", fex);
        }
    } else {
        System.out.println("Type " + object.getType() + " not found, NOT creating object with ID " + object.getUuid());
    }
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) ConfigurationProvider(org.structr.schema.ConfigurationProvider) RepositoryObject(org.structr.net.repository.RepositoryObject) GraphObject(org.structr.core.GraphObject) PropertyKey(org.structr.core.property.PropertyKey)

Example 14 with RepositoryObject

use of org.structr.net.repository.RepositoryObject in project structr by structr.

the class PeerToPeerService method addObjectToRepository.

public void addObjectToRepository(final SharedNodeInterface node) {
    final String objectId = node.getProperty(GraphObject.id);
    final String objectType = node.getProperty(GraphObject.type);
    final PseudoTime modified = node.getLastModificationPseudoTime();
    final PseudoTime created = node.getCreationPseudoTime();
    final String transactionId = NodeServiceCommand.getNextUuid();
    final RepositoryObject obj = repository.add(objectId, objectType, peer.getUuid(), node.getUserId(), created);
    for (final Entry<String, Object> entry : node.getData().entrySet()) {
        obj.setProperty(modified, transactionId, entry.getKey(), entry.getValue());
    }
    repository.complete(transactionId);
    // add update listener
    obj.addListener(new ObjectUpdater(objectId));
}
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)

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