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