use of org.structr.core.graph.search.SourceSearchAttribute in project structr by structr.
the class PathProperty method getSearchAttribute.
@Override
public SearchAttribute getSearchAttribute(final SecurityContext securityContext, final Occurrence occur, final String searchValue, final boolean exactMatch, final Query query) {
final App app = StructrApp.getInstance(securityContext);
final SourceSearchAttribute attr = new SourceSearchAttribute(occur);
try {
final ArrayList<String> parts = new ArrayList<>(Arrays.asList(PathHelper.getParts(searchValue)));
if (!parts.isEmpty()) {
searchRecursively(app, null, attr, parts);
}
} catch (FrameworkException ex) {
logger.error("", ex);
}
return attr;
}
use of org.structr.core.graph.search.SourceSearchAttribute in project structr by structr.
the class EndNodes method getSearchAttribute.
@Override
public SearchAttribute getSearchAttribute(SecurityContext securityContext, Occurrence occur, List<T> 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.graph.search.SourceSearchAttribute in project structr by structr.
the class EntityNotionProperty method getSearchAttribute.
@Override
public SearchAttribute getSearchAttribute(SecurityContext securityContext, Occurrence occur, T 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;
try {
if (searchValue != null && !StringUtils.isBlank(searchValue.toString())) {
final App app = StructrApp.getInstance(securityContext);
final PropertyKey key = notion.getPrimaryPropertyKey();
final PropertyConverter inputConverter = key != null ? key.inputConverter(securityContext) : null;
// transform search values using input convert of notion property
final Object transformedValue = inputConverter != null ? inputConverter.convert(searchValue) : searchValue;
if (exactMatch) {
Result<AbstractNode> result = app.nodeQuery(entityProperty.relatedType()).and(key, transformedValue).getResult();
for (AbstractNode node : result.getResults()) {
switch(occur) {
case REQUIRED:
if (!alreadyAdded) {
// the first result is the basis of all subsequent intersections
intersectionResult.addAll(entityProperty.getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
// the next additions are intersected with this one
alreadyAdded = true;
} else {
intersectionResult.retainAll(entityProperty.getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
}
break;
case OPTIONAL:
intersectionResult.addAll(entityProperty.getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
break;
case FORBIDDEN:
break;
}
}
} else {
Result<AbstractNode> result = app.nodeQuery(entityProperty.relatedType()).and(key, transformedValue, false).getResult();
// loose search behaves differently, all results must be combined
for (AbstractNode node : result.getResults()) {
intersectionResult.addAll(entityProperty.getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
}
}
attr.setResult(intersectionResult);
} else {
// value in the given field
return new EmptySearchAttribute(this, null);
}
} catch (FrameworkException fex) {
logger.warn("", fex);
}
return attr;
}
use of org.structr.core.graph.search.SourceSearchAttribute in project structr by structr.
the class EndNode method getSearchAttribute.
@Override
public SearchAttribute getSearchAttribute(SecurityContext securityContext, Occurrence occur, T 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.graph.search.SourceSearchAttribute 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;
}
Aggregations