use of org.structr.api.DatabaseService in project structr by structr.
the class SyncCommand method execute.
@Override
public void execute(final Map<String, Object> attributes) throws FrameworkException {
DatabaseService graphDb = Services.getInstance().getService(NodeService.class).getGraphDb();
String mode = (String) attributes.get("mode");
String fileName = (String) attributes.get("file");
String validate = (String) attributes.get("validate");
String query = (String) attributes.get("query");
Long batchSize = (Long) attributes.get("batchSize");
boolean doValidation = true;
// should we validate imported nodes?
if (validate != null) {
try {
doValidation = Boolean.valueOf(validate);
} catch (Throwable t) {
logger.warn("Unable to parse value for validation flag: {}", t.getMessage());
}
}
if (fileName == null) {
throw new FrameworkException(400, "Please specify sync file.");
}
if ("export".equals(mode)) {
exportToFile(graphDb, fileName, query, true);
} else if ("exportDb".equals(mode)) {
exportToFile(graphDb, fileName, query, false);
} else if ("import".equals(mode)) {
importFromFile(graphDb, securityContext, fileName, doValidation, batchSize);
} else {
throw new FrameworkException(400, "Please specify sync mode (import|export).");
}
}
use of org.structr.api.DatabaseService in project structr by structr.
the class TransactionCommand method beginTx.
public TransactionCommand beginTx() throws FrameworkException {
final DatabaseService graphDb = (DatabaseService) arguments.get("graphDb");
TransactionReference tx = transactions.get();
if (graphDb != null) {
if (tx == null) {
try {
// start new transaction
tx = new TransactionReference(graphDb.beginTx());
} catch (NetworkException nex) {
throw new DatabaseServiceNetworkException(503, nex.getMessage());
}
queues.set(new ModificationQueue());
buffers.set(new ErrorBuffer());
transactions.set(tx);
currentCommand.set(this);
}
// increase depth
tx.begin();
} else {
throw new DatabaseServiceNotAvailableException(503, "Database service is not available, ensure the database is running and that there is a working network connection to it");
}
return this;
}
use of org.structr.api.DatabaseService in project structr by structr.
the class DeleteRelationshipCommand method execute.
public Object execute(final RelationshipInterface rel, final boolean passiveDeletion) {
DatabaseService graphDb = (DatabaseService) arguments.get("graphDb");
if (graphDb != null && rel != null) {
if (rel.getProperty(AbstractRelationship.id) == null) {
logger.warn("Will not delete relationship which has no UUID: {} --[:{}]-->{}", new Object[] { rel.getSourceNode(), rel.getType(), rel.getTargetNode() });
return null;
}
final Relationship relToDelete = rel.getRelationship();
final RelationshipInterface finalRel = rel;
TransactionCommand.relationshipDeleted(securityContext.getCachedUser(), finalRel, passiveDeletion);
// callback
finalRel.onRelationshipDeletion();
// remove object from index
finalRel.removeFromIndex();
// delete node in database
relToDelete.delete();
}
return null;
}
use of org.structr.api.DatabaseService in project structr by structr.
the class FindRelationshipCommand method execute.
public T execute(String idString) throws FrameworkException {
DatabaseService graphDb = (DatabaseService) arguments.get("graphDb");
RelationshipFactory<T> relationshipFactory = new RelationshipFactory<>(securityContext);
if (graphDb != null) {
// single string value, try to parse to long
try {
return relationshipFactory.instantiate(graphDb.getRelationshipById(Long.parseLong(idString)));
} catch (NumberFormatException ex) {
// failed :(
logger.debug("Could not parse {} to number", idString);
}
}
return null;
}
use of org.structr.api.DatabaseService in project structr by structr.
the class FindRelationshipCommand method execute.
public T execute(Long id) throws FrameworkException {
DatabaseService graphDb = (DatabaseService) arguments.get("graphDb");
RelationshipFactory<T> relationshipFactory = new RelationshipFactory<>(securityContext);
if (graphDb != null) {
return relationshipFactory.instantiate(graphDb.getRelationshipById(id));
}
return null;
}
Aggregations