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());
}
}
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);
}
}
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;
}
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);
}
}
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);
}
}
Aggregations