TSK-311 refactoring

This commit is contained in:
Mustapha Zorgati 2018-02-28 10:25:37 +01:00 committed by Holger Hagen
parent eaf15fd19c
commit 798e160669
29 changed files with 70 additions and 76 deletions

View File

@ -24,8 +24,8 @@ script:
- (cd admin && npm run test-phantom)
&& mvn verify -f lib/
&& mvn verify -f rest/
&& lib/deployment/deploy.sh -ik -p lib/ -m "lib/taskana-core/ lib/taskana-spring/ lib/taskana-cdi/"
&& lib/deployment/deploy.sh -pp -p rest/ -m rest/taskana-rest-spring -mf manifest.yml -swarm lib/taskana-cdi/src/test/java/pro/taskana/TaskanaProducersTest.java
&& lib/deployment/release.sh -ik -p lib/ -m "lib/taskana-core/ lib/taskana-spring/ lib/taskana-cdi/"
&& lib/deployment/release.sh -pp -p rest/ -m rest/taskana-rest-spring -mf manifest.yml -swarm lib/taskana-cdi/src/test/java/pro/taskana/TaskanaProducersTest.java
deploy:
provider: cloudfoundry
username: tobias.schaefer@novatec-gmbh.de

View File

@ -1,16 +1,16 @@
#!/bin/bash
set -e #fail fast
reqRepo="mustaphazorgati/taskana"
reqRepo="Taskana/taskana"
if [[ -z "$MANIFEST_PREFIX" ]]; then
MANIFEST_PREFIX="/rest"
MANIFEST_PREFIX="target/taskana-rest-spring-example"
fi
#H Usage:
#H deploy.sh -h | deploy.sh --help
#H release.sh -h | release.sh --help
#H
#H prints this help and exits
#H
#H deploy.sh [PARAM...]
#H release.sh [PARAM...]
#H
#H an easy deployment tool to deploy maven projects.
#H

View File

@ -1,8 +1,7 @@
# Configuration file for Cloud Foundry, see https://docs.cloudfoundry.org/devguide/deploy-apps/manifest.html
applications:
- name: taskana-rest
#TODO: path
path: rest/target/rest-0.0.8-SNAPSHOT.jar
path: rest/taskana-rest-spring-example/target/taskana-rest-spring-example-0.0.8-SNAPSHOT.jar
buildpack: https://github.com/cloudfoundry/java-buildpack.git#v3.10
memory: 512M
disk_quota: 256M

View File

@ -9,7 +9,7 @@
<packaging>jar</packaging>
<name>rest</name>
<description>Demo project for Spring Boot</description>
<description>Demo project for taskana-rest-spring</description>
<parent>
<groupId>org.springframework.boot</groupId>

View File

@ -10,8 +10,11 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.DependsOn;
import org.springframework.context.annotation.Import;
import sampledata.SampleDataGenerator;
import pro.taskana.sampledata.SampleDataGenerator;
/**
* Example Application showing the implementation of taskana-rest-spring.
*/
@SpringBootApplication
@Import(RestConfiguration.class)
public class ExampleRestApplication {

View File

@ -13,6 +13,9 @@ import javax.security.auth.spi.LoginModule;
import pro.taskana.security.GroupPrincipal;
import pro.taskana.security.UserPrincipal;
/**
* TODO.
*/
public class SampleLoginModule implements LoginModule {
private NameCallback nameCallback;
@ -45,6 +48,8 @@ public class SampleLoginModule implements LoginModule {
subject.getPrincipals()
.add(new GroupPrincipal("manager" + "_domain_" + username.charAt(0)));
break;
default:
//necessary for checkstyle
}
subject.getPrincipals().add(new GroupPrincipal("team_" + username.substring(2, 6)));
}

View File

@ -6,6 +6,9 @@ import java.util.Set;
import org.springframework.security.authentication.jaas.AuthorityGranter;
/**
* TODO.
*/
public class SampleRoleGranter implements AuthorityGranter {
@Override

View File

@ -21,6 +21,9 @@ import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
/**
* TODO.
*/
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

View File

@ -1,4 +1,4 @@
package sampledata;
package pro.taskana.sampledata;
import java.io.InputStreamReader;
import java.io.PrintWriter;
@ -11,11 +11,12 @@ import org.apache.ibatis.jdbc.ScriptRunner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* This class generates sample data for manual testing purposes.
*/
public class SampleDataGenerator {
private static final Logger logger = LoggerFactory.getLogger(SampleDataGenerator.class);
private ScriptRunner runner;
private static final Logger LOGGER = LoggerFactory.getLogger(SampleDataGenerator.class);
private static final String SQL = "/sql";
private static final String TEST_DATA = "/sample-data";
private static final String TASK = SQL + TEST_DATA + "/task.sql";
@ -24,19 +25,15 @@ public class SampleDataGenerator {
private static final String WORKBASKET_ACCESS_LIST = SQL + TEST_DATA + "/workbasket-access-list.sql";
private static final String CLASSIFICATION = SQL + TEST_DATA + "/classification.sql";
private static final String OBJECT_REFERENCE = SQL + TEST_DATA + "/object-reference.sql";
private ScriptRunner runner;
public SampleDataGenerator(DataSource dataSource) throws SQLException {
if (logger.isDebugEnabled()) {
logger.debug(dataSource.getConnection().getMetaData().toString());
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(dataSource.getConnection().getMetaData().toString());
}
runner = new ScriptRunner(dataSource.getConnection());
}
/**
* Creates sample data for manual testing purposes.
*
* @throws SQLException
*/
public void generateSampleData() throws SQLException {
StringWriter outWriter = new StringWriter();
PrintWriter logWriter = new PrintWriter(outWriter);
@ -57,9 +54,9 @@ public class SampleDataGenerator {
runner.closeConnection();
logger.debug(outWriter.toString());
LOGGER.debug(outWriter.toString());
if (!errorWriter.toString().trim().isEmpty()) {
logger.error(errorWriter.toString());
LOGGER.error(errorWriter.toString());
}
}

View File

@ -29,7 +29,7 @@ import pro.taskana.rest.resource.ClassificationResource;
import pro.taskana.rest.resource.mapper.ClassificationMapper;
/**
* TODO.
* Controller for all {@link Classification} related endpoints.
*/
@RestController
@RequestMapping(path = "/v1/classifications", produces = {MediaType.APPLICATION_JSON_VALUE})

View File

@ -29,7 +29,7 @@ import pro.taskana.rest.resource.ClassificationResource;
import pro.taskana.rest.resource.mapper.ClassificationMapper;
/**
* TODO.
* Controller for Importing / Exporting classifications.
*/
@RestController
@RequestMapping(path = "/v1/classificationdefinitions", produces = {MediaType.APPLICATION_JSON_VALUE})

View File

@ -13,7 +13,7 @@ import org.springframework.web.bind.annotation.RestController;
import pro.taskana.TaskState;
/**
* TODO.
* Controller for all monitoring endpoints.
*/
@RestController
@RequestMapping(path = "/v1/monitor", produces = {MediaType.APPLICATION_JSON_VALUE})

View File

@ -30,7 +30,7 @@ import pro.taskana.configuration.SpringTaskanaEngineConfiguration;
import pro.taskana.configuration.TaskanaEngineConfiguration;
/**
* TODO.
* Configuration for REST service.
*/
@Configuration
@ComponentScan
@ -72,7 +72,7 @@ public class RestConfiguration {
@Bean
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
public TaskanaEngine getTaskanaEngine(TaskanaEngineConfiguration taskanaEngineConfiguration) throws SQLException {
public TaskanaEngine getTaskanaEngine(TaskanaEngineConfiguration taskanaEngineConfiguration) {
return taskanaEngineConfiguration.buildTaskanaEngine();
}
@ -82,12 +82,7 @@ public class RestConfiguration {
return new SpringTaskanaEngineConfiguration(dataSource, true, true);
}
/**
* Needed to override JSON De-/Serializer in Jackson.
*
* @param handlerInstantiator
* @return
*/
// Needed to override JSON De-/Serializer in Jackson.
@Bean
public Jackson2ObjectMapperBuilder jacksonBuilder(HandlerInstantiator handlerInstantiator) {
Jackson2ObjectMapperBuilder b = new Jackson2ObjectMapperBuilder();
@ -96,12 +91,7 @@ public class RestConfiguration {
return b;
}
/**
* Needed for injection into jackson deserilizer.
*
* @param context
* @return
*/
//Needed for injection into jackson deserilizer.
@Bean
public HandlerInstantiator handlerInstantiator(ApplicationContext context) {
return new SpringHandlerInstantiator(context.getAutowireCapableBeanFactory());

View File

@ -34,7 +34,7 @@ import pro.taskana.exceptions.TaskNotFoundException;
import pro.taskana.rest.query.TaskFilter;
/**
* TODO.
* Controller for all {@link Task} related endpoints.
*/
@RestController
@RequestMapping(path = "/v1/tasks", produces = {MediaType.APPLICATION_JSON_VALUE})

View File

@ -42,7 +42,7 @@ import pro.taskana.rest.resource.mapper.WorkbasketMapper;
import pro.taskana.rest.resource.mapper.WorkbasketSummaryMapper;
/**
* TODO.
* Controller for all {@link Workbasket} related endpoints.
*/
@RestController
@RequestMapping(path = "/v1/workbaskets", produces = {MediaType.APPLICATION_JSON_VALUE})

View File

@ -35,7 +35,7 @@ import pro.taskana.rest.resource.mapper.WorkbasketDefinitionMapper;
import pro.taskana.rest.resource.mapper.WorkbasketMapper;
/**
* TODO.
* Controller for all {@link WorkbasketDefinition} related endpoints.
*/
@RestController
@RequestMapping(path = "/v1/workbasketdefinitions", produces = {MediaType.APPLICATION_JSON_VALUE})
@ -85,8 +85,6 @@ public class WorkbasketDefinitionController {
* the list of workbasket definitions which will be imported to the current system.
* @return Return answer is determined by the status code: 200 - all good 400 - list state error (referring to non
* existing id's) 401 - not authorized
* @throws InvalidArgumentException
* When the pre-conditions of a workbasket doesn´t match.
*/
@PostMapping(path = "/import")
@Transactional(rollbackFor = Exception.class)

View File

@ -3,7 +3,7 @@ package pro.taskana.rest.resource;
import org.springframework.hateoas.ResourceSupport;
/**
* TODO.
* Resource class for {@link pro.taskana.Classification}.
*/
public class ClassificationResource extends ResourceSupport {

View File

@ -5,7 +5,7 @@ import javax.validation.constraints.NotNull;
import org.springframework.hateoas.ResourceSupport;
/**
* TODO.
* Resource class for {@link pro.taskana.WorkbasketAccessItem}.
*/
public class WorkbasketAccessItemResource extends ResourceSupport {

View File

@ -7,7 +7,7 @@ import org.springframework.hateoas.ResourceSupport;
import pro.taskana.impl.WorkbasketType;
/**
* TODO.
* Resource class for {@link pro.taskana.Workbasket}.
*/
public class WorkbasketResource extends ResourceSupport {

View File

@ -7,7 +7,7 @@ import org.springframework.hateoas.ResourceSupport;
import pro.taskana.impl.WorkbasketType;
/**
* TODO.
* Resource class for {@link pro.taskana.WorkbasketSummary}.
*/
public class WorkbasketSummaryResource extends ResourceSupport {

View File

@ -17,7 +17,7 @@ import pro.taskana.rest.ClassificationController;
import pro.taskana.rest.resource.ClassificationResource;
/**
* TODO.
* Transforms {@link Classification} to its resource counterpart {@link ClassificationResource} and vice versa.
*/
@Component
public class ClassificationMapper {

View File

@ -3,7 +3,7 @@ package pro.taskana.rest.resource.mapper;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
import java.util.Arrays;
import java.util.Collections;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -17,7 +17,7 @@ import pro.taskana.rest.WorkbasketController;
import pro.taskana.rest.resource.WorkbasketAccessItemResource;
/**
* TODO.
* Transforms {@link WorkbasketAccessItem} to its resource counterpart {@link WorkbasketAccessItemResource} and vice versa.
*/
@Component
public class WorkbasketAccessItemMapper {
@ -43,7 +43,7 @@ public class WorkbasketAccessItemMapper {
return wbAccItemModel;
}
WorkbasketAccessItemResource addLinks(WorkbasketAccessItemResource resource, WorkbasketAccessItem wbAccItem)
private WorkbasketAccessItemResource addLinks(WorkbasketAccessItemResource resource, WorkbasketAccessItem wbAccItem)
throws NotAuthorizedException {
resource.add(
linkTo(methodOn(WorkbasketController.class).getWorkbasketAccessItems(wbAccItem.getWorkbasketId()))
@ -56,8 +56,8 @@ public class WorkbasketAccessItemMapper {
.withRel("updateWorkbasketAccessItem"));
resource.add(
linkTo(methodOn(WorkbasketController.class).setWorkbasketAccessItems(wbAccItem.getWorkbasketId(),
Arrays.asList(resource)))
.withRel("setWorkbasketAccessItems"));
Collections.singletonList(resource)))
.withRel("setWorkbasketAuthorizations"));
resource.add(
linkTo(methodOn(WorkbasketController.class).deleteWorkbasketAccessItem(wbAccItem.getId()))
.withRel("deleteWorkbasketAccessItem"));

View File

@ -4,7 +4,7 @@ import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@ -13,6 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import pro.taskana.Workbasket;
import pro.taskana.WorkbasketAccessItem;
import pro.taskana.WorkbasketService;
import pro.taskana.WorkbasketSummary;
import pro.taskana.exceptions.NotAuthorizedException;
@ -22,7 +23,8 @@ import pro.taskana.rest.resource.WorkbasketAccessItemResource;
import pro.taskana.rest.resource.WorkbasketDefinition;
/**
* TODO.
* Transforms {@link Workbasket} into a {@link WorkbasketDefinition}
* containing all additional information about that workbasket.
*/
@Component
public class WorkbasketDefinitionMapper {
@ -41,7 +43,7 @@ public class WorkbasketDefinitionMapper {
*
* @param basket
* {@link Workbasket} which will be converted
* @return a {@link WorkbasketDefinition}, containing the {@code basket}, its ditribution targets and its
* @return a {@link WorkbasketDefinition}, containing the {@code basket}, its distribution targets and its
* authorizations
* @throws NotAuthorizedException
* if the user is not authorized
@ -51,16 +53,9 @@ public class WorkbasketDefinitionMapper {
public WorkbasketDefinition toResource(Workbasket basket)
throws NotAuthorizedException, WorkbasketNotFoundException {
List<WorkbasketAccessItemResource> authorizations = new ArrayList<>();
workbasketService.getWorkbasketAccessItems(
basket.getKey())
.stream()
.forEach(t -> {
try {
authorizations.add(workbasketAccessItemMapper.toResource(t));
} catch (NotAuthorizedException e) {
e.printStackTrace();
for (WorkbasketAccessItem accessItem : workbasketService.getWorkbasketAccessItems(basket.getKey())) {
authorizations.add(workbasketAccessItemMapper.toResource(accessItem));
}
});
Set<String> distroTargets = workbasketService.getDistributionTargets(basket.getId())
.stream()
.map(WorkbasketSummary::getId)
@ -75,7 +70,8 @@ public class WorkbasketDefinitionMapper {
linkTo(methodOn(WorkbasketDefinitionController.class).exportWorkbaskets(workbasket.getDomain()))
.withRel("exportWorkbaskets"));
resource.add(
linkTo(methodOn(WorkbasketDefinitionController.class).importWorkbaskets(Arrays.asList(resource)))
linkTo(
methodOn(WorkbasketDefinitionController.class).importWorkbaskets(Collections.singletonList(resource)))
.withRel("importWorkbaskets"));
return resource;
}

View File

@ -17,7 +17,7 @@ import pro.taskana.rest.WorkbasketController;
import pro.taskana.rest.resource.WorkbasketResource;
/**
* TODO.
* Transforms {@link Workbasket} to its resource counterpart {@link WorkbasketResource} and vice versa.
*/
@Component
public class WorkbasketMapper {

View File

@ -11,7 +11,7 @@ import pro.taskana.rest.WorkbasketController;
import pro.taskana.rest.resource.WorkbasketSummaryResource;
/**
* TODO.
* Transforms {@link WorkbasketSummary} to its resource counterpart {@link WorkbasketSummaryResource} and vice versa.
*/
@Component
public class WorkbasketSummaryMapper {

View File

@ -18,7 +18,7 @@ import pro.taskana.rest.RestConfiguration;
import pro.taskana.rest.resource.ClassificationResource;
/**
* TODO.
* Test for {@link ClassificationMapper}.
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {RestConfiguration.class})

View File

@ -15,7 +15,7 @@ import pro.taskana.rest.RestConfiguration;
import pro.taskana.rest.resource.WorkbasketAccessItemResource;
/**
* TODO.
* Test for {@link WorkbasketAccessItemMapper}.
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {RestConfiguration.class})

View File

@ -19,7 +19,7 @@ import pro.taskana.rest.RestConfiguration;
import pro.taskana.rest.resource.WorkbasketResource;
/**
* TODO.
* Test for {@link WorkbasketMapper}.
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {RestConfiguration.class})

View File

@ -15,7 +15,7 @@ import pro.taskana.rest.RestConfiguration;
import pro.taskana.rest.resource.WorkbasketSummaryResource;
/**
* TODO.
* Test for {@link WorkbasketSummaryMapper}.
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {RestConfiguration.class})