Skip to content

Commit

Permalink
First working version of dynamic paths for pages.
Browse files Browse the repository at this point in the history
  • Loading branch information
cmorgner committed Feb 28, 2024
1 parent 71b0574 commit e44b643
Show file tree
Hide file tree
Showing 51 changed files with 664 additions and 267 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@
<target>17</target>
<encoding>${project.build.sourceEncoding}</encoding>
<debug>true</debug>
<showDeprecation>false</showDeprecation>
</configuration>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void injectArguments(Command command) {
}

@Override
public ServiceResult initialize(final StructrServices services, String serviceName) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
public ServiceResult initialize(final StructrServices services, String serviceName) throws ReflectiveOperationException {
return new ServiceResult(true);
}

Expand Down Expand Up @@ -245,7 +245,7 @@ private Agent lookupAgent(Task task) {

try {

Agent supportedAgent = supportedAgentClass.newInstance();
Agent supportedAgent = supportedAgentClass.getDeclaredConstructor().newInstance();
Class supportedTaskClass = supportedAgent.getSupportedTaskType();

if (supportedTaskClass.equals(taskClass)) {
Expand All @@ -262,7 +262,7 @@ private Agent lookupAgent(Task task) {
if (agentClass != null) {

try {
agent = (Agent) agentClass.newInstance();
agent = (Agent) agentClass.getDeclaredConstructor().newInstance();

} catch (Throwable ignore) {}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ private static GeoCodingProvider getGeoCodingProvider() {
providerClass = (Class<GeoCodingProvider>)Class.forName(Settings.GeocodingProvider.getValue());
}

providerInstance = providerClass.newInstance();
providerInstance = providerClass.getDeclaredConstructor().newInstance();

} catch (Throwable t) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.structr.common.SecurityContext;

/**
* A helper class that provides methods for URL path splitting etc.
Expand All @@ -29,12 +28,6 @@ public class PathHelper {

public static final String PATH_SEP = "/";

private final SecurityContext securityContext;

public PathHelper(SecurityContext securityContext) {
this.securityContext = securityContext;
}

public static String clean(final String path) {

// Remove leading and trailing /
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public static RestCommand getCommand(final String name) {
if (cls != null) {

try {
return cls.newInstance();
return cls.getDeclaredConstructor().newInstance();

} catch (Throwable ignore) {}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static AdminConsoleCommand getCommand(final String name) {

try {

return cls.newInstance();
return cls.getDeclaredConstructor().newInstance();

} catch (Throwable t) {}
}
Expand Down
6 changes: 3 additions & 3 deletions structr-base/src/main/java/org/structr/core/Services.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public <T extends Command> T command(final SecurityContext securityContext, fina

try {

final T command = commandType.newInstance();
final T command = commandType.getDeclaredConstructor().newInstance();
final Class serviceClass = command.getServiceClass();

// inject security context first
Expand Down Expand Up @@ -725,7 +725,7 @@ public ConfigurationProvider getConfigurationProvider() {
// initializers.
try {

configuration = (ConfigurationProvider)Class.forName(configurationClass).newInstance();
configuration = (ConfigurationProvider)Class.forName(configurationClass).getDeclaredConstructor().newInstance();
configuration.initialize(licenseManager);

} catch (Throwable t) {
Expand Down Expand Up @@ -805,7 +805,7 @@ public ServiceResult startService(final Class serviceClass, final String service

logger.info("Creating {}..", serviceClass.getSimpleName());

final Service service = (Service) serviceClass.newInstance();
final Service service = (Service) serviceClass.getDeclaredConstructor().newInstance();

if (licenseManager != null && !licenseManager.isValid(service)) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1525,7 +1525,7 @@ public static void clearCaches() {

try {

instance = type.newInstance();
instance = type.getDeclaredConstructor().newInstance();
relationshipTemplateInstanceCache.put(type.getName(), instance);

} catch (Throwable t) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public static Relation getInstance(final Class<? extends Relation> type) {

try {

instance = type.newInstance();
instance = type.getDeclaredConstructor().newInstance();
relationCache.put(type, instance);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.structr.core.function.Functions;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.*;

import static org.structr.api.service.DatabaseConnection.*;
Expand Down Expand Up @@ -371,11 +372,11 @@ private ErrorBuffer checkInput(final Map<String, Object> data, final boolean nam

if (driverClassString != null) {

databaseService = (DatabaseService) Class.forName((String) driverClassString).newInstance();
databaseService = (DatabaseService) Class.forName((String) driverClassString).getDeclaredConstructor().newInstance();

} else {

databaseService = (DatabaseService) Class.forName("org.structr.bolt.BoltDatabaseService").newInstance();
databaseService = (DatabaseService) Class.forName("org.structr.bolt.BoltDatabaseService").getDeclaredConstructor().newInstance();
}

if (databaseService == null) {
Expand All @@ -396,7 +397,7 @@ private ErrorBuffer checkInput(final Map<String, Object> data, final boolean nam
}
}

} catch (ClassNotFoundException|InstantiationException|IllegalAccessException ex) {
} catch (ClassNotFoundException|InstantiationException|IllegalAccessException | NoSuchMethodException | SecurityException | IllegalArgumentException | InvocationTargetException ex) {
errorBuffer.add(new SemanticErrorToken("Driver", "driver", "driver_error"));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ private Object listThreads() {
return threads;
}

@SuppressWarnings("deprecation")
private Object killThread() {

for (final Thread thread : Thread.getAllStackTraces().keySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.structr.core.graph;


import java.lang.reflect.InvocationTargetException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.structr.api.graph.Identity;
Expand Down Expand Up @@ -83,9 +84,9 @@ public T instantiateWithType(final Node node, final Class<T> nodeClass, final Id
T newNode = null;

try {
newNode = nodeClass.newInstance();
newNode = nodeClass.getDeclaredConstructor().newInstance();

} catch (NoClassDefFoundError|InstantiationException|IllegalAccessException itex) {
} catch (NoSuchMethodException|NoClassDefFoundError|InvocationTargetException|InstantiationException|IllegalAccessException itex) {
newNode = null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.structr.core.Services;
import org.structr.core.app.App;
import org.structr.core.app.StructrApp;
import org.structr.core.property.PropertyKey;

import java.io.File;

Expand Down Expand Up @@ -66,14 +65,14 @@ public void injectArguments(Command command) {
}

@Override
public ServiceResult initialize(final StructrServices services, String serviceName) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
public ServiceResult initialize(final StructrServices services, String serviceName) throws ReflectiveOperationException {

this.servicesParent = services;

final String databaseDriver = Settings.DatabaseDriver.getPrefixedValue(serviceName);
String errorMessage = null;

databaseService = (DatabaseService)Class.forName(databaseDriver).newInstance();
databaseService = (DatabaseService)Class.forName(databaseDriver).getDeclaredConstructor().newInstance();
if (databaseService != null) {

if (databaseService.initialize(serviceName, services.getVersion(), services.getInstanceName())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public T instantiateWithType(final Relationship relationship, final Class<T> rel

try {

newRel = relClass.newInstance();
newRel = relClass.getDeclaredConstructor().newInstance();

} catch (Throwable t) {
logger.warn("", t);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
/**
*
*
* @param <S>
*/
public class TypeSearchAttribute<S extends GraphObject> extends PropertySearchAttribute<String> implements TypeQuery {

Expand All @@ -47,7 +48,7 @@ public TypeSearchAttribute(final Class<S> type, final Occurrence occur, final bo

try {

final Relation rel = (Relation)type.newInstance();
final Relation rel = (Relation)type.getDeclaredConstructor().newInstance();
setValue(rel.name());

this.sourceType = rel.getSourceType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,9 @@ private Transformer getTransformator(final String fqcn) {

try {

return (Transformer)Class.forName(fqcn).newInstance();
final Class clazz = Class.forName(fqcn);

return (Transformer)clazz.getConstructor().newInstance();

} catch (Throwable t) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
*/
public abstract class Property<T> implements PropertyKey<T> {

private static final Logger logger = LoggerFactory.getLogger(Property.class.getName());
private static final Pattern rangeQueryPattern = Pattern.compile("\\[(.*) TO (.*)\\]");
private static final Logger logger = LoggerFactory.getLogger(Property.class.getName());
private static final Pattern RANGE_QUERY_PATTERN = Pattern.compile("\\[(.*) TO (.*)\\]");

protected List<String> transformators = new LinkedList<>();
protected Class<? extends GraphObject> declaringClass = null;
Expand Down Expand Up @@ -620,7 +620,7 @@ protected void determineSearchType(final SecurityContext securityContext, final
if (StringUtils.startsWith(requestParameter, "[") && StringUtils.endsWith(requestParameter, "]")) {

// check for existence of range query string
Matcher matcher = rangeQueryPattern.matcher(requestParameter);
Matcher matcher = RANGE_QUERY_PATTERN.matcher(requestParameter);
if (matcher.matches()) {

if (matcher.groupCount() == 2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,8 @@
import java.util.List;
import java.util.Map.Entry;

//~--- classes ----------------------------------------------------------------

/**
* Controls deserialization of property sets.
*
*
*/
public class JsonInputGSONAdapter implements InstanceCreator<IJsonInput>, JsonSerializer<IJsonInput>, JsonDeserializer<IJsonInput> {

Expand All @@ -45,9 +41,9 @@ public class JsonInputGSONAdapter implements InstanceCreator<IJsonInput>, JsonSe
public IJsonInput createInstance(final Type type) {

try {
return (IJsonInput)type.getClass().newInstance();
return (IJsonInput)type.getClass().getDeclaredConstructor().newInstance();

} catch (InstantiationException | IllegalAccessException e) {
} catch (Throwable e) {
logger.warn("", e);
}

Expand Down
4 changes: 2 additions & 2 deletions structr-base/src/main/java/org/structr/cron/CronService.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void run() {

if (taskClass != null) {

Task task = (Task)taskClass.newInstance();
Task task = (Task)taskClass.getDeclaredConstructor().newInstance();

logger.debug("Starting task {}", taskClassName);
StructrApp.getInstance().processTasks(task);
Expand Down Expand Up @@ -170,7 +170,7 @@ public void injectArguments(Command command) {
}

@Override
public ServiceResult initialize(final StructrServices services, String serviceName) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
public ServiceResult initialize(final StructrServices services, String serviceName) throws ReflectiveOperationException {

final String taskList = Settings.CronTasks.getValue();
if (StringUtils.isNotBlank(taskList)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ public void injectArguments(final Command command) {
}

@Override
public ServiceResult initialize(final StructrServices services, String serviceName) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
public ServiceResult initialize(final StructrServices services, String serviceName) throws ReflectiveOperationException {

return new ServiceResult(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,7 @@ private void importResource(final StructrModuleInfo module) throws IOException {
try {

// we need to make sure that a module is initialized exactly once
final StructrModule structrModule = (StructrModule) clazz.newInstance();
final StructrModule structrModule = (StructrModule) clazz.getDeclaredConstructor().newInstance();
final String moduleName = structrModule.getName();

if (!modules.containsKey(moduleName)) {
Expand Down Expand Up @@ -1263,7 +1263,7 @@ private StructrModuleInfo loadResource(String resource) throws IOException {
if (StructrModule.class.isAssignableFrom(clazz) && !(Modifier.isAbstract(modifiers))) {

// we need to make sure that a module is initialized exactly once
final StructrModule structrModule = (StructrModule) clazz.newInstance();
final StructrModule structrModule = (StructrModule) clazz.getDeclaredConstructor().newInstance();

structrModule.registerModuleFunctions(licenseManager);

Expand Down Expand Up @@ -1348,7 +1348,7 @@ private Relation instantiate(final Class clazz) {

try {

return (Relation) clazz.newInstance();
return (Relation) clazz.getDeclaredConstructor().newInstance();

} catch (Throwable t) {
// ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ private Relation getRelationshipTemplate() {

try {

return (Relation)entityClass.newInstance();
return (Relation)entityClass.getDeclaredConstructor().newInstance();

} catch (Throwable t) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
import org.structr.core.GraphObject;
import org.structr.core.api.AbstractMethod;
import org.structr.core.api.Arguments;
import org.structr.core.app.StructrApp;
import org.structr.core.entity.SchemaMethod.HttpVerb;
import org.structr.core.graph.Tx;
import org.structr.rest.RestMethodResult;
import org.structr.rest.api.RESTCall;
import org.structr.rest.api.RESTMethodCallHandler;
Expand Down Expand Up @@ -120,9 +122,15 @@ public RestMethodResult doDelete(final SecurityContext securityContext) throws F

if (HttpVerb.DELETE.equals(method.getHttpVerb())) {

final GraphObject entity = getEntity(securityContext, entityClass, typeName, uuid);
try (final Tx tx = StructrApp.getInstance(securityContext).tx()) {

final GraphObject entity = getEntity(securityContext, entityClass, typeName, uuid);
final RestMethodResult result = executeMethod(securityContext, entity, Arguments.fromPath(call.getPathParameters()));

tx.success();

return executeMethod(securityContext, entity, Arguments.fromPath(call.getPathParameters()));
return result;
}

} else {

Expand Down
Loading

0 comments on commit e44b643

Please sign in to comment.