use of org.structr.core.entity.AbstractNode in project structr by structr.
the class CMISObjectService method updateProperties.
@Override
public void updateProperties(final String repositoryId, final Holder<String> objectId, final Holder<String> changeToken, final Properties properties, final ExtensionsData extension) {
final App app = StructrApp.getInstance();
final String id = objectId.getValue();
try (final Tx tx = app.tx()) {
final AbstractNode obj = app.get(AbstractNode.class, id);
if (obj != null) {
final PropertyMap propertyMap = PropertyMap.cmisTypeToJavaType(securityContext, obj.getClass(), properties);
if (propertyMap != null) {
obj.setProperties(securityContext, propertyMap);
}
} else {
throw new CmisObjectNotFoundException("Object with ID " + objectId + " does not exist");
}
tx.success();
} catch (FrameworkException fex) {
throw new CmisConstraintException(fex.getMessage(), fex);
}
}
use of org.structr.core.entity.AbstractNode in project structr by structr.
the class CMISObjectService method bulkUpdateProperties.
@Override
public List<BulkUpdateObjectIdAndChangeToken> bulkUpdateProperties(final String repositoryId, final List<BulkUpdateObjectIdAndChangeToken> objectIdsAndChangeTokens, final Properties properties, final List<String> addSecondaryTypeIds, final List<String> removeSecondaryTypeIds, final ExtensionsData extension) {
final List<BulkUpdateObjectIdAndChangeToken> result = new LinkedList<>();
final App app = StructrApp.getInstance(securityContext);
try (final Tx tx = app.tx()) {
for (final BulkUpdateObjectIdAndChangeToken token : objectIdsAndChangeTokens) {
final AbstractNode obj = app.get(AbstractNode.class, token.getId());
if (obj != null) {
final PropertyMap propertyMap = PropertyMap.cmisTypeToJavaType(securityContext, obj.getClass(), properties);
if (propertyMap != null) {
obj.setProperties(securityContext, propertyMap);
}
result.add(token);
}
}
tx.success();
} catch (FrameworkException fex) {
throw new CmisConstraintException(fex.getMessage(), fex);
}
return result;
}
use of org.structr.core.entity.AbstractNode in project structr by structr.
the class CMISObjectService method deleteObject.
@Override
public void deleteObject(String repositoryId, String objectId, Boolean allVersions, ExtensionsData extension) {
final App app = StructrApp.getInstance(securityContext);
try (final Tx tx = app.tx()) {
final Principal principal = securityContext.getUser(false);
final AbstractNode obj = app.get(AbstractNode.class, objectId);
if (obj != null) {
if (principal.isGranted(Permission.delete, securityContext)) {
if (obj.isNode()) {
// getSyncNode() returns the node or null
app.delete(obj.getSyncNode());
} else {
// getSyncRelationship() return the relationship or null
app.delete(obj.getSyncRelationship());
}
} else {
throw new CmisPermissionDeniedException("Cannot delete object with ID " + objectId);
}
} else {
throw new CmisObjectNotFoundException("Object with ID " + objectId + " does not exist");
}
tx.success();
} catch (FrameworkException fex) {
throw new CmisConstraintException(fex.getMessage(), fex);
}
}
use of org.structr.core.entity.AbstractNode in project structr by structr.
the class RelationshipResource method doGet.
@Override
public Result doGet(final PropertyKey sortKey, final boolean sortDescending, final int pageSize, final int page) throws FrameworkException {
// fetch all results, paging is applied later
final List<? extends GraphObject> results = wrappedResource.doGet(null, false, NodeFactory.DEFAULT_PAGE_SIZE, NodeFactory.DEFAULT_PAGE).getResults();
final App app = StructrApp.getInstance();
if (results != null && !results.isEmpty()) {
try {
final List<GraphObject> resultList = new LinkedList<>();
for (GraphObject obj : results) {
if (obj instanceof AbstractNode) {
final List<? extends RelationshipInterface> relationships = Direction.INCOMING.equals(direction) ? Iterables.toList(((AbstractNode) obj).getIncomingRelationships()) : Iterables.toList(((AbstractNode) obj).getOutgoingRelationships());
if (relationships != null) {
boolean filterInternalRelationshipTypes = false;
if (securityContext != null && securityContext.getRequest() != null) {
final String filterInternal = securityContext.getRequest().getParameter(REQUEST_PARAMETER_FILTER_INTERNAL_RELATIONSHIP_TYPES);
if (filterInternal != null) {
filterInternalRelationshipTypes = "true".equals(filterInternal);
}
}
// the result set using the request parameter "filterInternal=true"
if (filterInternalRelationshipTypes) {
for (final RelationshipInterface rel : relationships) {
if (!rel.isInternal()) {
resultList.add(rel);
}
}
} else {
resultList.addAll(relationships);
}
}
}
}
final int rawResultCount = resultList.size();
return new Result(PagingHelper.subList(resultList, pageSize, page), rawResultCount, true, false);
} catch (Throwable t) {
logger.warn("Exception while fetching relationships", t);
}
} else {
logger.info("No results from parent..");
}
throw new IllegalPathException(getResourceSignature() + " can only be applied to a non-empty resource");
}
use of org.structr.core.entity.AbstractNode in project structr by structr.
the class GetIncomingRelationshipsFunction method apply.
@Override
public Object apply(final ActionContext ctx, final Object caller, final Object[] sources) throws FrameworkException {
final List<AbstractRelationship> list = new ArrayList<>();
if (arrayHasMinLengthAndMaxLengthAndAllElementsNotNull(sources, 2, 3)) {
final Object source = sources[0];
final Object target = sources[1];
AbstractNode sourceNode = null;
AbstractNode targetNode = null;
if (source instanceof AbstractNode && target instanceof AbstractNode) {
sourceNode = (AbstractNode) source;
targetNode = (AbstractNode) target;
} else {
logger.warn("Error: entities are not nodes. Parameters: {}", getParametersAsString(sources));
return "Error: entities are not nodes.";
}
if (sources.length == 2) {
for (final AbstractRelationship rel : sourceNode.getIncomingRelationships()) {
final NodeInterface s = rel.getSourceNode();
final NodeInterface t = rel.getTargetNode();
// We need to check if current user can see source and target node which is often not the case for OWNS or SECURITY rels
if (s != null && t != null && s.equals(targetNode) && t.equals(sourceNode)) {
list.add(rel);
}
}
} else if (sources.length == 3) {
// dont try to create the relClass because we would need to do that both ways!!! otherwise it just fails if the nodes are in the "wrong" order (see tests:890f)
final String relType = (String) sources[2];
for (final AbstractRelationship rel : sourceNode.getIncomingRelationships()) {
final NodeInterface s = rel.getSourceNode();
final NodeInterface t = rel.getTargetNode();
// We need to check if current user can see source and target node which is often not the case for OWNS or SECURITY rels
if (s != null && t != null && rel.getRelType().name().equals(relType) && s.equals(targetNode) && t.equals(sourceNode)) {
list.add(rel);
}
}
}
} else {
logParameterError(caller, sources, ctx.isJavaScriptContext());
}
return list;
}
Aggregations