Search in sources :

Example 6 with ErrorBuffer

use of org.structr.common.error.ErrorBuffer in project structr by structr.

the class SchemaProperty method getDoublePropertyParser.

public DoublePropertyParser getDoublePropertyParser() {
    if (doublePropertyParser == null) {
        try {
            doublePropertyParser = new DoublePropertyParser(new ErrorBuffer(), getName(), this);
            doublePropertyParser.getPropertySource(new StringBuilder(), getProperty(SchemaProperty.schemaNode));
        } catch (FrameworkException fex) {
            logger.warn("", fex);
        }
    }
    return doublePropertyParser;
}
Also used : DoublePropertyParser(org.structr.schema.parser.DoublePropertyParser) ErrorBuffer(org.structr.common.error.ErrorBuffer) FrameworkException(org.structr.common.error.FrameworkException)

Example 7 with ErrorBuffer

use of org.structr.common.error.ErrorBuffer in project structr by structr.

the class SchemaProperty method getIntArrayPropertyParser.

public IntegerArrayPropertyParser getIntArrayPropertyParser() {
    if (intArrayPropertyParser == null) {
        try {
            intArrayPropertyParser = new IntegerArrayPropertyParser(new ErrorBuffer(), getName(), this);
            intArrayPropertyParser.getPropertySource(new StringBuilder(), getProperty(SchemaProperty.schemaNode));
        } catch (FrameworkException fex) {
            logger.warn("", fex);
        }
    }
    return intArrayPropertyParser;
}
Also used : ErrorBuffer(org.structr.common.error.ErrorBuffer) IntegerArrayPropertyParser(org.structr.schema.parser.IntegerArrayPropertyParser) FrameworkException(org.structr.common.error.FrameworkException)

Example 8 with ErrorBuffer

use of org.structr.common.error.ErrorBuffer in project structr by structr.

the class SchemaProperty method getLongArrayPropertyParser.

public LongArrayPropertyParser getLongArrayPropertyParser() {
    if (longArrayPropertyParser == null) {
        try {
            longArrayPropertyParser = new LongArrayPropertyParser(new ErrorBuffer(), getName(), this);
            longArrayPropertyParser.getPropertySource(new StringBuilder(), getProperty(SchemaProperty.schemaNode));
        } catch (FrameworkException fex) {
            logger.warn("", fex);
        }
    }
    return longArrayPropertyParser;
}
Also used : ErrorBuffer(org.structr.common.error.ErrorBuffer) FrameworkException(org.structr.common.error.FrameworkException) LongArrayPropertyParser(org.structr.schema.parser.LongArrayPropertyParser)

Example 9 with ErrorBuffer

use of org.structr.common.error.ErrorBuffer in project structr by structr.

the class SchemaProperty method getDoubleArrayPropertyParser.

public DoubleArrayPropertyParser getDoubleArrayPropertyParser() {
    if (doubleArrayPropertyParser == null) {
        try {
            doubleArrayPropertyParser = new DoubleArrayPropertyParser(new ErrorBuffer(), getName(), this);
            doubleArrayPropertyParser.getPropertySource(new StringBuilder(), getProperty(SchemaProperty.schemaNode));
        } catch (FrameworkException fex) {
            logger.warn("", fex);
        }
    }
    return doubleArrayPropertyParser;
}
Also used : ErrorBuffer(org.structr.common.error.ErrorBuffer) FrameworkException(org.structr.common.error.FrameworkException) DoubleArrayPropertyParser(org.structr.schema.parser.DoubleArrayPropertyParser)

Example 10 with ErrorBuffer

use of org.structr.common.error.ErrorBuffer in project structr by structr.

the class SyncCommand method importDatabase.

private static void importDatabase(final DatabaseService graphDb, final SecurityContext securityContext, final ZipInputStream zis, boolean doValidation, final Long batchSize) throws FrameworkException, IOException {
    final App app = StructrApp.getInstance();
    final DataInputStream dis = new DataInputStream(new BufferedInputStream(zis));
    final long internalBatchSize = batchSize != null ? batchSize : 200;
    final String uuidPropertyName = GraphObject.id.dbName();
    final Map<String, Node> uuidMap = new LinkedHashMap<>();
    final Set<Long> deletedNodes = new HashSet<>();
    double t0 = System.nanoTime();
    PropertyContainer currentObject = null;
    String currentKey = null;
    boolean finished = false;
    long totalNodeCount = 0;
    long totalRelCount = 0;
    do {
        try (final Tx tx = app.tx(doValidation)) {
            final List<Relationship> rels = new LinkedList<>();
            final List<Node> nodes = new LinkedList<>();
            long nodeCount = 0;
            long relCount = 0;
            do {
                try {
                    // store current position
                    dis.mark(4);
                    // read one byte
                    byte objectType = dis.readByte();
                    // skip newlines
                    if (objectType == '\n') {
                        continue;
                    }
                    if (objectType == 'N') {
                        // break loop after 200 objects, commit and restart afterwards
                        if (nodeCount + relCount >= internalBatchSize) {
                            dis.reset();
                            break;
                        }
                        currentObject = graphDb.createNode(Collections.EMPTY_SET, Collections.EMPTY_MAP);
                        nodeCount++;
                        // store for later use
                        nodes.add((Node) currentObject);
                    } else if (objectType == 'R') {
                        // break look after 200 objects, commit and restart afterwards
                        if (nodeCount + relCount >= internalBatchSize) {
                            dis.reset();
                            break;
                        }
                        String startId = (String) deserialize(dis);
                        String endId = (String) deserialize(dis);
                        String relTypeName = (String) deserialize(dis);
                        Node endNode = uuidMap.get(endId);
                        Node startNode = uuidMap.get(startId);
                        if (startNode != null && endNode != null) {
                            if (deletedNodes.contains(startNode.getId()) || deletedNodes.contains(endNode.getId())) {
                                System.out.println("NOT creating relationship between deleted nodes..");
                                currentObject = null;
                                currentKey = null;
                            } else {
                                RelationshipType relType = RelationshipType.forName(relTypeName);
                                currentObject = startNode.createRelationshipTo(endNode, relType);
                                // store for later use
                                rels.add((Relationship) currentObject);
                                relCount++;
                            }
                        } else {
                            System.out.println("NOT creating relationship of type " + relTypeName + ", start: " + startId + ", end: " + endId);
                            currentObject = null;
                            currentKey = null;
                        }
                    } else {
                        // reset if not at the beginning of a line
                        dis.reset();
                        if (currentKey == null) {
                            try {
                                currentKey = (String) deserialize(dis);
                            } catch (Throwable t) {
                                logger.warn("", t);
                            }
                        } else {
                            final Object obj = deserialize(dis);
                            if (obj != null && currentObject != null) {
                                if (uuidPropertyName.equals(currentKey) && currentObject instanceof Node) {
                                    final String uuid = (String) obj;
                                    uuidMap.put(uuid, (Node) currentObject);
                                }
                                if (currentKey.length() != 0) {
                                    // store object in DB
                                    currentObject.setProperty(currentKey, obj);
                                    // set type label
                                    if (currentObject instanceof Node && NodeInterface.type.dbName().equals(currentKey)) {
                                        ((Node) currentObject).addLabel(graphDb.forName(Label.class, (String) obj));
                                    }
                                } else {
                                    logger.error("Invalid property key for value {}, ignoring", obj);
                                }
                            } else {
                                logger.warn("No current object to store property in.");
                            }
                            currentKey = null;
                        }
                    }
                } catch (EOFException eofex) {
                    finished = true;
                }
            } while (!finished);
            totalNodeCount += nodeCount;
            totalRelCount += relCount;
            logger.info("Imported {} nodes and {} rels, committing transaction..", new Object[] { totalNodeCount, totalRelCount });
            tx.success();
        }
    } while (!finished);
    // build schema
    try (final Tx tx = app.tx()) {
        SchemaHelper.reloadSchema(new ErrorBuffer(), securityContext.getSessionId());
        tx.success();
    } catch (FrameworkException fex) {
        logger.warn("", fex);
    }
    final Map<String, Object> params = new HashMap<>();
    params.put("removeUnused", false);
    // set correct labels after schema has been compiled
    app.command(BulkCreateLabelsCommand.class).execute(params);
    double t1 = System.nanoTime();
    double time = ((t1 - t0) / 1000000000.0);
    DecimalFormat decimalFormat = new DecimalFormat("0.000000000", DecimalFormatSymbols.getInstance(Locale.ENGLISH));
    logger.info("Import done in {} s", decimalFormat.format(time));
}
Also used : App(org.structr.core.app.App) StructrApp(org.structr.core.app.StructrApp) PropertyContainer(org.structr.api.graph.PropertyContainer) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Node(org.structr.api.graph.Node) AbstractNode(org.structr.core.entity.AbstractNode) AbstractSchemaNode(org.structr.core.entity.AbstractSchemaNode) DecimalFormat(java.text.DecimalFormat) RelationshipType(org.structr.api.graph.RelationshipType) LinkedHashMap(java.util.LinkedHashMap) BufferedInputStream(java.io.BufferedInputStream) EOFException(java.io.EOFException) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) FrameworkException(org.structr.common.error.FrameworkException) DataInputStream(java.io.DataInputStream) LinkedList(java.util.LinkedList) ErrorBuffer(org.structr.common.error.ErrorBuffer) AbstractRelationship(org.structr.core.entity.AbstractRelationship) Relationship(org.structr.api.graph.Relationship) GraphObject(org.structr.core.GraphObject)

Aggregations

ErrorBuffer (org.structr.common.error.ErrorBuffer)16 FrameworkException (org.structr.common.error.FrameworkException)13 App (org.structr.core.app.App)4 StructrApp (org.structr.core.app.StructrApp)4 EmptyPropertyToken (org.structr.common.error.EmptyPropertyToken)3 LinkedList (java.util.LinkedList)2 DatabaseService (org.structr.api.DatabaseService)2 AbstractRelationship (org.structr.core.entity.AbstractRelationship)2 PropertyMap (org.structr.core.property.PropertyMap)2 RestMethodResult (org.structr.rest.RestMethodResult)2 GraphQLOutputType (graphql.schema.GraphQLOutputType)1 GraphQLScalarType (graphql.schema.GraphQLScalarType)1 BufferedInputStream (java.io.BufferedInputStream)1 DataInputStream (java.io.DataInputStream)1 EOFException (java.io.EOFException)1 File (java.io.File)1 DecimalFormat (java.text.DecimalFormat)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1