use of org.structr.core.property.StringProperty in project structr by structr.
the class VideoFile method getMetadata.
static RestMethodResult getMetadata(final VideoFile thisVideo) throws FrameworkException {
final SecurityContext securityContext = thisVideo.getSecurityContext();
final Map<String, String> metadata = AVConv.newInstance(securityContext, thisVideo).getMetadata();
final RestMethodResult result = new RestMethodResult(200);
final GraphObjectMap map = new GraphObjectMap();
for (final Entry<String, String> entry : metadata.entrySet()) {
map.setProperty(new StringProperty(entry.getKey()), entry.getValue());
}
result.addContent(map);
return result;
}
use of org.structr.core.property.StringProperty in project structr by structr.
the class StaticRelationshipResource method doGet.
// ~--- methods --------------------------------------------------------
@Override
public Result doGet(final PropertyKey sortKey, final boolean sortDescending, final int pageSize, final int page) throws FrameworkException {
// ok, source node exists, fetch it
final GraphObject sourceEntity = typedIdResource.getEntity();
if (sourceEntity != null) {
// first try: look through existing relations
if (propertyKey == null) {
if (sourceEntity instanceof NodeInterface) {
if (!typeResource.isNode) {
final NodeInterface source = (NodeInterface) sourceEntity;
final Node sourceNode = source.getNode();
final Class relationshipType = typeResource.entityClass;
final Relation relation = AbstractNode.getRelationshipForType(relationshipType);
final Class destNodeType = relation.getOtherType(typedIdResource.getEntityClass());
final Set partialResult = new LinkedHashSet<>(typeResource.doGet(sortKey, sortDescending, NodeFactory.DEFAULT_PAGE_SIZE, NodeFactory.DEFAULT_PAGE).getResults());
// filter list according to end node type
final Set<GraphObject> set = Iterables.toSet(Iterables.filter(new OtherNodeTypeRelationFilter(securityContext, sourceNode, destNodeType), source.getRelationships(relationshipType)));
// intersect partial result with result list
set.retainAll(partialResult);
final List<GraphObject> finalResult = new LinkedList<>(set);
// sort after merge
applyDefaultSorting(finalResult, sortKey, sortDescending);
// return result
return new Result(PagingHelper.subList(finalResult, pageSize, page), finalResult.size(), isCollectionResource(), isPrimitiveArray());
} else {
// what here?
throw new NotFoundException("Cannot access relationship collection " + typeResource.getRawType());
}
}
} else {
Query query = typeResource.query;
if (query == null) {
query = StructrApp.getInstance(securityContext).nodeQuery();
}
// use search context from type resource
typeResource.collectSearchAttributes(query);
final Predicate<GraphObject> predicate = query.toPredicate();
final Object value = sourceEntity.getProperty(propertyKey, predicate);
if (value != null) {
if (value instanceof Iterable) {
final Set<Object> propertyResults = new LinkedHashSet<>();
Iterator<Object> iter = ((Iterable<Object>) value).iterator();
boolean iterableContainsGraphObject = false;
while (iter.hasNext()) {
Object obj = iter.next();
propertyResults.add(obj);
if (obj != null && !iterableContainsGraphObject) {
if (obj instanceof GraphObject) {
iterableContainsGraphObject = true;
}
}
}
int rawResultCount = propertyResults.size();
if (rawResultCount > 0 && !iterableContainsGraphObject) {
GraphObjectMap gObject = new GraphObjectMap();
gObject.setProperty(new ArrayProperty(this.typeResource.rawType, Object.class), propertyResults.toArray());
Result r = new Result(gObject, true);
r.setRawResultCount(rawResultCount);
return r;
}
final List<GraphObject> finalResult = new LinkedList<>();
propertyResults.forEach(v -> finalResult.add((GraphObject) v));
applyDefaultSorting(finalResult, sortKey, sortDescending);
// return result
Result r = new Result(PagingHelper.subList(finalResult, pageSize, page), finalResult.size(), isCollectionResource(), isPrimitiveArray());
r.setRawResultCount(rawResultCount);
return r;
} else if (value instanceof GraphObject) {
return new Result((GraphObject) value, isPrimitiveArray());
} else {
GraphObjectMap gObject = new GraphObjectMap();
PropertyKey key;
String keyName = this.typeResource.rawType;
int resultCount = 1;
// FIXME: Dynamically resolve all property types and their result count
if (value instanceof String) {
key = new StringProperty(keyName);
} else if (value instanceof Integer) {
key = new IntProperty(keyName);
} else if (value instanceof Long) {
key = new LongProperty(keyName);
} else if (value instanceof Double) {
key = new DoubleProperty(keyName);
} else if (value instanceof Boolean) {
key = new BooleanProperty(keyName);
} else if (value instanceof Date) {
key = new DateProperty(keyName);
} else if (value instanceof String[]) {
key = new ArrayProperty(keyName, String.class);
resultCount = ((String[]) value).length;
} else {
key = new GenericProperty(keyName);
}
gObject.setProperty(key, value);
Result r = new Result(gObject, true);
r.setRawResultCount(resultCount);
return r;
}
}
// check propertyKey to return the right variant of empty result
if (!(propertyKey instanceof StartNode || propertyKey instanceof EndNode)) {
return new Result(Collections.EMPTY_LIST, 1, false, true);
}
}
}
return new Result(Collections.EMPTY_LIST, 0, false, true);
}
use of org.structr.core.property.StringProperty in project structr by structr.
the class AdvancedSearchTest method testSearchWithOwnerAndEnumOnDynamicNodes.
@Test
public void testSearchWithOwnerAndEnumOnDynamicNodes() {
createTestUserType();
try {
// create 3 users
final String user1 = createEntity("/test_users", "{ name: user1 }");
final String user2 = createEntity("/test_users", "{ name: user2 }");
final String user3 = createEntity("/test_users", "{ name: user3 }");
SchemaNode node = null;
// setup schema
try (final Tx tx = app.tx()) {
node = app.create(SchemaNode.class, new NodeAttribute(SchemaNode.name, "TestType"));
node.setProperty(new StringProperty("_status"), "Enum(one, two, three)");
node.setProperty(new StringProperty("___ui"), "status");
tx.success();
}
// create 9 test entities
final String test1 = createEntity("/test_types", "{ name: test1, owner: " + user1 + ", status: one }");
final String test2 = createEntity("/test_types", "{ name: test2, owner: " + user2 + ", status: two }");
final String test3 = createEntity("/test_types", "{ name: test3, owner: " + user3 + ", status: one }");
final String test4 = createEntity("/test_types", "{ name: test4, owner: " + user1 + ", status: two }");
final String test5 = createEntity("/test_types", "{ name: test5, owner: " + user2 + ", status: three }");
final String test6 = createEntity("/test_types", "{ name: test6, owner: " + user3 + ", status: one }");
final String test7 = createEntity("/test_types", "{ name: test7, owner: " + user1 + ", status: two }");
final String test8 = createEntity("/test_types", "{ name: test8, owner: " + user2 + ", status: three }");
final String test9 = createEntity("/test_types", "{ name: test9, owner: " + user3 + ", status: one }");
// check that all entities are there
RestAssured.given().contentType("application/json; charset=UTF-8").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(201)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(400)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(401)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(403)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(404)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).expect().statusCode(200).body("result", hasSize(9)).body("result_count", equalTo(9)).body("result[0].id", equalTo(test1)).body("result[1].id", equalTo(test2)).body("result[2].id", equalTo(test3)).body("result[3].id", equalTo(test4)).body("result[4].id", equalTo(test5)).body("result[5].id", equalTo(test6)).body("result[6].id", equalTo(test7)).body("result[7].id", equalTo(test8)).body("result[8].id", equalTo(test9)).when().get("/test_types/ui?sort=name");
// check entities of user1 are there
RestAssured.given().contentType("application/json; charset=UTF-8").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(201)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(400)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(401)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(403)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(404)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).expect().statusCode(200).body("result", hasSize(3)).body("result_count", equalTo(3)).body("result[0].id", equalTo(test1)).body("result[1].id", equalTo(test4)).body("result[2].id", equalTo(test7)).when().get("/test_types/ui?sort=createdDate&owner=" + user1);
// check entities of user2 are there
RestAssured.given().contentType("application/json; charset=UTF-8").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(201)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(400)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(401)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(403)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(404)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).expect().statusCode(200).body("result", hasSize(3)).body("result_count", equalTo(3)).body("result[0].id", equalTo(test2)).body("result[1].id", equalTo(test5)).body("result[2].id", equalTo(test8)).when().get("/test_types/ui?sort=createdDate&owner=" + user2);
// check entities of user3 are there
RestAssured.given().contentType("application/json; charset=UTF-8").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(201)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(400)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(401)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(403)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(404)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).expect().statusCode(200).body("result", hasSize(3)).body("result_count", equalTo(3)).body("result[0].id", equalTo(test3)).body("result[1].id", equalTo(test6)).body("result[2].id", equalTo(test9)).when().get("/test_types/ui?sort=createdDate&owner=" + user3);
// check entities of user1 with a given enum are there
RestAssured.given().contentType("application/json; charset=UTF-8").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(201)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(400)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(401)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(403)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(404)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).expect().statusCode(200).body("result", hasSize(1)).body("result_count", equalTo(1)).body("result[0].id", equalTo(test1)).when().get("/test_types/ui?sort=createdDate&owner=" + user1 + "&status=one");
// check entities of user1 with a given enum are there
RestAssured.given().contentType("application/json; charset=UTF-8").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(201)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(400)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(401)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(403)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(404)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).expect().statusCode(200).body("result", hasSize(2)).body("result_count", equalTo(2)).body("result[0].id", equalTo(test4)).body("result[1].id", equalTo(test7)).when().get("/test_types/ui?sort=createdDate&owner=" + user1 + "&status=two");
// check entities of user1 with a given enum are there
RestAssured.given().contentType("application/json; charset=UTF-8").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(201)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(400)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(401)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(403)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(404)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).expect().statusCode(200).body("result", hasSize(2)).body("result_count", equalTo(2)).body("result[0].id", equalTo(test5)).body("result[1].id", equalTo(test8)).when().get("/test_types/ui?sort=createdDate&owner=" + user2 + "&status=three");
} catch (FrameworkException ex) {
logger.warn("", ex);
fail("Unexpected exception");
}
}
use of org.structr.core.property.StringProperty in project structr by structr.
the class EnumInfoFunction method apply.
@Override
public Object apply(ActionContext ctx, Object caller, Object[] sources) throws FrameworkException {
try {
if (arrayHasMinLengthAndMaxLengthAndAllElementsNotNull(sources, 2, 3)) {
final ConfigurationProvider config = StructrApp.getConfiguration();
final String typeName = sources[0].toString();
final String enumPropertyName = sources[1].toString();
final boolean rawList = (sources.length == 3) ? Boolean.parseBoolean(sources[2].toString()) : false;
final Class type = SchemaHelper.getEntityClassForRawType(typeName);
if (type != null) {
final PropertyKey key = StructrApp.key(type, enumPropertyName);
if (key != null) {
if (key instanceof EnumProperty) {
final String formatString = SchemaHelper.getPropertyInfo(ctx.getSecurityContext(), key).get("format").toString();
final List<String> valueList = Arrays.asList(formatString.replace(" ", "").split(","));
if (rawList) {
return valueList;
} else {
final ArrayList<GraphObjectMap> resultList = new ArrayList();
for (final String value : valueList) {
final GraphObjectMap valueMap = new GraphObjectMap();
resultList.add(valueMap);
valueMap.put(new StringProperty("value"), value);
}
return resultList;
}
} else {
logger.warn("Error: Not an Enum property \"{}.{}\"", typeName, enumPropertyName);
return "Not an Enum property " + typeName + "." + enumPropertyName;
}
} else {
logger.warn("Error: Unknown property \"{}.{}\"", typeName, enumPropertyName);
return "Unknown property " + typeName + "." + enumPropertyName;
}
} else {
logger.warn("Error: Unknown type \"{}\"", typeName);
return "Unknown type " + typeName;
}
} else {
logParameterError(caller, sources, ctx.isJavaScriptContext());
return usage(ctx.isJavaScriptContext());
}
} catch (final IllegalArgumentException e) {
logParameterError(caller, sources, ctx.isJavaScriptContext());
return usage(ctx.isJavaScriptContext());
}
}
use of org.structr.core.property.StringProperty in project structr by structr.
the class LocalizeFunction method getLocalizedList.
public static List getLocalizedList(final Locale locale, final List<String> keyList, final String domain) throws FrameworkException {
final ArrayList<GraphObjectMap> resultList = new ArrayList();
for (final String key : keyList) {
final GraphObjectMap localizedEntry = new GraphObjectMap();
resultList.add(localizedEntry);
localizedEntry.put(new StringProperty("name"), key);
if (domain == null) {
localizedEntry.put(new StringProperty("localizedName"), getLocalization(locale, key));
} else {
localizedEntry.put(new StringProperty("localizedName"), getLocalization(locale, key, domain));
}
}
return resultList;
}
Aggregations