Search in sources :

Example 6 with IntProperty

use of org.structr.core.property.IntProperty in project structr by structr.

the class LogResource method histogram.

private Result histogram(final LogState state) throws FrameworkException {
    // sort entries before creating the histogram
    state.sortEntries();
    final String dateFormat = state.aggregate();
    final long startTimestamp = state.beginTimestamp();
    final long endTimestamp = state.endTimestamp();
    final GraphObjectMap result = new GraphObjectMap();
    final long interval = findInterval(dateFormat);
    final long start = alignDateOnFormat(dateFormat, startTimestamp);
    final TreeMap<Long, Map<String, Object>> countMap = toHistogramCountMap(state);
    final Set<String> countProperties = getCountProperties(countMap);
    for (long current = start; current <= endTimestamp; current += interval) {
        final Map<Long, Map<String, Object>> counts = countMap.subMap(current, true, current + interval, false);
        final GraphObjectMap sum = new GraphObjectMap();
        // whether there are actual values or not)
        for (final String key : countProperties) {
            sum.put(new IntProperty(key), 0);
        }
        // evaluate counts
        for (final Map<String, Object> count : counts.values()) {
            for (final String key : countProperties) {
                final IntProperty prop = new IntProperty(key);
                Integer sumValue = sum.get(prop);
                if (sumValue == null) {
                    sumValue = 0;
                }
                Integer entryValue = (Integer) count.get(key);
                if (entryValue == null) {
                    entryValue = 0;
                }
                sum.put(prop, sumValue + entryValue);
            }
        }
        result.put(new GenericProperty(Long.toString(current)), sum);
    }
    return new Result(result, false);
}
Also used : Result(org.structr.core.Result) RestMethodResult(org.structr.rest.RestMethodResult) IntProperty(org.structr.core.property.IntProperty) GraphObjectMap(org.structr.core.GraphObjectMap) GenericProperty(org.structr.core.property.GenericProperty) GraphObject(org.structr.core.GraphObject) Map(java.util.Map) GraphObjectMap(org.structr.core.GraphObjectMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) PropertyMap(org.structr.core.property.PropertyMap) TreeMap(java.util.TreeMap)

Example 7 with IntProperty

use of org.structr.core.property.IntProperty in project structr by structr.

the class LogResource method aggregate.

private Result aggregate(final LogState state) throws FrameworkException {
    // sort entries before aggregation
    state.sortEntries();
    final long startTimestamp = state.beginTimestamp();
    final long endTimestamp = state.endTimestamp();
    final GraphObjectMap result = new GraphObjectMap();
    final long interval = findInterval(state.aggregate());
    final long start = alignDateOnFormat(state.aggregate(), startTimestamp);
    final TreeMap<Long, Map<String, Object>> countMap = toAggregatedCountMap(state);
    final Set<String> countProperties = getCountProperties(countMap);
    for (long current = start; current <= endTimestamp; current += interval) {
        final Map<Long, Map<String, Object>> counts = countMap.subMap(current, true, current + interval, false);
        final GraphObjectMap sum = new GraphObjectMap();
        // whether there are actual values or not)
        for (final String key : countProperties) {
            sum.put(new IntProperty(key), 0);
        }
        // evaluate counts
        for (final Map<String, Object> count : counts.values()) {
            for (final String key : countProperties) {
                final IntProperty prop = new IntProperty(key);
                Integer sumValue = sum.get(prop);
                if (sumValue == null) {
                    sumValue = 0;
                }
                Integer entryValue = (Integer) count.get(key);
                if (entryValue == null) {
                    entryValue = 0;
                }
                sum.put(prop, sumValue + entryValue);
            }
        }
        result.put(new GenericProperty(Long.toString(current)), sum);
    }
    return new Result(result, false);
}
Also used : Result(org.structr.core.Result) RestMethodResult(org.structr.rest.RestMethodResult) IntProperty(org.structr.core.property.IntProperty) GraphObjectMap(org.structr.core.GraphObjectMap) GenericProperty(org.structr.core.property.GenericProperty) GraphObject(org.structr.core.GraphObject) Map(java.util.Map) GraphObjectMap(org.structr.core.GraphObjectMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) PropertyMap(org.structr.core.property.PropertyMap) TreeMap(java.util.TreeMap)

Example 8 with IntProperty

use of org.structr.core.property.IntProperty in project structr by structr.

the class SystemTest method testFlawedParallelInstantiation.

/**
 * disabled, failing test to check for (existing, confirmed) flaw in parallel node instantiation)
 */
@Test
public void testFlawedParallelInstantiation() {
    final int nodeCount = 1000;
    SchemaNode createTestType = null;
    // setup: create dynamic type with onCreate() method
    try (final Tx tx = app.tx()) {
        createTestType = createTestNode(SchemaNode.class, "CreateTest");
        tx.success();
    } catch (FrameworkException fex) {
        logger.warn("", fex);
        fail("Unexpected exception.");
    }
    Class testType = StructrApp.getConfiguration().getNodeEntityClass("CreateTest");
    assertNotNull("Type CreateTest should have been created", testType);
    // second step: create 1000 test nodes
    try (final Tx tx = app.tx()) {
        createTestNodes(testType, nodeCount);
        tx.success();
    } catch (FrameworkException fex) {
        logger.warn("", fex);
        fail("Unexpected exception.");
    }
    try (final Tx tx = app.tx()) {
        createTestType.setProperty(new StringProperty("_testCount"), "Integer");
        createTestType.setProperty(new StringProperty("___onCreate"), "set(this, 'testCount', size(find('CreateTest')))");
        tx.success();
    } catch (FrameworkException fex) {
        logger.warn("", fex);
        fail("Unexpected exception.");
    }
    testType = StructrApp.getConfiguration().getNodeEntityClass("CreateTest");
    NodeInterface node = null;
    // third step: create a single node in a separate transaction
    try (final Tx tx = app.tx()) {
        node = createTestNode(testType, "Tester");
        tx.success();
    } catch (FrameworkException fex) {
        logger.warn("", fex);
        fail("Unexpected exception.");
    }
    // fourth step: check property value
    try (final Tx tx = app.tx()) {
        final Integer testCount = node.getProperty(new IntProperty("testCount"));
        assertEquals("Invalid node count, check parallel instantiation!", (int) nodeCount + 1, (int) testCount);
        tx.success();
    } catch (FrameworkException fex) {
        logger.warn("", fex);
        fail("Unexpected exception.");
    }
}
Also used : SchemaNode(org.structr.core.entity.SchemaNode) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) IntProperty(org.structr.core.property.IntProperty) StringProperty(org.structr.core.property.StringProperty) NodeInterface(org.structr.core.graph.NodeInterface) Test(org.junit.Test)

Aggregations

IntProperty (org.structr.core.property.IntProperty)8 GraphObjectMap (org.structr.core.GraphObjectMap)7 StringProperty (org.structr.core.property.StringProperty)6 Map (java.util.Map)5 GraphObject (org.structr.core.GraphObject)3 Result (org.structr.core.Result)3 GenericProperty (org.structr.core.property.GenericProperty)3 RestMethodResult (org.structr.rest.RestMethodResult)3 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 TreeMap (java.util.TreeMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 NodeInterface (org.structr.core.graph.NodeInterface)2 PropertyMap (org.structr.core.property.PropertyMap)2 Date (java.util.Date)1 LinkedHashSet (java.util.LinkedHashSet)1 LinkedList (java.util.LinkedList)1 Set (java.util.Set)1 Test (org.junit.Test)1 Node (org.structr.api.graph.Node)1