use of org.structr.core.GraphObject in project structr by structr.
the class StartNode method getSearchAttribute.
@Override
public SearchAttribute getSearchAttribute(SecurityContext securityContext, Occurrence occur, S searchValue, boolean exactMatch, final Query query) {
final Predicate<GraphObject> predicate = query != null ? query.toPredicate() : null;
final SourceSearchAttribute attr = new SourceSearchAttribute(occur);
final Set<GraphObject> intersectionResult = new LinkedHashSet<>();
boolean alreadyAdded = false;
if (searchValue != null && !StringUtils.isBlank(searchValue.toString())) {
if (exactMatch) {
switch(occur) {
case REQUIRED:
if (!alreadyAdded) {
// the first result is the basis of all subsequent intersections
intersectionResult.addAll(getRelatedNodesReverse(securityContext, searchValue, declaringClass, predicate));
// the next additions are intersected with this one
alreadyAdded = true;
} else {
intersectionResult.retainAll(getRelatedNodesReverse(securityContext, searchValue, declaringClass, predicate));
}
break;
case OPTIONAL:
intersectionResult.addAll(getRelatedNodesReverse(securityContext, searchValue, declaringClass, predicate));
break;
case FORBIDDEN:
break;
}
} else {
intersectionResult.addAll(getRelatedNodesReverse(securityContext, searchValue, declaringClass, predicate));
}
attr.setResult(intersectionResult);
} else {
// value in the given field
return new EmptySearchAttribute(this, null);
}
return attr;
}
use of org.structr.core.GraphObject in project structr by structr.
the class StartNodes method getSearchAttribute.
@Override
public SearchAttribute getSearchAttribute(SecurityContext securityContext, Occurrence occur, List<S> searchValue, boolean exactMatch, final Query query) {
final Predicate<GraphObject> predicate = query != null ? query.toPredicate() : null;
final SourceSearchAttribute attr = new SourceSearchAttribute(occur);
final Set<GraphObject> intersectionResult = new LinkedHashSet<>();
boolean alreadyAdded = false;
if (searchValue != null && !StringUtils.isBlank(searchValue.toString())) {
if (exactMatch) {
for (NodeInterface node : searchValue) {
switch(occur) {
case REQUIRED:
if (!alreadyAdded) {
// the first result is the basis of all subsequent intersections
intersectionResult.addAll(getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
// the next additions are intersected with this one
alreadyAdded = true;
} else {
intersectionResult.retainAll(getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
}
break;
case OPTIONAL:
intersectionResult.addAll(getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
break;
case FORBIDDEN:
break;
}
}
} else {
// loose search behaves differently, all results must be combined
for (NodeInterface node : searchValue) {
intersectionResult.addAll(getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
}
}
attr.setResult(intersectionResult);
} else {
// value in the given field
return new EmptySearchAttribute(this, null);
}
return attr;
}
use of org.structr.core.GraphObject in project structr by structr.
the class AllExpression method evaluate.
@Override
public Object evaluate(final ActionContext ctx, final GraphObject entity) throws FrameworkException, UnlicensedException {
if (listExpression == null) {
return ERROR_MESSAGE_ALL;
}
final Object listSource = listExpression.evaluate(ctx, entity);
if (listSource != null && listSource instanceof List) {
final List source = (List) listSource;
final Object oldDataValue = ctx.getConstant("data");
for (Object obj : source) {
ctx.setConstant("data", obj);
final Object resultObject = allExpression.evaluate(ctx, entity);
if (resultObject != null) {
if (resultObject instanceof Boolean) {
if (!(Boolean) resultObject) {
return false;
}
} else {
if (!Boolean.valueOf(resultObject.toString())) {
return false;
}
}
}
}
ctx.setConstant("data", oldDataValue);
}
return true;
}
use of org.structr.core.GraphObject in project structr by structr.
the class AnyExpression method evaluate.
@Override
public Object evaluate(final ActionContext ctx, final GraphObject entity) throws FrameworkException, UnlicensedException {
if (listExpression == null) {
return ERROR_MESSAGE_ANY;
}
final Object listSource = listExpression.evaluate(ctx, entity);
if (listSource != null && listSource instanceof List) {
final List source = (List) listSource;
final Object oldDataValue = ctx.getConstant("data");
for (Object obj : source) {
ctx.setConstant("data", obj);
final Object resultObject = anyExpression.evaluate(ctx, entity);
if (resultObject != null) {
if (resultObject instanceof Boolean) {
if ((Boolean) resultObject) {
return true;
}
} else {
if (Boolean.valueOf(resultObject.toString())) {
return true;
}
}
}
}
ctx.setConstant("data", oldDataValue);
}
return false;
}
use of org.structr.core.GraphObject in project structr by structr.
the class AutoStringProperty method index.
@Override
public void index(GraphObject entity, Object value) {
Object indexValue = value;
if (indexValue == null) {
indexValue = createValue(entity);
if (indexValue != null) {
try {
entity.setProperty(this, (String) indexValue);
} catch (FrameworkException fex) {
logger.warn("Unable to set value {} on entity {}: {}", new Object[] { indexValue, entity, fex.getMessage() });
}
}
}
super.index(entity, indexValue);
}
Aggregations