Search in sources :

Example 21 with GraphObjectMap

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;
}
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 22 with GraphObjectMap

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;
}
Also used : Relation(org.structr.core.entity.Relation) GraphObjectMap(org.structr.core.GraphObjectMap)

Example 23 with GraphObjectMap

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);
}
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 24 with GraphObjectMap

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;
}
Also used : GraphObjectMap(org.structr.core.GraphObjectMap) GenericProperty(org.structr.core.property.GenericProperty) GraphObject(org.structr.core.GraphObject) LinkedList(java.util.LinkedList) Date(java.util.Date)

Example 25 with GraphObjectMap

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.");
}
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)

Aggregations

GraphObjectMap (org.structr.core.GraphObjectMap)60 LinkedList (java.util.LinkedList)27 GraphObject (org.structr.core.GraphObject)24 Map (java.util.Map)18 FrameworkException (org.structr.common.error.FrameworkException)16 StringProperty (org.structr.core.property.StringProperty)15 GenericProperty (org.structr.core.property.GenericProperty)13 PropertyKey (org.structr.core.property.PropertyKey)12 List (java.util.List)11 Result (org.structr.core.Result)10 SecurityContext (org.structr.common.SecurityContext)8 IntProperty (org.structr.core.property.IntProperty)8 RestMethodResult (org.structr.rest.RestMethodResult)8 ArrayList (java.util.ArrayList)6 Collection (java.util.Collection)6 Test (org.junit.Test)6 ConfigurationProvider (org.structr.schema.ConfigurationProvider)6 HashMap (java.util.HashMap)5 LinkedHashSet (java.util.LinkedHashSet)5 Tx (org.structr.core.graph.Tx)5