use of org.structr.core.Result 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.Result 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.Result 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.");
}
use of org.structr.core.Result in project structr by structr.
the class CypherQueryResource method doGet.
@Override
public Result doGet(PropertyKey sortKey, boolean sortDescending, int pageSize, int page) throws FrameworkException {
// Admins only
if (!securityContext.isSuperUser()) {
throw new NotAllowedException("Use of the cypher endpoint is restricted to admin users");
}
try {
Object queryObject = securityContext.getRequest().getParameter("query");
if (queryObject != null) {
String query = queryObject.toString();
List<GraphObject> resultList = StructrApp.getInstance(securityContext).command(CypherQueryCommand.class).execute(query, Collections.EMPTY_MAP);
return new Result(resultList, resultList.size(), true, false);
}
} catch (org.structr.api.NotFoundException nfe) {
throw new NotFoundException("Entity not found for the given query");
}
return new Result(Collections.EMPTY_LIST, 0, false, false);
}
use of org.structr.core.Result in project structr by structr.
the class AccessControlTest method test07ResultCount.
@Test
public void test07ResultCount() {
// remove auto-generated resource access objects
clearResourceAccess();
try {
final Class type = TestOne.class;
final List<NodeInterface> nodes = createTestNodes(type, 10);
try (final Tx tx = app.tx()) {
nodes.get(3).setProperty(AbstractNode.visibleToPublicUsers, true);
nodes.get(5).setProperty(AbstractNode.visibleToPublicUsers, true);
nodes.get(7).setProperty(AbstractNode.visibleToPublicUsers, true);
tx.success();
}
SecurityContext publicContext = SecurityContext.getInstance(null, AccessMode.Frontend);
try (final Tx tx = app.tx()) {
Result result = StructrApp.getInstance(publicContext).nodeQuery(type).sort(AbstractNode.createdDate).getResult();
assertEquals(3, result.size());
assertEquals(3, (int) result.getRawResultCount());
// do not test order of elements
// assertEquals(nodes.get(3).getUuid(), result.get(0).getUuid());
// assertEquals(nodes.get(5).getUuid(), result.get(1).getUuid());
// assertEquals(nodes.get(7).getUuid(), result.get(2).getUuid());
}
} catch (FrameworkException ex) {
logger.warn("", ex);
fail("Unexpected exception");
}
}
Aggregations