Search in sources :

Example 96 with FrameworkException

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

the class JavaParserModule method handlePackageFolder.

private void handlePackageFolder(final Folder folder, final Folder parentFolder) {
    // Folder contains a package-info.java so it must be a package
    String[] parts = folder.getPath().split("src/main/java/");
    if (parts.length > 1) {
        final PropertyMap identifyingProperties = new PropertyMap();
        final PropertyMap allProperties = new PropertyMap();
        // Convert path to package path
        String path = StringUtils.replaceAll(parts[1], "/", ".");
        identifyingProperties.put(Package.name, path);
        allProperties.putAll(identifyingProperties);
        allProperties.put(Package.folder, folder);
        // Check if we are contained in a module:
        // Find the closest ancestor folder which has a module
        Module mod = null;
        Package pkg = null;
        Folder possibleModuleParentFolder = parentFolder;
        // Continue until root folder or a module was found
        while (possibleModuleParentFolder != null && mod == null) {
            try {
                mod = app.nodeQuery(Module.class).and(Module.folder, possibleModuleParentFolder).getFirst();
                pkg = app.nodeQuery(Package.class).and(Module.folder, possibleModuleParentFolder).getFirst();
            } catch (FrameworkException ignore) {
            }
            if (pkg != null) {
                // Parent folder contains a package
                allProperties.put(Package.parent, pkg);
            } else if (mod != null) {
                // Parent folder contains a module
                allProperties.put(Package.module, mod);
                break;
            }
            // Continue while loop
            possibleModuleParentFolder = possibleModuleParentFolder.getParent();
        }
        getOrCreate(Package.class, identifyingProperties, allProperties);
        logger.info("Created or found package '" + path + "' in folder " + folder.getPath());
    }
}
Also used : PropertyMap(org.structr.core.property.PropertyMap) FrameworkException(org.structr.common.error.FrameworkException) Package(org.structr.javaparser.entity.Package) StructrModule(org.structr.module.StructrModule) Module(org.structr.javaparser.entity.Module) Folder(org.structr.web.entity.Folder)

Example 97 with FrameworkException

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

the class JavaParserModule method handlePomFile.

private void handlePomFile(final File file, final Folder folder, final Folder parentFolder) {
    final XPath xpath = XPathFactory.newInstance().newXPath();
    QName returnType = XPathConstants.STRING;
    final String content = file.getFavoriteContent();
    final String projectName;
    try {
        projectName = (String) xpath.evaluate("/project/name", parseXml(content), returnType);
        final Module newMod = createModule(projectName, folder);
        logger.info("Created module '" + projectName + "' in folder " + folder.getPath());
        // Check if we are child of a parent module
        // Find the closest ancestor folder which has a module
        Module mod = null;
        Folder possibleModuleParentFolder = parentFolder;
        // Continue until root folder or a module was found
        while (possibleModuleParentFolder != null && mod == null) {
            try {
                mod = app.nodeQuery(Module.class).and(Module.folder, possibleModuleParentFolder).getFirst();
            } catch (FrameworkException ignore) {
            }
            if (mod != null) {
                newMod.setProperty(Module.parent, mod);
                break;
            }
            // Continue while loop
            possibleModuleParentFolder = possibleModuleParentFolder.getParent();
        }
    } catch (ParserConfigurationException | SAXException | IOException | XPathExpressionException | FrameworkException ex) {
        logger.warn("Exception exception occured", ex);
    }
}
Also used : XPath(javax.xml.xpath.XPath) FrameworkException(org.structr.common.error.FrameworkException) QName(javax.xml.namespace.QName) XPathExpressionException(javax.xml.xpath.XPathExpressionException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) StructrModule(org.structr.module.StructrModule) Module(org.structr.javaparser.entity.Module) Folder(org.structr.web.entity.Folder) SAXException(org.xml.sax.SAXException)

Example 98 with FrameworkException

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

the class JavaParserModule method handlePackage.

private org.structr.javaparser.entity.Package handlePackage(final PackageDeclaration pkg) {
    final PropertyMap packageIdentifyingProperties = new PropertyMap();
    packageIdentifyingProperties.put(org.structr.javaparser.entity.Package.name, pkg.getNameAsString());
    org.structr.javaparser.entity.Package clsPackage = (org.structr.javaparser.entity.Package) getOrCreate(Package.class, packageIdentifyingProperties, packageIdentifyingProperties);
    if (clsPackage != null) {
        try {
            // Find corresponding folder
            final Folder packageFolder = app.nodeQuery(Folder.class).and(StructrApp.key(Folder.class, "path"), StringUtils.replaceAll(clsPackage.getName(), ".", "/")).getFirst();
            if (packageFolder != null) {
                clsPackage.setProperty(Package.folder, packageFolder);
            }
        } catch (final FrameworkException ex) {
        }
        ;
    }
    return clsPackage;
}
Also used : Package(org.structr.javaparser.entity.Package) PropertyMap(org.structr.core.property.PropertyMap) FrameworkException(org.structr.common.error.FrameworkException) Package(org.structr.javaparser.entity.Package) Folder(org.structr.web.entity.Folder)

Example 99 with FrameworkException

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

the class StructrMessagingEngineModuleTest method cleanDatabase.

@Before
public void cleanDatabase() {
    try (final Tx tx = app.tx()) {
        final List<? extends NodeInterface> nodes = app.nodeQuery().getAsList();
        logger.info("Cleaning database: {} nodes", nodes.size());
        for (final NodeInterface node : nodes) {
            app.delete(node);
        }
        // delete remaining nodes without UUIDs etc.
        app.cypher("MATCH (n)-[r]-(m) DELETE n, r, m", Collections.emptyMap());
        tx.success();
    } catch (FrameworkException fex) {
        logger.error("Exception while trying to clean database: {}", fex);
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) NodeInterface(org.structr.core.graph.NodeInterface)

Example 100 with FrameworkException

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

the class ODSExporter method exportAttributes.

public static void exportAttributes(final ODSExporter thisNode, final String uuid) throws FrameworkException {
    final SecurityContext securityContext = thisNode.getSecurityContext();
    final File output = thisNode.getResultDocument();
    final VirtualType transformation = thisNode.getTransformationProvider();
    try {
        final App app = StructrApp.getInstance();
        final Result result = app.nodeQuery(AbstractNode.class).and(GraphObject.id, uuid).getResult();
        final Result transformedResult = transformation.transformOutput(securityContext, AbstractNode.class, result);
        Map<String, Object> nodeProperties = new HashMap<>();
        GraphObjectMap node = (GraphObjectMap) transformedResult.get(0);
        node.getPropertyKeys(null).forEach(p -> nodeProperties.put(p.dbName(), node.getProperty(p)));
        OdfSpreadsheetDocument spreadsheet = OdfSpreadsheetDocument.loadDocument(output.getFileOnDisk().getAbsolutePath());
        OdfTable sheet = spreadsheet.getTableList().get(0);
        Iterator<Entry<String, Object>> it = nodeProperties.entrySet().iterator();
        while (it.hasNext()) {
            Entry<String, Object> currentEntry = it.next();
            String address = currentEntry.getKey();
            Object val = currentEntry.getValue();
            if (val instanceof Collection) {
                Collection col = (Collection) val;
                writeCollectionToCells(sheet, sheet.getCellByPosition(address), col);
            } else if (val instanceof String[]) {
                String[] arr = (String[]) val;
                List<String> list = new ArrayList<>(Arrays.asList(arr));
                writeCollectionToCells(sheet, sheet.getCellByPosition(address), list);
            } else {
                writeObjectToCell(sheet.getCellByPosition(address), val);
            }
        }
        spreadsheet.save(output.getFileOnDisk().getAbsolutePath());
        spreadsheet.close();
    } catch (Exception e) {
        logger.error("Error while exporting to ODS", e);
    }
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) HashMap(java.util.HashMap) OdfSpreadsheetDocument(org.odftoolkit.odfdom.doc.OdfSpreadsheetDocument) VirtualType(org.structr.transform.VirtualType) FrameworkException(org.structr.common.error.FrameworkException) Result(org.structr.core.Result) Entry(java.util.Map.Entry) GraphObjectMap(org.structr.core.GraphObjectMap) SecurityContext(org.structr.common.SecurityContext) Collection(java.util.Collection) GraphObject(org.structr.core.GraphObject) OdfTable(org.odftoolkit.odfdom.doc.table.OdfTable) ArrayList(java.util.ArrayList) List(java.util.List) File(org.structr.web.entity.File)

Aggregations

FrameworkException (org.structr.common.error.FrameworkException)892 Tx (org.structr.core.graph.Tx)673 Test (org.junit.Test)450 App (org.structr.core.app.App)175 StructrApp (org.structr.core.app.StructrApp)174 StructrUiTest (org.structr.web.StructrUiTest)134 NodeInterface (org.structr.core.graph.NodeInterface)121 StructrTest (org.structr.common.StructrTest)118 PropertyKey (org.structr.core.property.PropertyKey)109 PropertyMap (org.structr.core.property.PropertyMap)105 IOException (java.io.IOException)96 GraphObject (org.structr.core.GraphObject)93 TestOne (org.structr.core.entity.TestOne)92 File (org.structr.web.entity.File)85 SecurityContext (org.structr.common.SecurityContext)78 Principal (org.structr.core.entity.Principal)69 Page (org.structr.web.entity.dom.Page)69 LinkedList (java.util.LinkedList)62 Folder (org.structr.web.entity.Folder)60 NodeAttribute (org.structr.core.graph.NodeAttribute)56