use of org.structr.common.error.ErrorBuffer in project structr by structr.
the class DeleteNodeCommand method doDeleteNode.
private void doDeleteNode(final NodeInterface node) {
if (TransactionCommand.isDeleted(node.getNode())) {
return;
}
try {
if (!deletedNodes.contains(node) && node.getUuid() == null) {
logger.warn("Will not delete node which has no UUID, dumping stack.");
Thread.dumpStack();
return;
}
} catch (java.lang.IllegalStateException ise) {
logger.warn("Trying to delete a node which is already deleted", ise.getMessage());
return;
} catch (org.structr.api.NotFoundException nfex) {
// exception can be ignored, node is already deleted
}
deletedNodes.add(node);
App app = StructrApp.getInstance(securityContext);
try {
List<NodeInterface> nodesToCheckAfterDeletion = new LinkedList<>();
// by relationships which are marked with DELETE_OUTGOING
for (AbstractRelationship rel : node.getOutgoingRelationships()) {
// deleted rels can be null..
if (rel != null) {
int cascadeDelete = rel.cascadeDelete();
NodeInterface endNode = rel.getTargetNode();
if ((cascadeDelete & Relation.CONSTRAINT_BASED) == Relation.CONSTRAINT_BASED) {
nodesToCheckAfterDeletion.add(endNode);
}
if (!deletedNodes.contains(endNode) && ((cascadeDelete & Relation.SOURCE_TO_TARGET) == Relation.SOURCE_TO_TARGET)) {
// remove end node from index
endNode.removeFromIndex();
doDeleteNode(endNode);
}
}
}
// by relationships which are marked with DELETE_INCOMING
for (AbstractRelationship rel : node.getIncomingRelationships()) {
// deleted rels can be null
if (rel != null) {
final int cascadeDelete = rel.cascadeDelete();
final NodeInterface startNode = rel.getSourceNode();
if ((cascadeDelete & Relation.CONSTRAINT_BASED) == Relation.CONSTRAINT_BASED) {
nodesToCheckAfterDeletion.add(startNode);
}
if (!deletedNodes.contains(startNode) && ((cascadeDelete & Relation.TARGET_TO_SOURCE) == Relation.TARGET_TO_SOURCE)) {
// remove start node from index
startNode.removeFromIndex();
doDeleteNode(startNode);
}
}
}
// deletion callback, must not prevent node deletion!
node.onNodeDeletion();
// Delete any relationship (this is PASSIVE DELETION)
for (AbstractRelationship r : node.getRelationships()) {
if (r != null) {
app.delete(r);
}
}
// still valid after node deletion
for (NodeInterface nodeToCheck : nodesToCheckAfterDeletion) {
ErrorBuffer errorBuffer = new ErrorBuffer();
if (!deletedNodes.contains(nodeToCheck) && !nodeToCheck.isValid(errorBuffer)) {
// remove end node from index
nodeToCheck.removeFromIndex();
doDeleteNode(nodeToCheck);
}
}
} catch (Throwable t) {
t.printStackTrace();
logger.warn("Exception while deleting node {}: {}", node, t.getMessage());
}
return;
}
use of org.structr.common.error.ErrorBuffer in project structr by structr.
the class Widget method expandWidget.
public static void expandWidget(final SecurityContext securityContext, final Page page, final DOMNode parent, final String baseUrl, final Map<String, Object> parameters, final boolean processDeploymentInfo) throws FrameworkException {
String _source = (String) parameters.get("source");
ErrorBuffer errorBuffer = new ErrorBuffer();
if (_source == null) {
errorBuffer.add(new EmptyPropertyToken(Widget.class.getSimpleName(), source));
} else {
// check source for mandatory parameters
Matcher matcher = threadLocalTemplateMatcher.get();
// initialize with source
matcher.reset(_source);
while (matcher.find()) {
final String group = matcher.group();
final String source = group.substring(1, group.length() - 1);
final ReplacementInfo info = new ReplacementInfo(source);
String key = info.getKey();
Object value = parameters.get(key);
if (value != null) {
// replace and restart matching process
_source = _source.replace(group, value.toString());
matcher.reset(_source);
}
}
}
if (!errorBuffer.hasError()) {
Importer importer = new Importer(securityContext, _source, baseUrl, null, false, false);
if (processDeploymentInfo) {
importer.setIsDeployment(true);
importer.setCommentHandler(new DeploymentCommentHandler());
}
importer.parse(true);
importer.createChildNodes(parent, page, true);
} else {
// report error to ui
throw new FrameworkException(422, "Unable to import the given source code", errorBuffer);
}
}
use of org.structr.common.error.ErrorBuffer in project structr by structr.
the class TypeResource method doPost.
@Override
public RestMethodResult doPost(final Map<String, Object> propertySet) throws FrameworkException {
// virtual type?
if (virtualType != null) {
virtualType.transformInput(securityContext, entityClass, propertySet);
}
if (isNode) {
final RestMethodResult result = new RestMethodResult(HttpServletResponse.SC_CREATED);
final NodeInterface newNode = createNode(propertySet);
if (newNode != null) {
result.addHeader("Location", buildLocationHeader(newNode));
result.addContent(newNode);
}
result.serializeAsPrimitiveArray(true);
// finally: return 201 Created
return result;
} else {
final App app = StructrApp.getInstance(securityContext);
final Relation template = getRelationshipTemplate();
final ErrorBuffer errorBuffer = new ErrorBuffer();
if (template != null) {
final NodeInterface sourceNode = identifyStartNode(template, propertySet);
final NodeInterface targetNode = identifyEndNode(template, propertySet);
final PropertyMap properties = PropertyMap.inputTypeToJavaType(securityContext, entityClass, propertySet);
RelationshipInterface newRelationship = null;
if (sourceNode == null) {
errorBuffer.add(new EmptyPropertyToken(entityClass.getSimpleName(), template.getSourceIdProperty()));
}
if (targetNode == null) {
errorBuffer.add(new EmptyPropertyToken(entityClass.getSimpleName(), template.getTargetIdProperty()));
}
if (errorBuffer.hasError()) {
throw new FrameworkException(422, "Source node ID and target node ID of relationsips must be set", errorBuffer);
}
template.ensureCardinality(securityContext, sourceNode, targetNode);
newRelationship = app.create(sourceNode, targetNode, entityClass, properties);
RestMethodResult result = new RestMethodResult(HttpServletResponse.SC_CREATED);
if (newRelationship != null) {
result.addHeader("Location", buildLocationHeader(newRelationship));
result.addContent(newRelationship);
}
result.serializeAsPrimitiveArray(true);
// finally: return 201 Created
return result;
}
// shouldn't happen
throw new NotFoundException("Type" + rawType + " does not exist");
}
}
use of org.structr.common.error.ErrorBuffer in project structr by structr.
the class SchemaProperty method getIntPropertyParser.
public IntPropertyParser getIntPropertyParser() {
if (intPropertyParser == null) {
try {
intPropertyParser = new IntPropertyParser(new ErrorBuffer(), getName(), this);
intPropertyParser.getPropertySource(new StringBuilder(), getProperty(SchemaProperty.schemaNode));
} catch (FrameworkException fex) {
logger.warn("", fex);
}
}
return intPropertyParser;
}
use of org.structr.common.error.ErrorBuffer in project structr by structr.
the class SchemaProperty method getNotionPropertyParser.
public NotionPropertyParser getNotionPropertyParser() {
if (notionPropertyParser == null) {
try {
notionPropertyParser = new NotionPropertyParser(new ErrorBuffer(), getName(), this);
notionPropertyParser.getPropertySource(new StringBuilder(), getProperty(SchemaProperty.schemaNode));
} catch (FrameworkException fex) {
logger.warn("", fex);
}
}
return notionPropertyParser;
}
Aggregations