Search in sources :

Example 1 with ModificationEvent

use of org.structr.core.graph.ModificationEvent in project structr by structr.

the class File method triggerMinificationIfNeeded.

static void triggerMinificationIfNeeded(final File thisFile, final ModificationQueue modificationQueue) throws FrameworkException {
    final List<AbstractMinifiedFile> targets = thisFile.getMinificationTargets();
    final PropertyKey<Integer> versionKey = StructrApp.key(File.class, "version");
    if (!targets.isEmpty()) {
        // only run minification if the file version changed
        boolean versionChanged = false;
        for (ModificationEvent modState : modificationQueue.getModificationEvents()) {
            if (getUuid().equals(modState.getUuid())) {
                versionChanged = versionChanged || modState.getRemovedProperties().containsKey(versionKey) || modState.getModifiedProperties().containsKey(versionKey) || modState.getNewProperties().containsKey(versionKey);
            }
        }
        if (versionChanged) {
            for (AbstractMinifiedFile minifiedFile : targets) {
                try {
                    minifiedFile.minify();
                } catch (IOException ex) {
                    logger.warn("Could not automatically update minification target: ".concat(minifiedFile.getName()), ex);
                }
            }
        }
    }
}
Also used : ModificationEvent(org.structr.core.graph.ModificationEvent) IOException(java.io.IOException)

Example 2 with ModificationEvent

use of org.structr.core.graph.ModificationEvent in project structr by structr.

the class AbstractMinifiedFile method onModification.

static void onModification(final AbstractMinifiedFile thisFile, final SecurityContext securityContext, final ErrorBuffer errorBuffer, final ModificationQueue modificationQueue) throws FrameworkException {
    boolean shouldMinify = false;
    final String myUUID = thisFile.getUuid();
    for (ModificationEvent modState : modificationQueue.getModificationEvents()) {
        // only take changes on this exact file into account
        if (myUUID.equals(modState.getUuid())) {
            shouldMinify = shouldMinify || thisFile.shouldModificationTriggerMinifcation(modState);
        }
    }
    if (shouldMinify) {
        try {
            thisFile.minify();
        } catch (IOException ex) {
            logger.warn("Could not automatically minify file", ex);
        }
    }
}
Also used : ModificationEvent(org.structr.core.graph.ModificationEvent) IOException(java.io.IOException)

Example 3 with ModificationEvent

use of org.structr.core.graph.ModificationEvent in project structr by structr.

the class SyncTransmission method doRemote.

@Override
public Boolean doRemote(final CloudConnection client) throws IOException, FrameworkException {
    int count = 0;
    try (final Tx tx = StructrApp.getInstance().tx()) {
        for (final ModificationEvent event : transaction) {
            final GraphObject graphObject = event.getGraphObject();
            if (event.isDeleted()) {
                final String id = event.getRemovedProperties().get(GraphObject.id);
                if (id != null) {
                    client.send(new Delete(id));
                }
            } else {
                try {
                    final Set<String> propertyKeys = new LinkedHashSet<>();
                    // collect all possibly modified property keys
                    mapPropertyKeysToStrings(propertyKeys, event.getNewProperties().keySet());
                    mapPropertyKeysToStrings(propertyKeys, event.getModifiedProperties().keySet());
                    mapPropertyKeysToStrings(propertyKeys, event.getRemovedProperties().keySet());
                    if (graphObject.isNode()) {
                        if (graphObject instanceof File) {
                            sendFile(client, (File) graphObject, CloudService.CHUNK_SIZE);
                        } else {
                            client.send(new NodeDataContainer(graphObject.getSyncNode(), count, propertyKeys));
                        }
                    } else {
                        client.send(new RelationshipDataContainer(graphObject.getSyncRelationship(), count, propertyKeys));
                    }
                } catch (NotFoundException nfex) {
                    logger.info("Trying to synchronize deleted entity, ignoring");
                }
            }
            count++;
        }
        tx.success();
    }
    // synchronize last sync timestamp with slave instance
    // (we're sending out own instance ID (master) for the slave to store)
    final String masterId = StructrApp.getInstance().getInstanceId();
    client.send(new ReplicationStatus(masterId, StructrApp.getInstance().getGlobalSetting(masterId + ".lastModified", 0L)));
    // wait for end of transmission
    client.waitForTransmission();
    return true;
}
Also used : Delete(org.structr.cloud.message.Delete) LinkedHashSet(java.util.LinkedHashSet) Tx(org.structr.core.graph.Tx) FileNodeDataContainer(org.structr.cloud.message.FileNodeDataContainer) NodeDataContainer(org.structr.cloud.message.NodeDataContainer) NotFoundException(org.structr.api.NotFoundException) GraphObject(org.structr.core.GraphObject) RelationshipDataContainer(org.structr.cloud.message.RelationshipDataContainer) ModificationEvent(org.structr.core.graph.ModificationEvent) File(org.structr.dynamic.File)

Aggregations

ModificationEvent (org.structr.core.graph.ModificationEvent)3 IOException (java.io.IOException)2 LinkedHashSet (java.util.LinkedHashSet)1 NotFoundException (org.structr.api.NotFoundException)1 Delete (org.structr.cloud.message.Delete)1 FileNodeDataContainer (org.structr.cloud.message.FileNodeDataContainer)1 NodeDataContainer (org.structr.cloud.message.NodeDataContainer)1 RelationshipDataContainer (org.structr.cloud.message.RelationshipDataContainer)1 GraphObject (org.structr.core.GraphObject)1 Tx (org.structr.core.graph.Tx)1 File (org.structr.dynamic.File)1