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);
}
}
}
}
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)));
}
}
}
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());
}
}
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));
}
Aggregations