use of org.structr.core.GraphObjectMap in project structr by structr.
the class SchemaJsonResource method doGet.
@Override
public Result doGet(PropertyKey sortKey, boolean sortDescending, int pageSize, int page) throws FrameworkException {
final GraphObjectMap schema = new GraphObjectMap();
int resultCount = 0;
try {
final JsonSchema jsonSchema = StructrSchema.createFromDatabase(StructrApp.getInstance());
schema.setProperty(new StringProperty("schema"), jsonSchema.toString());
resultCount = 1;
} catch (URISyntaxException ex) {
logger.error("Error while creating JsonSchema: " + ex.getMessage());
}
Result res = new Result(schema, true);
res.setRawResultCount(resultCount);
return res;
}
use of org.structr.core.GraphObjectMap in project structr by structr.
the class SchemaResource method relationPropertyToMap.
// ----- private methods -----
private static GraphObjectMap relationPropertyToMap(final ConfigurationProvider config, final RelationProperty relationProperty) {
final GraphObjectMap map = new GraphObjectMap();
final Relation relation = relationProperty.getRelation();
/**
* what we need here:
* id,
* sourceMultiplicity,
* targetMultiplicity,
* relationshipType,
*/
map.put(SchemaRelationshipNode.sourceMultiplicity, multiplictyToString(relation.getSourceMultiplicity()));
map.put(SchemaRelationshipNode.targetMultiplicity, multiplictyToString(relation.getTargetMultiplicity()));
map.put(typeProperty, relation.getClass().getSimpleName());
map.put(SchemaRelationshipNode.relationshipType, relation.name());
final Class sourceType = relation.getSourceType();
final Class targetType = relation.getTargetType();
// select AbstractNode and SUPERCLASSES (not subclasses!)
if (sourceType.isAssignableFrom(AbstractNode.class)) {
map.put(allSourceTypesPossibleProperty, true);
map.put(htmlSourceTypesPossibleProperty, true);
map.put(possibleSourceTypesProperty, null);
} else if ("DOMNode".equals(sourceType.getSimpleName())) {
map.put(allTargetTypesPossibleProperty, false);
map.put(htmlTargetTypesPossibleProperty, true);
map.put(possibleTargetTypesProperty, null);
} else {
map.put(allSourceTypesPossibleProperty, false);
map.put(htmlSourceTypesPossibleProperty, false);
map.put(possibleSourceTypesProperty, StringUtils.join(SearchCommand.getAllSubtypesAsStringSet(sourceType.getSimpleName()), ","));
}
// select AbstractNode and SUPERCLASSES (not subclasses!)
if (targetType.isAssignableFrom(AbstractNode.class)) {
map.put(allTargetTypesPossibleProperty, true);
map.put(htmlTargetTypesPossibleProperty, true);
map.put(possibleTargetTypesProperty, null);
} else if ("DOMNode".equals(targetType.getSimpleName())) {
map.put(allTargetTypesPossibleProperty, false);
map.put(htmlTargetTypesPossibleProperty, true);
map.put(possibleTargetTypesProperty, null);
} else {
map.put(allTargetTypesPossibleProperty, false);
map.put(htmlTargetTypesPossibleProperty, false);
map.put(possibleTargetTypesProperty, StringUtils.join(SearchCommand.getAllSubtypesAsStringSet(targetType.getSimpleName()), ","));
}
return map;
}
use of org.structr.core.GraphObjectMap in project structr by structr.
the class EnvResource method doGet.
@Override
public Result doGet(PropertyKey sortKey, boolean sortDescending, int pageSize, int page) throws FrameworkException {
final List<GraphObjectMap> resultList = new LinkedList<>();
final GraphObjectMap info = new GraphObjectMap();
info.setProperty(new GenericProperty("modules"), VersionHelper.getModules());
info.setProperty(new GenericProperty("components"), VersionHelper.getComponents());
info.setProperty(new StringProperty("classPath"), VersionHelper.getClassPath());
info.setProperty(new StringProperty("instanceName"), VersionHelper.getInstanceName());
info.setProperty(new StringProperty("instanceStage"), VersionHelper.getInstanceStage());
info.setProperty(new ArrayProperty("mainMenu", String.class), VersionHelper.getMenuEntries());
final LicenseManager licenseManager = Services.getInstance().getLicenseManager();
if (licenseManager != null) {
info.setProperty(new StringProperty("edition"), licenseManager.getEdition());
info.setProperty(new StringProperty("licensee"), licenseManager.getLicensee());
info.setProperty(new StringProperty("hostId"), licenseManager.getHardwareFingerprint());
info.setProperty(new StringProperty("startDate"), licenseManager.getStartDate());
info.setProperty(new StringProperty("endDate"), licenseManager.getEndDate());
} else {
info.setProperty(new StringProperty("edition"), "Community");
info.setProperty(new StringProperty("licensee"), "Unlicensed");
}
resultList.add(info);
return new Result(resultList, resultList.size(), false, false);
}
use of org.structr.core.GraphObjectMap in project structr by structr.
the class LogResource method wrap.
private List<GraphObjectMap> wrap(final List<Map<String, Object>> entries) {
final List<GraphObjectMap> result = new LinkedList<>();
for (final Map<String, Object> entry : entries) {
final GraphObjectMap map = new GraphObjectMap();
for (final Entry<String, Object> e : entry.entrySet()) {
final String key = e.getKey();
if (timestampProperty.jsonName().equals(key)) {
map.put(timestampProperty, new Date((Long) e.getValue()));
} else {
map.put(new GenericProperty(key), e.getValue());
}
}
result.add(map);
}
return result;
}
use of org.structr.core.GraphObjectMap in project structr by structr.
the class LogResource method doGet.
@Override
public Result doGet(PropertyKey sortKey, boolean sortDescending, int pageSize, int page) throws FrameworkException {
final HttpServletRequest request = securityContext.getRequest();
if (request != null) {
final String subjectId = request.getParameter(subjectProperty.jsonName());
final String objectId = request.getParameter(objectProperty.jsonName());
final GraphObjectMap overviewMap = new GraphObjectMap();
final LogState logState = new LogState(request);
if (StringUtils.isNotEmpty(subjectId) && StringUtils.isNotEmpty(objectId)) {
processData(logState, StructrApp.getInstance(securityContext).nodeQuery(LogEvent.class).and(LogEvent.subjectProperty, subjectId).and(LogEvent.objectProperty, objectId).and(LogEvent.actionProperty, logState.logAction).andRange(LogEvent.timestampProperty, new Date(logState.beginTimestamp()), new Date(logState.endTimestamp())).getAsList());
} else if (StringUtils.isNotEmpty(subjectId) && StringUtils.isEmpty(objectId)) {
processData(logState, StructrApp.getInstance(securityContext).nodeQuery(LogEvent.class).and(LogEvent.subjectProperty, subjectId).and(LogEvent.actionProperty, logState.logAction).andRange(LogEvent.timestampProperty, new Date(logState.beginTimestamp()), new Date(logState.endTimestamp())).getAsList());
} else if (StringUtils.isEmpty(subjectId) && StringUtils.isNotEmpty(objectId)) {
logState.inverse(true);
processData(logState, StructrApp.getInstance(securityContext).nodeQuery(LogEvent.class).and(LogEvent.objectProperty, objectId).and(LogEvent.actionProperty, logState.logAction).andRange(LogEvent.timestampProperty, new Date(logState.beginTimestamp()), new Date(logState.endTimestamp())).getAsList());
} else if (logState.doActionQuery()) {
processData(logState);
} else {
// create overview of existing logs
logState.overview(true);
processData(logState, StructrApp.getInstance(securityContext).nodeQuery(LogEvent.class).getAsList());
}
if (logState.overview()) {
overviewMap.put(actionsProperty, logState.actions());
overviewMap.put(entryCountProperty, logState.actionCount());
overviewMap.put(firstEntryProperty, new Date(logState.beginTimestamp()));
overviewMap.put(lastEntryProperty, new Date(logState.endTimestamp()));
return new Result(overviewMap, false);
} else if (logState.doHistogram()) {
// aggregate results
return histogram(logState);
} else if (logState.doAggregate()) {
// aggregate results
return aggregate(logState);
} else {
// sort result
logState.sortEntries();
return new Result(wrap(logState.entries()), logState.size(), true, false);
}
}
// no request object, this is fatal
throw new FrameworkException(500, "No request object present, aborting.");
}
Aggregations