Search in sources :

Example 6 with Result

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;
}
Also used : GraphObjectMap(org.structr.core.GraphObjectMap) JsonSchema(org.structr.schema.json.JsonSchema) StringProperty(org.structr.core.property.StringProperty) URISyntaxException(java.net.URISyntaxException) RestMethodResult(org.structr.rest.RestMethodResult) Result(org.structr.core.Result)

Example 7 with Result

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);
}
Also used : ArrayProperty(org.structr.core.property.ArrayProperty) GraphObjectMap(org.structr.core.GraphObjectMap) GenericProperty(org.structr.core.property.GenericProperty) StringProperty(org.structr.core.property.StringProperty) LicenseManager(org.structr.api.service.LicenseManager) LinkedList(java.util.LinkedList) RestMethodResult(org.structr.rest.RestMethodResult) Result(org.structr.core.Result)

Example 8 with Result

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.");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) FrameworkException(org.structr.common.error.FrameworkException) LogEvent(org.structr.rest.logging.entity.LogEvent) GraphObjectMap(org.structr.core.GraphObjectMap) Date(java.util.Date) Result(org.structr.core.Result) RestMethodResult(org.structr.rest.RestMethodResult)

Example 9 with Result

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);
}
Also used : NotAllowedException(org.structr.rest.exception.NotAllowedException) NotFoundException(org.structr.rest.exception.NotFoundException) GraphObject(org.structr.core.GraphObject) GraphObject(org.structr.core.GraphObject) CypherQueryCommand(org.structr.core.graph.CypherQueryCommand) RestMethodResult(org.structr.rest.RestMethodResult) Result(org.structr.core.Result)

Example 10 with Result

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");
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) TestOne(org.structr.core.entity.TestOne) NodeInterface(org.structr.core.graph.NodeInterface) Result(org.structr.core.Result) Test(org.junit.Test)

Aggregations

Result (org.structr.core.Result)66 FrameworkException (org.structr.common.error.FrameworkException)45 Tx (org.structr.core.graph.Tx)36 Test (org.junit.Test)34 TestOne (org.structr.core.entity.TestOne)31 PropertyKey (org.structr.core.property.PropertyKey)28 PropertyMap (org.structr.core.property.PropertyMap)21 NodeInterface (org.structr.core.graph.NodeInterface)18 GraphObject (org.structr.core.GraphObject)14 AbstractNode (org.structr.core.entity.AbstractNode)12 RestMethodResult (org.structr.rest.RestMethodResult)12 Random (java.util.Random)11 SecurityContext (org.structr.common.SecurityContext)11 GraphObjectMap (org.structr.core.GraphObjectMap)10 LinkedList (java.util.LinkedList)9 Query (org.structr.core.app.Query)9 App (org.structr.core.app.App)8 StructrApp (org.structr.core.app.StructrApp)8 List (java.util.List)7 Principal (org.structr.core.entity.Principal)7