Permalink
Browse files

APPNG-2180 revisited action, added child module to pom

  • Loading branch information...
madness-inc committed May 15, 2018
1 parent 78574fa commit 5e236dfa7c0c66b14bb9bee9b025b7a2bba051c7
@@ -829,6 +829,12 @@
<version>1.18.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.appng</groupId>
<artifactId>appng-rest-api</artifactId>
<version>1.18.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.appng</groupId>
<artifactId>appng-camunda</artifactId>
@@ -78,64 +78,67 @@ public RestAction(MessageSource messageSource) {
@GetMapping(path = "/action/{event-id}/{id}")
public ResponseEntity<Action> getAction(@PathVariable(name = "event-id") String eventId,
@PathVariable(name = "id") String actionId, Site site, Application application, Environment environment,
HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
@PathVariable(name = "id") String actionId, Site site, Application app, Environment env,
HttpServletRequest servletReq, HttpServletResponse servletResp)
throws JAXBException, InvalidConfigurationException, ProcessingException {
RestRequest initialRequest = new RestRequest(null, null);
httpServletRequest.getParameterMap().keySet().stream().filter(k -> !k.equals(FORM_ACTION)).forEach(key -> {
String[] parameterValues = httpServletRequest.getParameterValues(key);
for (String parameterValue : parameterValues) {
initialRequest.addParameter(key, parameterValue);
}
});
ApplicationProvider applicationProvider = (ApplicationProvider) application;
ApplicationProvider applicationProvider = (ApplicationProvider) app;
MarshallService marshallService = MarshallService.getMarshallService();
initRequest(site, application, environment, applicationProvider, initialRequest);
org.appng.xml.platform.Action initialAction = applicationProvider.processAction(httpServletResponse, false,
RestRequest initialRequest = getInitialRequest(site, app, env, servletReq, applicationProvider);
org.appng.xml.platform.Action initialAction = applicationProvider.processAction(servletResp, false,
initialRequest, actionId, eventId, marshallService);
if (httpServletResponse.getStatus() != HttpStatus.OK.value()) {
return new ResponseEntity<>(HttpStatus.valueOf(httpServletResponse.getStatus()));
if (servletResp.getStatus() != HttpStatus.OK.value()) {
return new ResponseEntity<>(HttpStatus.valueOf(servletResp.getStatus()));
}
Action action = getAction(initialRequest, initialAction, environment, null);
postProcessAction(action, site, application, environment);
Action action = getAction(initialRequest, initialAction, env, null);
postProcessAction(action, site, app, env);
return new ResponseEntity<Action>(action, HttpStatus.OK);
}
@RequestMapping(path = "/action/{event-id}/{id}", method = { RequestMethod.POST, RequestMethod.PUT,
RequestMethod.DELETE })
public ResponseEntity<Action> performAction(@PathVariable(name = "event-id") String eventId,
@PathVariable(name = "id") String actionId, @RequestBody Action receivedData, Site site,
Application application, Environment environment, HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) throws ProcessingException, JAXBException,
InvalidConfigurationException, org.appng.api.ProcessingException {
@PathVariable(name = "id") String actionId, @RequestBody Action receivedData, Site site, Application app,
Environment env, HttpServletRequest servletReq, HttpServletResponse servletResp) throws ProcessingException,
JAXBException, InvalidConfigurationException, org.appng.api.ProcessingException {
ApplicationProvider applicationProvider = (ApplicationProvider) application;
ApplicationProvider applicationProvider = (ApplicationProvider) app;
MarshallService marshallService = MarshallService.getMarshallService();
RestRequest initialRequest = initRequest(site, application, environment, applicationProvider,
new RestRequest(null, null));
org.appng.xml.platform.Action initialAction = applicationProvider.processAction(httpServletResponse, false,
RestRequest initialRequest = getInitialRequest(site, app, env, servletReq, applicationProvider);
org.appng.xml.platform.Action initialAction = applicationProvider.processAction(servletResp, false,
initialRequest, actionId, eventId, marshallService);
if (httpServletResponse.getStatus() != HttpStatus.OK.value()) {
return new ResponseEntity<>(HttpStatus.valueOf(httpServletResponse.getStatus()));
if (servletResp.getStatus() != HttpStatus.OK.value()) {
return new ResponseEntity<>(HttpStatus.valueOf(servletResp.getStatus()));
}
RestRequest executingRequest = new RestRequest(initialAction, receivedData);
initRequest(site, application, environment, applicationProvider, executingRequest);
org.appng.xml.platform.Action processedAction = applicationProvider.processAction(httpServletResponse, false,
initRequest(site, app, env, applicationProvider, executingRequest);
org.appng.xml.platform.Action processedAction = applicationProvider.processAction(servletResp, false,
executingRequest, actionId, eventId, marshallService);
if (httpServletResponse.getStatus() != HttpStatus.OK.value()) {
return new ResponseEntity<>(HttpStatus.valueOf(httpServletResponse.getStatus()));
if (servletResp.getStatus() != HttpStatus.OK.value()) {
return new ResponseEntity<>(HttpStatus.valueOf(servletResp.getStatus()));
}
Action action = getAction(executingRequest, processedAction, environment, receivedData);
postProcessAction(action, site, application, environment);
Action action = getAction(executingRequest, processedAction, env, receivedData);
postProcessAction(action, site, app, env);
return new ResponseEntity<>(action, HttpStatus.OK);
}
protected RestRequest getInitialRequest(Site site, Application application, Environment environment,
HttpServletRequest httpServletRequest, ApplicationProvider applicationProvider) {
RestRequest initialRequest = new RestRequest();
httpServletRequest.getParameterMap().keySet().stream().filter(k -> !k.equals(FORM_ACTION)).forEach(key -> {
String[] parameterValues = httpServletRequest.getParameterValues(key);
for (String parameterValue : parameterValues) {
initialRequest.addParameter(key, parameterValue);
}
});
initRequest(site, application, environment, applicationProvider, initialRequest);
return initialRequest;
}
protected Action getAction(ApplicationRequest request, org.appng.xml.platform.Action processedAction,
Environment environment, Action receivedData) {
Action action = new Action();
@@ -164,7 +167,7 @@ protected Action getAction(ApplicationRequest request, org.appng.xml.platform.Ac
actionField.setValue(receivedData.getFields().stream()
.filter(pdf -> pdf.getName().equals(f.getName())).findFirst().get().getValue());
}
applyValidationRules(request, actionField, originalDef);
applyValidationRules(request, actionField, originalDef.get());
actionField.setMessages(getMessages(fieldDef.getMessages()));
if (isSelectionType(actionField.getFieldType())) {
@@ -194,9 +197,8 @@ protected Action getAction(ApplicationRequest request, org.appng.xml.platform.Ac
return action;
}
protected void applyValidationRules(ApplicationRequest request, ActionField actionField,
Optional<FieldDef> originalDef) {
Validation validation = originalDef.get().getValidation();
protected void applyValidationRules(ApplicationRequest request, ActionField actionField, FieldDef originalDef) {
Validation validation = originalDef.getValidation();
if (null != validation) {
actionField.setRules(new ArrayList<>());
validation.getRules().forEach(r -> {
@@ -289,21 +291,29 @@ protected void extractRequestParameters(org.appng.xml.platform.Action original,
log.debug("Parameters: {}", wrappedRequest.getParametersList());
}
RestRequest() {
initWrappedRequest();
}
protected RequestBean initWrappedRequest() {
RequestBean wrappedRequest = new RequestBean() {
@Override
public void addParameter(String key, String value) {
if (!parameters.containsKey(key)) {
log.debug("added parameter {}={}", key, value);
parameters.put(key, new ArrayList<>());
}
log.debug("added parameter {}={}", key, value);
parameters.get(key).add(value);
}
};
setWrappedRequest(wrappedRequest);
return wrappedRequest;
}
@Override
public String toString() {
return getClass().getName() + ": " + getWrappedRequest().getParametersList();
}
}
@ExceptionHandler
View
@@ -109,6 +109,7 @@
<module>appng-xmlapi</module>
<module>appng-testsupport</module>
<module>appng-api</module>
<module>appng-rest-api</module>
<module>appng-persistence</module>
<module>appng-search</module>
<module>appng-core</module>

0 comments on commit 5e236df

Please sign in to comment.