TSK-1031: removed unnecessary throws statements
This commit is contained in:
parent
448d4fb8fc
commit
e6f8883e49
|
@ -1,149 +1,146 @@
|
||||||
package pro.taskana.common.internal.jobs;
|
package pro.taskana.common.internal.jobs;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import pro.taskana.common.api.BaseQuery;
|
import pro.taskana.common.api.BaseQuery;
|
||||||
import pro.taskana.common.api.BulkOperationResults;
|
import pro.taskana.common.api.BulkOperationResults;
|
||||||
import pro.taskana.common.api.ScheduledJob;
|
import pro.taskana.common.api.ScheduledJob;
|
||||||
import pro.taskana.common.api.TaskanaEngine;
|
import pro.taskana.common.api.TaskanaEngine;
|
||||||
import pro.taskana.common.api.exceptions.InvalidArgumentException;
|
import pro.taskana.common.api.exceptions.InvalidArgumentException;
|
||||||
import pro.taskana.common.api.exceptions.NotAuthorizedException;
|
import pro.taskana.common.api.exceptions.NotAuthorizedException;
|
||||||
import pro.taskana.common.api.exceptions.TaskanaException;
|
import pro.taskana.common.api.exceptions.TaskanaException;
|
||||||
import pro.taskana.common.internal.transaction.TaskanaTransactionProvider;
|
import pro.taskana.common.internal.transaction.TaskanaTransactionProvider;
|
||||||
import pro.taskana.workbasket.api.WorkbasketQueryColumnName;
|
import pro.taskana.workbasket.api.WorkbasketQueryColumnName;
|
||||||
import pro.taskana.workbasket.api.exceptions.WorkbasketInUseException;
|
|
||||||
import pro.taskana.workbasket.api.exceptions.WorkbasketNotFoundException;
|
/**
|
||||||
|
* Job to cleanup completed workbaskets after a period of time if there are no pending tasks
|
||||||
/**
|
* associated to the workbasket.
|
||||||
* Job to cleanup completed workbaskets after a period of time if there are no pending tasks
|
*/
|
||||||
* associated to the workbasket.
|
public class WorkbasketCleanupJob extends AbstractTaskanaJob {
|
||||||
*/
|
|
||||||
public class WorkbasketCleanupJob extends AbstractTaskanaJob {
|
private static final Logger LOGGER = LoggerFactory.getLogger(WorkbasketCleanupJob.class);
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(WorkbasketCleanupJob.class);
|
// Parameter
|
||||||
|
private Instant firstRun;
|
||||||
// Parameter
|
private Duration runEvery;
|
||||||
private Instant firstRun;
|
private int batchSize;
|
||||||
private Duration runEvery;
|
|
||||||
private int batchSize;
|
public WorkbasketCleanupJob(
|
||||||
|
TaskanaEngine taskanaEngine,
|
||||||
public WorkbasketCleanupJob(
|
TaskanaTransactionProvider<Object> txProvider,
|
||||||
TaskanaEngine taskanaEngine,
|
ScheduledJob job) {
|
||||||
TaskanaTransactionProvider<Object> txProvider,
|
super(taskanaEngine, txProvider, job);
|
||||||
ScheduledJob job) {
|
firstRun = taskanaEngine.getConfiguration().getCleanupJobFirstRun();
|
||||||
super(taskanaEngine, txProvider, job);
|
runEvery = taskanaEngine.getConfiguration().getCleanupJobRunEvery();
|
||||||
firstRun = taskanaEngine.getConfiguration().getCleanupJobFirstRun();
|
batchSize = taskanaEngine.getConfiguration().getMaxNumberOfUpdatesPerTransaction();
|
||||||
runEvery = taskanaEngine.getConfiguration().getCleanupJobRunEvery();
|
}
|
||||||
batchSize = taskanaEngine.getConfiguration().getMaxNumberOfUpdatesPerTransaction();
|
|
||||||
}
|
@Override
|
||||||
|
public void run() throws TaskanaException {
|
||||||
@Override
|
LOGGER.info("Running job to delete all workbaskets marked for deletion");
|
||||||
public void run() throws TaskanaException {
|
try {
|
||||||
LOGGER.info("Running job to delete all workbaskets marked for deletion");
|
List<String> workbasketsMarkedForDeletion = getWorkbasketsMarkedForDeletion();
|
||||||
try {
|
int totalNumberOfWorkbasketDeleted = 0;
|
||||||
List<String> workbasketsMarkedForDeletion = getWorkbasketsMarkedForDeletion();
|
while (workbasketsMarkedForDeletion.size() > 0) {
|
||||||
int totalNumberOfWorkbasketDeleted = 0;
|
int upperLimit = batchSize;
|
||||||
while (workbasketsMarkedForDeletion.size() > 0) {
|
if (upperLimit > workbasketsMarkedForDeletion.size()) {
|
||||||
int upperLimit = batchSize;
|
upperLimit = workbasketsMarkedForDeletion.size();
|
||||||
if (upperLimit > workbasketsMarkedForDeletion.size()) {
|
}
|
||||||
upperLimit = workbasketsMarkedForDeletion.size();
|
totalNumberOfWorkbasketDeleted +=
|
||||||
}
|
deleteWorkbasketsTransactionally(workbasketsMarkedForDeletion.subList(0, upperLimit));
|
||||||
totalNumberOfWorkbasketDeleted +=
|
workbasketsMarkedForDeletion.subList(0, upperLimit).clear();
|
||||||
deleteWorkbasketsTransactionally(workbasketsMarkedForDeletion.subList(0, upperLimit));
|
}
|
||||||
workbasketsMarkedForDeletion.subList(0, upperLimit).clear();
|
LOGGER.info(
|
||||||
}
|
"Job ended successfully. {} workbaskets deleted.", totalNumberOfWorkbasketDeleted);
|
||||||
LOGGER.info(
|
} catch (Exception e) {
|
||||||
"Job ended successfully. {} workbaskets deleted.", totalNumberOfWorkbasketDeleted);
|
throw new TaskanaException("Error while processing WorkbasketCleanupJob.", e);
|
||||||
} catch (Exception e) {
|
} finally {
|
||||||
throw new TaskanaException("Error while processing WorkbasketCleanupJob.", e);
|
scheduleNextCleanupJob();
|
||||||
} finally {
|
}
|
||||||
scheduleNextCleanupJob();
|
}
|
||||||
}
|
|
||||||
}
|
/**
|
||||||
|
* Initializes the WorkbasketCleanupJob schedule. <br>
|
||||||
/**
|
* All scheduled cleanup jobs are cancelled/deleted and a new one is scheduled.
|
||||||
* Initializes the WorkbasketCleanupJob schedule. <br>
|
*
|
||||||
* All scheduled cleanup jobs are cancelled/deleted and a new one is scheduled.
|
* @param taskanaEngine the taskana engine
|
||||||
*
|
*/
|
||||||
* @param taskanaEngine the taskana engine
|
public static void initializeSchedule(TaskanaEngine taskanaEngine) {
|
||||||
*/
|
WorkbasketCleanupJob job = new WorkbasketCleanupJob(taskanaEngine, null, null);
|
||||||
public static void initializeSchedule(TaskanaEngine taskanaEngine) {
|
job.scheduleNextCleanupJob();
|
||||||
WorkbasketCleanupJob job = new WorkbasketCleanupJob(taskanaEngine, null, null);
|
}
|
||||||
job.scheduleNextCleanupJob();
|
|
||||||
}
|
private List<String> getWorkbasketsMarkedForDeletion() {
|
||||||
|
List<String> workbasketList =
|
||||||
private List<String> getWorkbasketsMarkedForDeletion() {
|
taskanaEngineImpl
|
||||||
List<String> workbasketList =
|
.getWorkbasketService()
|
||||||
taskanaEngineImpl
|
.createWorkbasketQuery()
|
||||||
.getWorkbasketService()
|
.markedForDeletion(true)
|
||||||
.createWorkbasketQuery()
|
.listValues(WorkbasketQueryColumnName.ID, BaseQuery.SortDirection.ASCENDING);
|
||||||
.markedForDeletion(true)
|
|
||||||
.listValues(WorkbasketQueryColumnName.ID, BaseQuery.SortDirection.ASCENDING);
|
return workbasketList;
|
||||||
|
}
|
||||||
return workbasketList;
|
|
||||||
}
|
private int deleteWorkbasketsTransactionally(List<String> workbasketsToBeDeleted) {
|
||||||
|
int deletedWorkbasketsCount = 0;
|
||||||
private int deleteWorkbasketsTransactionally(List<String> workbasketsToBeDeleted) {
|
if (txProvider != null) {
|
||||||
int deletedWorkbasketsCount = 0;
|
int count =
|
||||||
if (txProvider != null) {
|
(Integer)
|
||||||
int count =
|
txProvider.executeInTransaction(
|
||||||
(Integer)
|
() -> {
|
||||||
txProvider.executeInTransaction(
|
try {
|
||||||
() -> {
|
return deleteWorkbaskets(workbasketsToBeDeleted);
|
||||||
try {
|
} catch (Exception e) {
|
||||||
return deleteWorkbaskets(workbasketsToBeDeleted);
|
LOGGER.warn("Could not delete workbaskets.", e);
|
||||||
} catch (Exception e) {
|
return 0;
|
||||||
LOGGER.warn("Could not delete workbaskets.", e);
|
}
|
||||||
return 0;
|
});
|
||||||
}
|
return count;
|
||||||
});
|
} else {
|
||||||
return count;
|
try {
|
||||||
} else {
|
deletedWorkbasketsCount = deleteWorkbaskets(workbasketsToBeDeleted);
|
||||||
try {
|
} catch (Exception e) {
|
||||||
deletedWorkbasketsCount = deleteWorkbaskets(workbasketsToBeDeleted);
|
LOGGER.warn("Could not delete workbaskets.", e);
|
||||||
} catch (Exception e) {
|
}
|
||||||
LOGGER.warn("Could not delete workbaskets.", e);
|
}
|
||||||
}
|
return deletedWorkbasketsCount;
|
||||||
}
|
}
|
||||||
return deletedWorkbasketsCount;
|
|
||||||
}
|
private int deleteWorkbaskets(List<String> workbasketsToBeDeleted)
|
||||||
|
throws InvalidArgumentException, NotAuthorizedException {
|
||||||
private int deleteWorkbaskets(List<String> workbasketsToBeDeleted)
|
|
||||||
throws InvalidArgumentException, NotAuthorizedException, WorkbasketNotFoundException,
|
BulkOperationResults<String, TaskanaException> results =
|
||||||
WorkbasketInUseException {
|
taskanaEngineImpl.getWorkbasketService().deleteWorkbaskets(workbasketsToBeDeleted);
|
||||||
|
LOGGER.debug(
|
||||||
BulkOperationResults<String, TaskanaException> results =
|
"{} workbasket deleted.", workbasketsToBeDeleted.size() - results.getFailedIds().size());
|
||||||
taskanaEngineImpl.getWorkbasketService().deleteWorkbaskets(workbasketsToBeDeleted);
|
for (String failedId : results.getFailedIds()) {
|
||||||
LOGGER.debug(
|
LOGGER.warn(
|
||||||
"{} workbasket deleted.", workbasketsToBeDeleted.size() - results.getFailedIds().size());
|
"Workbasket with id {} could not be deleted. Reason: {}",
|
||||||
for (String failedId : results.getFailedIds()) {
|
failedId,
|
||||||
LOGGER.warn(
|
results.getErrorForId(failedId));
|
||||||
"Workbasket with id {} could not be deleted. Reason: {}",
|
}
|
||||||
failedId,
|
return workbasketsToBeDeleted.size() - results.getFailedIds().size();
|
||||||
results.getErrorForId(failedId));
|
}
|
||||||
}
|
|
||||||
return workbasketsToBeDeleted.size() - results.getFailedIds().size();
|
private void scheduleNextCleanupJob() {
|
||||||
}
|
LOGGER.debug("Entry to scheduleNextCleanupJob.");
|
||||||
|
ScheduledJob job = new ScheduledJob();
|
||||||
private void scheduleNextCleanupJob() {
|
job.setType(ScheduledJob.Type.WORKBASKETCLEANUPJOB);
|
||||||
LOGGER.debug("Entry to scheduleNextCleanupJob.");
|
job.setDue(getNextDueForWorkbasketCleanupJob());
|
||||||
ScheduledJob job = new ScheduledJob();
|
taskanaEngineImpl.getJobService().createJob(job);
|
||||||
job.setType(ScheduledJob.Type.WORKBASKETCLEANUPJOB);
|
LOGGER.debug("Exit from scheduleNextCleanupJob.");
|
||||||
job.setDue(getNextDueForWorkbasketCleanupJob());
|
}
|
||||||
taskanaEngineImpl.getJobService().createJob(job);
|
|
||||||
LOGGER.debug("Exit from scheduleNextCleanupJob.");
|
private Instant getNextDueForWorkbasketCleanupJob() {
|
||||||
}
|
Instant nextRunAt = firstRun;
|
||||||
|
while (nextRunAt.isBefore(Instant.now())) {
|
||||||
private Instant getNextDueForWorkbasketCleanupJob() {
|
nextRunAt = nextRunAt.plus(runEvery);
|
||||||
Instant nextRunAt = firstRun;
|
}
|
||||||
while (nextRunAt.isBefore(Instant.now())) {
|
LOGGER.info("Scheduling next run of the WorkbasketCleanupJob for {}", nextRunAt);
|
||||||
nextRunAt = nextRunAt.plus(runEvery);
|
return nextRunAt;
|
||||||
}
|
}
|
||||||
LOGGER.info("Scheduling next run of the WorkbasketCleanupJob for {}", nextRunAt);
|
}
|
||||||
return nextRunAt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,74 +1,73 @@
|
||||||
package pro.taskana.rest;
|
package pro.taskana.rest;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.annotation.PostConstruct;
|
import javax.sql.DataSource;
|
||||||
import javax.sql.DataSource;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.DependsOn;
|
||||||
import org.springframework.context.annotation.DependsOn;
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
import org.springframework.transaction.PlatformTransactionManager;
|
||||||
import org.springframework.transaction.PlatformTransactionManager;
|
|
||||||
|
import pro.taskana.jobs.TransactionalJobsConfiguration;
|
||||||
import pro.taskana.jobs.TransactionalJobsConfiguration;
|
import pro.taskana.ldap.LdapCacheTestImpl;
|
||||||
import pro.taskana.ldap.LdapCacheTestImpl;
|
import pro.taskana.ldap.LdapClient;
|
||||||
import pro.taskana.ldap.LdapClient;
|
import pro.taskana.ldap.LdapConfiguration;
|
||||||
import pro.taskana.ldap.LdapConfiguration;
|
import pro.taskana.sampledata.SampleDataGenerator;
|
||||||
import pro.taskana.sampledata.SampleDataGenerator;
|
|
||||||
|
/** Example Application showing the implementation of taskana-rest-spring. */
|
||||||
/** Example Application showing the implementation of taskana-rest-spring. */
|
@SpringBootApplication
|
||||||
@SpringBootApplication
|
@EnableScheduling
|
||||||
@EnableScheduling
|
@ComponentScan(basePackages = "pro.taskana")
|
||||||
@ComponentScan(basePackages = "pro.taskana")
|
@SuppressWarnings("checkstyle:Indentation")
|
||||||
@SuppressWarnings("checkstyle:Indentation")
|
@Import({
|
||||||
@Import({
|
TransactionalJobsConfiguration.class,
|
||||||
TransactionalJobsConfiguration.class,
|
LdapConfiguration.class,
|
||||||
LdapConfiguration.class,
|
RestConfiguration.class,
|
||||||
RestConfiguration.class,
|
WebMvcConfig.class
|
||||||
WebMvcConfig.class
|
})
|
||||||
})
|
public class ExampleRestApplication {
|
||||||
public class ExampleRestApplication {
|
|
||||||
|
@Value("${taskana.schemaName:TASKANA}")
|
||||||
@Value("${taskana.schemaName:TASKANA}")
|
public String schemaName;
|
||||||
public String schemaName;
|
|
||||||
|
@Value("${generateSampleData:true}")
|
||||||
@Value("${generateSampleData:true}")
|
public boolean generateSampleData;
|
||||||
public boolean generateSampleData;
|
|
||||||
|
@Autowired private SampleDataGenerator sampleDataGenerator;
|
||||||
@Autowired private SampleDataGenerator sampleDataGenerator;
|
|
||||||
|
@Autowired private LdapClient ldapClient;
|
||||||
@Autowired private LdapClient ldapClient;
|
|
||||||
|
@Autowired private LdapCacheTestImpl ldapCacheTest;
|
||||||
@Autowired private LdapCacheTestImpl ldapCacheTest;
|
|
||||||
|
public static void main(String[] args) {
|
||||||
public static void main(String[] args) {
|
SpringApplication.run(ExampleRestApplication.class, args);
|
||||||
SpringApplication.run(ExampleRestApplication.class, args);
|
}
|
||||||
}
|
|
||||||
|
@Bean
|
||||||
@Bean
|
public PlatformTransactionManager txManager(DataSource dataSource) {
|
||||||
public PlatformTransactionManager txManager(DataSource dataSource) {
|
return new DataSourceTransactionManager(dataSource);
|
||||||
return new DataSourceTransactionManager(dataSource);
|
}
|
||||||
}
|
|
||||||
|
@Bean
|
||||||
@Bean
|
@DependsOn("getTaskanaEngine") // generate sample data after schema was inserted
|
||||||
@DependsOn("getTaskanaEngine") // generate sample data after schema was inserted
|
public SampleDataGenerator generateSampleData(DataSource dataSource) {
|
||||||
public SampleDataGenerator generateSampleData(DataSource dataSource) {
|
sampleDataGenerator = new SampleDataGenerator(dataSource, schemaName);
|
||||||
sampleDataGenerator = new SampleDataGenerator(dataSource, schemaName);
|
return sampleDataGenerator;
|
||||||
return sampleDataGenerator;
|
}
|
||||||
}
|
|
||||||
|
@PostConstruct
|
||||||
@PostConstruct
|
private void init() {
|
||||||
private void init() throws SQLException {
|
if (!ldapClient.useLdap()) {
|
||||||
if (!ldapClient.useLdap()) {
|
AccessIdController.setLdapCache(ldapCacheTest);
|
||||||
AccessIdController.setLdapCache(ldapCacheTest);
|
}
|
||||||
}
|
if (generateSampleData) {
|
||||||
if (generateSampleData) {
|
sampleDataGenerator.generateSampleData();
|
||||||
sampleDataGenerator.generateSampleData();
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -1,74 +1,73 @@
|
||||||
package pro.taskana.rest;
|
package pro.taskana.rest;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.annotation.PostConstruct;
|
import javax.sql.DataSource;
|
||||||
import javax.sql.DataSource;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.DependsOn;
|
||||||
import org.springframework.context.annotation.DependsOn;
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
import org.springframework.transaction.PlatformTransactionManager;
|
||||||
import org.springframework.transaction.PlatformTransactionManager;
|
|
||||||
|
import pro.taskana.jobs.TransactionalJobsConfiguration;
|
||||||
import pro.taskana.jobs.TransactionalJobsConfiguration;
|
import pro.taskana.ldap.LdapCacheTestImpl;
|
||||||
import pro.taskana.ldap.LdapCacheTestImpl;
|
import pro.taskana.ldap.LdapClient;
|
||||||
import pro.taskana.ldap.LdapClient;
|
import pro.taskana.ldap.LdapConfiguration;
|
||||||
import pro.taskana.ldap.LdapConfiguration;
|
import pro.taskana.sampledata.SampleDataGenerator;
|
||||||
import pro.taskana.sampledata.SampleDataGenerator;
|
|
||||||
|
/** Example Application showing the implementation of taskana-rest-spring. */
|
||||||
/** Example Application showing the implementation of taskana-rest-spring. */
|
@SpringBootApplication
|
||||||
@SpringBootApplication
|
@EnableScheduling
|
||||||
@EnableScheduling
|
@ComponentScan(basePackages = "pro.taskana")
|
||||||
@ComponentScan(basePackages = "pro.taskana")
|
@SuppressWarnings("checkstyle:Indentation")
|
||||||
@SuppressWarnings("checkstyle:Indentation")
|
@Import({
|
||||||
@Import({
|
TransactionalJobsConfiguration.class,
|
||||||
TransactionalJobsConfiguration.class,
|
LdapConfiguration.class,
|
||||||
LdapConfiguration.class,
|
RestConfiguration.class,
|
||||||
RestConfiguration.class,
|
WebMvcConfig.class
|
||||||
WebMvcConfig.class
|
})
|
||||||
})
|
public class ExampleRestApplication {
|
||||||
public class ExampleRestApplication {
|
|
||||||
|
@Value("${taskana.schemaName:TASKANA}")
|
||||||
@Value("${taskana.schemaName:TASKANA}")
|
public String schemaName;
|
||||||
public String schemaName;
|
|
||||||
|
@Value("${generateSampleData:true}")
|
||||||
@Value("${generateSampleData:true}")
|
public boolean generateSampleData;
|
||||||
public boolean generateSampleData;
|
|
||||||
|
@Autowired private SampleDataGenerator sampleDataGenerator;
|
||||||
@Autowired private SampleDataGenerator sampleDataGenerator;
|
|
||||||
|
@Autowired private LdapClient ldapClient;
|
||||||
@Autowired private LdapClient ldapClient;
|
|
||||||
|
@Autowired private LdapCacheTestImpl ldapCacheTest;
|
||||||
@Autowired private LdapCacheTestImpl ldapCacheTest;
|
|
||||||
|
public static void main(String[] args) {
|
||||||
public static void main(String[] args) {
|
SpringApplication.run(ExampleRestApplication.class, args);
|
||||||
SpringApplication.run(ExampleRestApplication.class, args);
|
}
|
||||||
}
|
|
||||||
|
@Bean
|
||||||
@Bean
|
public PlatformTransactionManager txManager(DataSource dataSource) {
|
||||||
public PlatformTransactionManager txManager(DataSource dataSource) {
|
return new DataSourceTransactionManager(dataSource);
|
||||||
return new DataSourceTransactionManager(dataSource);
|
}
|
||||||
}
|
|
||||||
|
@Bean
|
||||||
@Bean
|
@DependsOn("getTaskanaEngine") // generate sample data after schema was inserted
|
||||||
@DependsOn("getTaskanaEngine") // generate sample data after schema was inserted
|
public SampleDataGenerator generateSampleData(DataSource dataSource) {
|
||||||
public SampleDataGenerator generateSampleData(DataSource dataSource) {
|
sampleDataGenerator = new SampleDataGenerator(dataSource, schemaName);
|
||||||
sampleDataGenerator = new SampleDataGenerator(dataSource, schemaName);
|
return sampleDataGenerator;
|
||||||
return sampleDataGenerator;
|
}
|
||||||
}
|
|
||||||
|
@PostConstruct
|
||||||
@PostConstruct
|
private void init() {
|
||||||
private void init() throws SQLException {
|
if (!ldapClient.useLdap()) {
|
||||||
if (!ldapClient.useLdap()) {
|
AccessIdController.setLdapCache(ldapCacheTest);
|
||||||
AccessIdController.setLdapCache(ldapCacheTest);
|
}
|
||||||
}
|
if (generateSampleData) {
|
||||||
if (generateSampleData) {
|
sampleDataGenerator.generateSampleData();
|
||||||
sampleDataGenerator.generateSampleData();
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -1,122 +1,121 @@
|
||||||
package pro.taskana;
|
package pro.taskana;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.sql.SQLException;
|
import java.util.Properties;
|
||||||
import java.util.Properties;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.annotation.PostConstruct;
|
import javax.naming.Context;
|
||||||
import javax.naming.Context;
|
import javax.naming.InitialContext;
|
||||||
import javax.naming.InitialContext;
|
import javax.sql.DataSource;
|
||||||
import javax.sql.DataSource;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
|
||||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.DependsOn;
|
||||||
import org.springframework.context.annotation.DependsOn;
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Primary;
|
||||||
import org.springframework.context.annotation.Primary;
|
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
import org.springframework.transaction.PlatformTransactionManager;
|
||||||
import org.springframework.transaction.PlatformTransactionManager;
|
|
||||||
|
import pro.taskana.jobs.TransactionalJobsConfiguration;
|
||||||
import pro.taskana.jobs.TransactionalJobsConfiguration;
|
import pro.taskana.ldap.LdapCacheTestImpl;
|
||||||
import pro.taskana.ldap.LdapCacheTestImpl;
|
import pro.taskana.ldap.LdapClient;
|
||||||
import pro.taskana.ldap.LdapClient;
|
import pro.taskana.ldap.LdapConfiguration;
|
||||||
import pro.taskana.ldap.LdapConfiguration;
|
import pro.taskana.rest.AccessIdController;
|
||||||
import pro.taskana.rest.AccessIdController;
|
import pro.taskana.rest.RestConfiguration;
|
||||||
import pro.taskana.rest.RestConfiguration;
|
import pro.taskana.rest.WebMvcConfig;
|
||||||
import pro.taskana.rest.WebMvcConfig;
|
import pro.taskana.sampledata.SampleDataGenerator;
|
||||||
import pro.taskana.sampledata.SampleDataGenerator;
|
|
||||||
|
/**
|
||||||
/**
|
* Example Application showing the implementation of taskana-rest-spring for jboss application
|
||||||
* Example Application showing the implementation of taskana-rest-spring for jboss application
|
* server.
|
||||||
* server.
|
*/
|
||||||
*/
|
@SpringBootApplication
|
||||||
@SpringBootApplication
|
@EnableScheduling
|
||||||
@EnableScheduling
|
@SuppressWarnings("checkstyle:Indentation")
|
||||||
@SuppressWarnings("checkstyle:Indentation")
|
@Import({
|
||||||
@Import({
|
TransactionalJobsConfiguration.class,
|
||||||
TransactionalJobsConfiguration.class,
|
LdapConfiguration.class,
|
||||||
LdapConfiguration.class,
|
RestConfiguration.class,
|
||||||
RestConfiguration.class,
|
WebMvcConfig.class
|
||||||
WebMvcConfig.class
|
})
|
||||||
})
|
public class TaskanaWildFlyApplication extends SpringBootServletInitializer {
|
||||||
public class TaskanaWildFlyApplication extends SpringBootServletInitializer {
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(TaskanaWildFlyApplication.class);
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(TaskanaWildFlyApplication.class);
|
|
||||||
|
@Value("${taskana.schemaName:TASKANA}")
|
||||||
@Value("${taskana.schemaName:TASKANA}")
|
public String schemaName;
|
||||||
public String schemaName;
|
|
||||||
|
@Value("${generateSampleData:true}")
|
||||||
@Value("${generateSampleData:true}")
|
public boolean generateSampleData;
|
||||||
public boolean generateSampleData;
|
|
||||||
|
@Autowired private SampleDataGenerator sampleDataGenerator;
|
||||||
@Autowired private SampleDataGenerator sampleDataGenerator;
|
|
||||||
|
@Autowired private LdapClient ldapClient;
|
||||||
@Autowired private LdapClient ldapClient;
|
|
||||||
|
@Autowired private LdapCacheTestImpl ldapCacheTest;
|
||||||
@Autowired private LdapCacheTestImpl ldapCacheTest;
|
|
||||||
|
public static void main(String[] args) {
|
||||||
public static void main(String[] args) {
|
SpringApplication.run(TaskanaWildFlyApplication.class, args);
|
||||||
SpringApplication.run(TaskanaWildFlyApplication.class, args);
|
}
|
||||||
}
|
|
||||||
|
@Bean
|
||||||
@Bean
|
@Primary
|
||||||
@Primary
|
@ConfigurationProperties(prefix = "datasource")
|
||||||
@ConfigurationProperties(prefix = "datasource")
|
public DataSourceProperties dataSourceProperties() {
|
||||||
public DataSourceProperties dataSourceProperties() {
|
DataSourceProperties props = new DataSourceProperties();
|
||||||
DataSourceProperties props = new DataSourceProperties();
|
props.setUrl(
|
||||||
props.setUrl(
|
"jdbc:h2:mem:taskana;IGNORECASE=TRUE;LOCK_MODE=0;INIT=CREATE SCHEMA IF NOT EXISTS "
|
||||||
"jdbc:h2:mem:taskana;IGNORECASE=TRUE;LOCK_MODE=0;INIT=CREATE SCHEMA IF NOT EXISTS "
|
+ schemaName);
|
||||||
+ schemaName);
|
return props;
|
||||||
return props;
|
}
|
||||||
}
|
|
||||||
|
@Bean
|
||||||
@Bean
|
public DataSource dataSource(DataSourceProperties dsProperties) {
|
||||||
public DataSource dataSource(DataSourceProperties dsProperties) {
|
// First try to load Properties and get Datasource via jndi lookup
|
||||||
// First try to load Properties and get Datasource via jndi lookup
|
Context ctx;
|
||||||
Context ctx;
|
DataSource dataSource;
|
||||||
DataSource dataSource;
|
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
|
||||||
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
|
try (InputStream propertyStream = classloader.getResourceAsStream("application.properties")) {
|
||||||
try (InputStream propertyStream = classloader.getResourceAsStream("application.properties")) {
|
Properties properties = new Properties();
|
||||||
Properties properties = new Properties();
|
ctx = new InitialContext();
|
||||||
ctx = new InitialContext();
|
properties.load(propertyStream);
|
||||||
properties.load(propertyStream);
|
dataSource = (DataSource) ctx.lookup(properties.getProperty("datasource.jndi"));
|
||||||
dataSource = (DataSource) ctx.lookup(properties.getProperty("datasource.jndi"));
|
return dataSource;
|
||||||
return dataSource;
|
} catch (Exception e) {
|
||||||
} catch (Exception e) {
|
LOGGER.error(
|
||||||
LOGGER.error(
|
"Caught exception {} when attempting to start Taskana with Datasource "
|
||||||
"Caught exception {} when attempting to start Taskana with Datasource "
|
+ "from Jndi. Using default H2 datasource. ",
|
||||||
+ "from Jndi. Using default H2 datasource. ",
|
e);
|
||||||
e);
|
return dsProperties.initializeDataSourceBuilder().build();
|
||||||
return dsProperties.initializeDataSourceBuilder().build();
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@Bean
|
||||||
@Bean
|
public PlatformTransactionManager txManager(DataSource dataSource) {
|
||||||
public PlatformTransactionManager txManager(DataSource dataSource) {
|
return new DataSourceTransactionManager(dataSource);
|
||||||
return new DataSourceTransactionManager(dataSource);
|
}
|
||||||
}
|
|
||||||
|
@Bean
|
||||||
@Bean
|
@DependsOn("getTaskanaEngine") // generate sample data after schema was inserted
|
||||||
@DependsOn("getTaskanaEngine") // generate sample data after schema was inserted
|
public SampleDataGenerator generateSampleData(DataSource dataSource) {
|
||||||
public SampleDataGenerator generateSampleData(DataSource dataSource) {
|
sampleDataGenerator = new SampleDataGenerator(dataSource, schemaName);
|
||||||
sampleDataGenerator = new SampleDataGenerator(dataSource, schemaName);
|
return sampleDataGenerator;
|
||||||
return sampleDataGenerator;
|
}
|
||||||
}
|
|
||||||
|
@PostConstruct
|
||||||
@PostConstruct
|
private void init() {
|
||||||
private void init() throws SQLException {
|
if (!ldapClient.useLdap()) {
|
||||||
if (!ldapClient.useLdap()) {
|
AccessIdController.setLdapCache(ldapCacheTest);
|
||||||
AccessIdController.setLdapCache(ldapCacheTest);
|
}
|
||||||
}
|
if (generateSampleData) {
|
||||||
if (generateSampleData) {
|
sampleDataGenerator.generateSampleData();
|
||||||
sampleDataGenerator.generateSampleData();
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -1,203 +1,203 @@
|
||||||
package pro.taskana.wildfly.security;
|
package pro.taskana.wildfly.security;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.core.annotation.Order;
|
import org.springframework.core.annotation.Order;
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.security.authentication.AuthenticationManager;
|
import org.springframework.security.authentication.AuthenticationManager;
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.security.core.AuthenticationException;
|
import org.springframework.security.core.AuthenticationException;
|
||||||
import org.springframework.security.core.GrantedAuthority;
|
import org.springframework.security.core.GrantedAuthority;
|
||||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||||
import org.springframework.security.core.userdetails.AuthenticationUserDetailsService;
|
import org.springframework.security.core.userdetails.AuthenticationUserDetailsService;
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||||
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationProvider;
|
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationProvider;
|
||||||
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken;
|
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken;
|
||||||
import org.springframework.security.web.authentication.preauth.j2ee.J2eePreAuthenticatedProcessingFilter;
|
import org.springframework.security.web.authentication.preauth.j2ee.J2eePreAuthenticatedProcessingFilter;
|
||||||
import org.springframework.security.web.jaasapi.JaasApiIntegrationFilter;
|
import org.springframework.security.web.jaasapi.JaasApiIntegrationFilter;
|
||||||
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
|
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
|
||||||
import org.wildfly.security.auth.server.SecurityDomain;
|
import org.wildfly.security.auth.server.SecurityDomain;
|
||||||
import org.wildfly.security.auth.server.SecurityIdentity;
|
import org.wildfly.security.auth.server.SecurityIdentity;
|
||||||
import org.wildfly.security.authz.Roles;
|
import org.wildfly.security.authz.Roles;
|
||||||
|
|
||||||
import pro.taskana.rest.security.WebSecurityConfig;
|
import pro.taskana.rest.security.WebSecurityConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default basic configuration for taskana web example running on Wildfly / JBoss with Elytron or
|
* Default basic configuration for taskana web example running on Wildfly / JBoss with Elytron or
|
||||||
* JAAS Security.
|
* JAAS Security.
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableWebSecurity
|
@EnableWebSecurity
|
||||||
@Order(1)
|
@Order(1)
|
||||||
public class WildflyWebSecurityConfig extends WebSecurityConfig {
|
public class WildflyWebSecurityConfig extends WebSecurityConfig {
|
||||||
|
|
||||||
@Value("${devMode:false}")
|
@Value("${devMode:false}")
|
||||||
private boolean devMode;
|
private boolean devMode;
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public J2eePreAuthenticatedProcessingFilter preAuthFilter() throws Exception {
|
public J2eePreAuthenticatedProcessingFilter preAuthFilter() {
|
||||||
J2eePreAuthenticatedProcessingFilter filter = new J2eePreAuthenticatedProcessingFilter();
|
J2eePreAuthenticatedProcessingFilter filter = new J2eePreAuthenticatedProcessingFilter();
|
||||||
filter.setAuthenticationManager(preAuthManager());
|
filter.setAuthenticationManager(preAuthManager());
|
||||||
return filter;
|
return filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public AuthenticationManager preAuthManager() {
|
public AuthenticationManager preAuthManager() {
|
||||||
return new AuthenticationManager() {
|
return new AuthenticationManager() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Authentication authenticate(Authentication authentication)
|
public Authentication authenticate(Authentication authentication)
|
||||||
throws AuthenticationException {
|
throws AuthenticationException {
|
||||||
return preauthAuthProvider().authenticate(authentication);
|
return preauthAuthProvider().authenticate(authentication);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public PreAuthenticatedAuthenticationProvider preauthAuthProvider() {
|
public PreAuthenticatedAuthenticationProvider preauthAuthProvider() {
|
||||||
PreAuthenticatedAuthenticationProvider preauthAuthProvider =
|
PreAuthenticatedAuthenticationProvider preauthAuthProvider =
|
||||||
new PreAuthenticatedAuthenticationProvider();
|
new PreAuthenticatedAuthenticationProvider();
|
||||||
preauthAuthProvider.setPreAuthenticatedUserDetailsService(authenticationUserDetailsService());
|
preauthAuthProvider.setPreAuthenticatedUserDetailsService(authenticationUserDetailsService());
|
||||||
return preauthAuthProvider;
|
return preauthAuthProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public AuthenticationUserDetailsService<PreAuthenticatedAuthenticationToken>
|
public AuthenticationUserDetailsService<PreAuthenticatedAuthenticationToken>
|
||||||
authenticationUserDetailsService() {
|
authenticationUserDetailsService() {
|
||||||
return new PreAuthenticatedAuthenticationTokenAuthenticationUserDetailsService();
|
return new PreAuthenticatedAuthenticationTokenAuthenticationUserDetailsService();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure(HttpSecurity http) throws Exception {
|
protected void configure(HttpSecurity http) throws Exception {
|
||||||
http.authorizeRequests()
|
http.authorizeRequests()
|
||||||
.antMatchers("/css/**", "/img/**")
|
.antMatchers("/css/**", "/img/**")
|
||||||
.permitAll()
|
.permitAll()
|
||||||
.and()
|
.and()
|
||||||
.csrf()
|
.csrf()
|
||||||
.disable()
|
.disable()
|
||||||
.httpBasic()
|
.httpBasic()
|
||||||
.and()
|
.and()
|
||||||
.authenticationProvider(preauthAuthProvider())
|
.authenticationProvider(preauthAuthProvider())
|
||||||
.authorizeRequests()
|
.authorizeRequests()
|
||||||
.antMatchers(HttpMethod.GET, "/docs/**")
|
.antMatchers(HttpMethod.GET, "/docs/**")
|
||||||
.permitAll()
|
.permitAll()
|
||||||
.and()
|
.and()
|
||||||
.addFilter(preAuthFilter())
|
.addFilter(preAuthFilter())
|
||||||
.addFilterAfter(new ElytronToJaasFilter(), JaasApiIntegrationFilter.class)
|
.addFilterAfter(new ElytronToJaasFilter(), JaasApiIntegrationFilter.class)
|
||||||
.addFilter(jaasApiIntegrationFilter());
|
.addFilter(jaasApiIntegrationFilter());
|
||||||
|
|
||||||
if (devMode) {
|
if (devMode) {
|
||||||
http.headers()
|
http.headers()
|
||||||
.frameOptions()
|
.frameOptions()
|
||||||
.sameOrigin()
|
.sameOrigin()
|
||||||
.and()
|
.and()
|
||||||
.authorizeRequests()
|
.authorizeRequests()
|
||||||
.antMatchers("/h2-console/**")
|
.antMatchers("/h2-console/**")
|
||||||
.permitAll();
|
.permitAll();
|
||||||
} else {
|
} else {
|
||||||
addLoginPageConfiguration(http);
|
addLoginPageConfiguration(http);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private JaasApiIntegrationFilter jaasApiIntegrationFilter() {
|
private JaasApiIntegrationFilter jaasApiIntegrationFilter() {
|
||||||
JaasApiIntegrationFilter filter = new JaasApiIntegrationFilter();
|
JaasApiIntegrationFilter filter = new JaasApiIntegrationFilter();
|
||||||
filter.setCreateEmptySubject(true);
|
filter.setCreateEmptySubject(true);
|
||||||
return filter;
|
return filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addLoginPageConfiguration(HttpSecurity http) throws Exception {
|
private void addLoginPageConfiguration(HttpSecurity http) throws Exception {
|
||||||
http.authorizeRequests()
|
http.authorizeRequests()
|
||||||
.anyRequest()
|
.anyRequest()
|
||||||
.fullyAuthenticated()
|
.fullyAuthenticated()
|
||||||
.and()
|
.and()
|
||||||
.formLogin()
|
.formLogin()
|
||||||
.loginPage("/login")
|
.loginPage("/login")
|
||||||
.failureUrl("/login?error")
|
.failureUrl("/login?error")
|
||||||
.defaultSuccessUrl("/")
|
.defaultSuccessUrl("/")
|
||||||
.permitAll()
|
.permitAll()
|
||||||
.and()
|
.and()
|
||||||
.logout()
|
.logout()
|
||||||
.invalidateHttpSession(true)
|
.invalidateHttpSession(true)
|
||||||
.clearAuthentication(true)
|
.clearAuthentication(true)
|
||||||
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
|
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
|
||||||
.logoutSuccessUrl("/login?logout")
|
.logoutSuccessUrl("/login?logout")
|
||||||
.deleteCookies("JSESSIONID")
|
.deleteCookies("JSESSIONID")
|
||||||
.permitAll();
|
.permitAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class PreAuthenticatedAuthenticationTokenAuthenticationUserDetailsService
|
private static class PreAuthenticatedAuthenticationTokenAuthenticationUserDetailsService
|
||||||
implements AuthenticationUserDetailsService<PreAuthenticatedAuthenticationToken> {
|
implements AuthenticationUserDetailsService<PreAuthenticatedAuthenticationToken> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserDetails loadUserDetails(PreAuthenticatedAuthenticationToken token)
|
public UserDetails loadUserDetails(PreAuthenticatedAuthenticationToken token)
|
||||||
throws UsernameNotFoundException {
|
throws UsernameNotFoundException {
|
||||||
return new MyUserDetails(token);
|
return new MyUserDetails(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class MyUserDetails implements UserDetails {
|
private static class MyUserDetails implements UserDetails {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
private final PreAuthenticatedAuthenticationToken token;
|
private final PreAuthenticatedAuthenticationToken token;
|
||||||
|
|
||||||
public MyUserDetails(PreAuthenticatedAuthenticationToken token) {
|
public MyUserDetails(PreAuthenticatedAuthenticationToken token) {
|
||||||
this.token = token;
|
this.token = token;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<? extends GrantedAuthority> getAuthorities() {
|
public Collection<? extends GrantedAuthority> getAuthorities() {
|
||||||
List<GrantedAuthority> authorities = new ArrayList<>();
|
List<GrantedAuthority> authorities = new ArrayList<>();
|
||||||
SecurityIdentity securityIdentity = getSecurityIdentity();
|
SecurityIdentity securityIdentity = getSecurityIdentity();
|
||||||
if (securityIdentity != null) {
|
if (securityIdentity != null) {
|
||||||
Roles roles = securityIdentity.getRoles();
|
Roles roles = securityIdentity.getRoles();
|
||||||
roles.forEach(role -> authorities.add(new SimpleGrantedAuthority(role)));
|
roles.forEach(role -> authorities.add(new SimpleGrantedAuthority(role)));
|
||||||
}
|
}
|
||||||
return authorities;
|
return authorities;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPassword() {
|
public String getPassword() {
|
||||||
return (String) token.getCredentials();
|
return (String) token.getCredentials();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getUsername() {
|
public String getUsername() {
|
||||||
return token.getName();
|
return token.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAccountNonExpired() {
|
public boolean isAccountNonExpired() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAccountNonLocked() {
|
public boolean isAccountNonLocked() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCredentialsNonExpired() {
|
public boolean isCredentialsNonExpired() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private SecurityIdentity getSecurityIdentity() {
|
private SecurityIdentity getSecurityIdentity() {
|
||||||
SecurityDomain current = SecurityDomain.getCurrent();
|
SecurityDomain current = SecurityDomain.getCurrent();
|
||||||
if (current != null) {
|
if (current != null) {
|
||||||
return current.getCurrentSecurityIdentity();
|
return current.getCurrentSecurityIdentity();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -156,7 +156,7 @@ public class WorkbasketController extends AbstractPagingController {
|
||||||
public ResponseEntity<WorkbasketResource> createWorkbasket(
|
public ResponseEntity<WorkbasketResource> createWorkbasket(
|
||||||
@RequestBody WorkbasketResource workbasketResource)
|
@RequestBody WorkbasketResource workbasketResource)
|
||||||
throws InvalidWorkbasketException, NotAuthorizedException, WorkbasketAlreadyExistException,
|
throws InvalidWorkbasketException, NotAuthorizedException, WorkbasketAlreadyExistException,
|
||||||
WorkbasketNotFoundException, DomainNotFoundException {
|
DomainNotFoundException {
|
||||||
if (LOGGER.isDebugEnabled()) {
|
if (LOGGER.isDebugEnabled()) {
|
||||||
LOGGER.debug("Entry to createWorkbasket(workbasketResource= {})", workbasketResource);
|
LOGGER.debug("Entry to createWorkbasket(workbasketResource= {})", workbasketResource);
|
||||||
}
|
}
|
||||||
|
@ -178,8 +178,8 @@ public class WorkbasketController extends AbstractPagingController {
|
||||||
public ResponseEntity<WorkbasketResource> updateWorkbasket(
|
public ResponseEntity<WorkbasketResource> updateWorkbasket(
|
||||||
@PathVariable(value = "workbasketId") String workbasketId,
|
@PathVariable(value = "workbasketId") String workbasketId,
|
||||||
@RequestBody WorkbasketResource workbasketResource)
|
@RequestBody WorkbasketResource workbasketResource)
|
||||||
throws InvalidWorkbasketException, WorkbasketNotFoundException,
|
throws InvalidWorkbasketException, WorkbasketNotFoundException, NotAuthorizedException,
|
||||||
NotAuthorizedException, ConcurrencyException {
|
ConcurrencyException {
|
||||||
LOGGER.debug("Entry to updateWorkbasket(workbasketId= {})", workbasketId);
|
LOGGER.debug("Entry to updateWorkbasket(workbasketId= {})", workbasketId);
|
||||||
ResponseEntity<WorkbasketResource> result;
|
ResponseEntity<WorkbasketResource> result;
|
||||||
if (workbasketId.equals(workbasketResource.workbasketId)) {
|
if (workbasketId.equals(workbasketResource.workbasketId)) {
|
||||||
|
|
|
@ -1,303 +1,301 @@
|
||||||
package pro.taskana.rest;
|
package pro.taskana.rest;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import java.io.IOException;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.core.ParameterizedTypeReference;
|
||||||
import org.springframework.core.ParameterizedTypeReference;
|
import org.springframework.hateoas.Link;
|
||||||
import org.springframework.hateoas.Link;
|
import org.springframework.http.HttpEntity;
|
||||||
import org.springframework.http.HttpEntity;
|
import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
import org.springframework.test.annotation.DirtiesContext;
|
import org.springframework.web.client.HttpClientErrorException;
|
||||||
import org.springframework.web.client.HttpClientErrorException;
|
import org.springframework.web.client.RestTemplate;
|
||||||
import org.springframework.web.client.RestTemplate;
|
|
||||||
|
import pro.taskana.RestHelper;
|
||||||
import pro.taskana.RestHelper;
|
import pro.taskana.TaskanaSpringBootTest;
|
||||||
import pro.taskana.TaskanaSpringBootTest;
|
import pro.taskana.rest.resource.ClassificationResource;
|
||||||
import pro.taskana.rest.resource.ClassificationResource;
|
import pro.taskana.rest.resource.ClassificationSummaryListResource;
|
||||||
import pro.taskana.rest.resource.ClassificationSummaryListResource;
|
import pro.taskana.rest.resource.ClassificationSummaryResource;
|
||||||
import pro.taskana.rest.resource.ClassificationSummaryResource;
|
|
||||||
|
/**
|
||||||
/**
|
* Test ClassificationController.
|
||||||
* Test ClassificationController.
|
*
|
||||||
*
|
* @author bbr
|
||||||
* @author bbr
|
*/
|
||||||
*/
|
@TaskanaSpringBootTest
|
||||||
@TaskanaSpringBootTest
|
class ClassificationControllerIntTest {
|
||||||
class ClassificationControllerIntTest {
|
|
||||||
|
static RestTemplate template = RestHelper.getRestTemplate();
|
||||||
static RestTemplate template = RestHelper.getRestTemplate();
|
@Autowired RestHelper restHelper;
|
||||||
@Autowired RestHelper restHelper;
|
|
||||||
|
@Test
|
||||||
@Test
|
void testGetAllClassifications() {
|
||||||
void testGetAllClassifications() {
|
ResponseEntity<ClassificationSummaryListResource> response =
|
||||||
ResponseEntity<ClassificationSummaryListResource> response =
|
template.exchange(
|
||||||
template.exchange(
|
restHelper.toUrl(Mapping.URL_CLASSIFICATIONS),
|
||||||
restHelper.toUrl(Mapping.URL_CLASSIFICATIONS),
|
HttpMethod.GET,
|
||||||
HttpMethod.GET,
|
restHelper.defaultRequest(),
|
||||||
restHelper.defaultRequest(),
|
ParameterizedTypeReference.forType(ClassificationSummaryListResource.class));
|
||||||
ParameterizedTypeReference.forType(ClassificationSummaryListResource.class));
|
assertNotNull(response.getBody().getLink(Link.REL_SELF));
|
||||||
assertNotNull(response.getBody().getLink(Link.REL_SELF));
|
}
|
||||||
}
|
|
||||||
|
@Test
|
||||||
@Test
|
void testGetAllClassificationsFilterByCustomAttribute() {
|
||||||
void testGetAllClassificationsFilterByCustomAttribute() {
|
ResponseEntity<ClassificationSummaryListResource> response =
|
||||||
ResponseEntity<ClassificationSummaryListResource> response =
|
template.exchange(
|
||||||
template.exchange(
|
restHelper.toUrl(Mapping.URL_CLASSIFICATIONS) + "?domain=DOMAIN_A&custom-1-like=RVNR",
|
||||||
restHelper.toUrl(Mapping.URL_CLASSIFICATIONS) + "?domain=DOMAIN_A&custom-1-like=RVNR",
|
HttpMethod.GET,
|
||||||
HttpMethod.GET,
|
restHelper.defaultRequest(),
|
||||||
restHelper.defaultRequest(),
|
ParameterizedTypeReference.forType(ClassificationSummaryListResource.class));
|
||||||
ParameterizedTypeReference.forType(ClassificationSummaryListResource.class));
|
assertNotNull(response.getBody().getLink(Link.REL_SELF));
|
||||||
assertNotNull(response.getBody().getLink(Link.REL_SELF));
|
assertEquals(13, response.getBody().getContent().size());
|
||||||
assertEquals(13, response.getBody().getContent().size());
|
}
|
||||||
}
|
|
||||||
|
@Test
|
||||||
@Test
|
void testGetAllClassificationsKeepingFilters() {
|
||||||
void testGetAllClassificationsKeepingFilters() {
|
ResponseEntity<ClassificationSummaryListResource> response =
|
||||||
ResponseEntity<ClassificationSummaryListResource> response =
|
template.exchange(
|
||||||
template.exchange(
|
restHelper.toUrl(Mapping.URL_CLASSIFICATIONS)
|
||||||
restHelper.toUrl(Mapping.URL_CLASSIFICATIONS)
|
+ "?domain=DOMAIN_A&sort-by=key&order=asc",
|
||||||
+ "?domain=DOMAIN_A&sort-by=key&order=asc",
|
HttpMethod.GET,
|
||||||
HttpMethod.GET,
|
restHelper.defaultRequest(),
|
||||||
restHelper.defaultRequest(),
|
ParameterizedTypeReference.forType(ClassificationSummaryListResource.class));
|
||||||
ParameterizedTypeReference.forType(ClassificationSummaryListResource.class));
|
assertNotNull(response.getBody().getLink(Link.REL_SELF));
|
||||||
assertNotNull(response.getBody().getLink(Link.REL_SELF));
|
assertTrue(
|
||||||
assertTrue(
|
response
|
||||||
response
|
.getBody()
|
||||||
.getBody()
|
.getLink(Link.REL_SELF)
|
||||||
.getLink(Link.REL_SELF)
|
.getHref()
|
||||||
.getHref()
|
.endsWith("/api/v1/classifications?domain=DOMAIN_A&sort-by=key&order=asc"));
|
||||||
.endsWith("/api/v1/classifications?domain=DOMAIN_A&sort-by=key&order=asc"));
|
assertEquals(17, response.getBody().getContent().size());
|
||||||
assertEquals(17, response.getBody().getContent().size());
|
assertEquals("A12", response.getBody().getContent().iterator().next().key);
|
||||||
assertEquals("A12", response.getBody().getContent().iterator().next().key);
|
}
|
||||||
}
|
|
||||||
|
@Test
|
||||||
@Test
|
void testGetSecondPageSortedByKey() {
|
||||||
void testGetSecondPageSortedByKey() {
|
ResponseEntity<ClassificationSummaryListResource> response =
|
||||||
ResponseEntity<ClassificationSummaryListResource> response =
|
template.exchange(
|
||||||
template.exchange(
|
restHelper.toUrl(Mapping.URL_CLASSIFICATIONS)
|
||||||
restHelper.toUrl(Mapping.URL_CLASSIFICATIONS)
|
+ "?domain=DOMAIN_A&sort-by=key&order=asc&page=2&page-size=5",
|
||||||
+ "?domain=DOMAIN_A&sort-by=key&order=asc&page=2&page-size=5",
|
HttpMethod.GET,
|
||||||
HttpMethod.GET,
|
restHelper.defaultRequest(),
|
||||||
restHelper.defaultRequest(),
|
ParameterizedTypeReference.forType(ClassificationSummaryListResource.class));
|
||||||
ParameterizedTypeReference.forType(ClassificationSummaryListResource.class));
|
assertEquals(5, response.getBody().getContent().size());
|
||||||
assertEquals(5, response.getBody().getContent().size());
|
assertEquals("L1050", response.getBody().getContent().iterator().next().key);
|
||||||
assertEquals("L1050", response.getBody().getContent().iterator().next().key);
|
assertNotNull(response.getBody().getLink(Link.REL_SELF));
|
||||||
assertNotNull(response.getBody().getLink(Link.REL_SELF));
|
assertTrue(
|
||||||
assertTrue(
|
response
|
||||||
response
|
.getBody()
|
||||||
.getBody()
|
.getLink(Link.REL_SELF)
|
||||||
.getLink(Link.REL_SELF)
|
.getHref()
|
||||||
.getHref()
|
.endsWith(
|
||||||
.endsWith(
|
"/api/v1/classifications?"
|
||||||
"/api/v1/classifications?"
|
+ "domain=DOMAIN_A&sort-by=key&order=asc&page=2&page-size=5"));
|
||||||
+ "domain=DOMAIN_A&sort-by=key&order=asc&page=2&page-size=5"));
|
assertNotNull(response.getBody().getLink(Link.REL_FIRST));
|
||||||
assertNotNull(response.getBody().getLink(Link.REL_FIRST));
|
assertNotNull(response.getBody().getLink(Link.REL_LAST));
|
||||||
assertNotNull(response.getBody().getLink(Link.REL_LAST));
|
assertNotNull(response.getBody().getLink(Link.REL_NEXT));
|
||||||
assertNotNull(response.getBody().getLink(Link.REL_NEXT));
|
assertNotNull(response.getBody().getLink(Link.REL_PREVIOUS));
|
||||||
assertNotNull(response.getBody().getLink(Link.REL_PREVIOUS));
|
}
|
||||||
}
|
|
||||||
|
@Test
|
||||||
@Test
|
@DirtiesContext
|
||||||
@DirtiesContext
|
void testCreateClassification() {
|
||||||
void testCreateClassification() {
|
String newClassification =
|
||||||
String newClassification =
|
"{\"classificationId\":\"\",\"category\":\"MANUAL\","
|
||||||
"{\"classificationId\":\"\",\"category\":\"MANUAL\","
|
+ "\"domain\":\"DOMAIN_A\",\"key\":\"NEW_CLASS\","
|
||||||
+ "\"domain\":\"DOMAIN_A\",\"key\":\"NEW_CLASS\","
|
+ "\"name\":\"new classification\",\"type\":\"TASK\"}";
|
||||||
+ "\"name\":\"new classification\",\"type\":\"TASK\"}";
|
|
||||||
|
ResponseEntity<ClassificationResource> responseEntity =
|
||||||
ResponseEntity<ClassificationResource> responseEntity =
|
template.exchange(
|
||||||
template.exchange(
|
restHelper.toUrl(Mapping.URL_CLASSIFICATIONS),
|
||||||
restHelper.toUrl(Mapping.URL_CLASSIFICATIONS),
|
HttpMethod.POST,
|
||||||
HttpMethod.POST,
|
new HttpEntity<>(newClassification, restHelper.getHeaders()),
|
||||||
new HttpEntity<>(newClassification, restHelper.getHeaders()),
|
ParameterizedTypeReference.forType(ClassificationResource.class));
|
||||||
ParameterizedTypeReference.forType(ClassificationResource.class));
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
assertNotNull(responseEntity);
|
assertEquals(HttpStatus.CREATED, responseEntity.getStatusCode());
|
||||||
assertEquals(HttpStatus.CREATED, responseEntity.getStatusCode());
|
|
||||||
|
newClassification =
|
||||||
newClassification =
|
"{\"classificationId\":\"\",\"category\":\"MANUAL\","
|
||||||
"{\"classificationId\":\"\",\"category\":\"MANUAL\","
|
+ "\"domain\":\"DOMAIN_A\",\"key\":\"NEW_CLASS_2\","
|
||||||
+ "\"domain\":\"DOMAIN_A\",\"key\":\"NEW_CLASS_2\","
|
+ "\"name\":\"new classification\",\"type\":\"TASK\"}";
|
||||||
+ "\"name\":\"new classification\",\"type\":\"TASK\"}";
|
|
||||||
|
responseEntity =
|
||||||
responseEntity =
|
template.exchange(
|
||||||
template.exchange(
|
restHelper.toUrl(Mapping.URL_CLASSIFICATIONS),
|
||||||
restHelper.toUrl(Mapping.URL_CLASSIFICATIONS),
|
HttpMethod.POST,
|
||||||
HttpMethod.POST,
|
new HttpEntity<>(newClassification, restHelper.getHeaders()),
|
||||||
new HttpEntity<>(newClassification, restHelper.getHeaders()),
|
ParameterizedTypeReference.forType(ClassificationResource.class));
|
||||||
ParameterizedTypeReference.forType(ClassificationResource.class));
|
|
||||||
|
assertEquals(HttpStatus.CREATED, responseEntity.getStatusCode());
|
||||||
assertEquals(HttpStatus.CREATED, responseEntity.getStatusCode());
|
}
|
||||||
}
|
|
||||||
|
@Test
|
||||||
@Test
|
@DirtiesContext
|
||||||
@DirtiesContext
|
void testCreateClassificationWithParentId() {
|
||||||
void testCreateClassificationWithParentId() {
|
String newClassification =
|
||||||
String newClassification =
|
"{\"classificationId\":\"\",\"category\":\"MANUAL\","
|
||||||
"{\"classificationId\":\"\",\"category\":\"MANUAL\","
|
+ "\"domain\":\"DOMAIN_B\",\"key\":\"NEW_CLASS_P1\","
|
||||||
+ "\"domain\":\"DOMAIN_B\",\"key\":\"NEW_CLASS_P1\","
|
+ "\"name\":\"new classification\",\"type\":\"TASK\","
|
||||||
+ "\"name\":\"new classification\",\"type\":\"TASK\","
|
+ "\"parentId\":\"CLI:200000000000000000000000000000000015\"}";
|
||||||
+ "\"parentId\":\"CLI:200000000000000000000000000000000015\"}";
|
|
||||||
|
ResponseEntity<ClassificationResource> responseEntity =
|
||||||
ResponseEntity<ClassificationResource> responseEntity =
|
template.exchange(
|
||||||
template.exchange(
|
restHelper.toUrl(Mapping.URL_CLASSIFICATIONS),
|
||||||
restHelper.toUrl(Mapping.URL_CLASSIFICATIONS),
|
HttpMethod.POST,
|
||||||
HttpMethod.POST,
|
new HttpEntity<>(newClassification, restHelper.getHeaders()),
|
||||||
new HttpEntity<>(newClassification, restHelper.getHeaders()),
|
ParameterizedTypeReference.forType(ClassificationResource.class));
|
||||||
ParameterizedTypeReference.forType(ClassificationResource.class));
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
assertNotNull(responseEntity);
|
assertEquals(HttpStatus.CREATED, responseEntity.getStatusCode());
|
||||||
assertEquals(HttpStatus.CREATED, responseEntity.getStatusCode());
|
}
|
||||||
}
|
|
||||||
|
@Test
|
||||||
@Test
|
@DirtiesContext
|
||||||
@DirtiesContext
|
@SuppressWarnings("checkstyle:LineLength")
|
||||||
@SuppressWarnings("checkstyle:LineLength")
|
void testCreateClassificationWithParentKey() {
|
||||||
void testCreateClassificationWithParentKey() {
|
String newClassification =
|
||||||
String newClassification =
|
"{\"classificationId\":\"\",\"category\":\"MANUAL\",\"domain\":\"DOMAIN_B\","
|
||||||
"{\"classificationId\":\"\",\"category\":\"MANUAL\",\"domain\":\"DOMAIN_B\","
|
+ "\"key\":\"NEW_CLASS_P2\",\"name\":\"new classification\","
|
||||||
+ "\"key\":\"NEW_CLASS_P2\",\"name\":\"new classification\","
|
+ "\"type\":\"TASK\",\"parentKey\":\"T2100\"}";
|
||||||
+ "\"type\":\"TASK\",\"parentKey\":\"T2100\"}";
|
|
||||||
|
ResponseEntity<ClassificationResource> responseEntity =
|
||||||
ResponseEntity<ClassificationResource> responseEntity =
|
template.exchange(
|
||||||
template.exchange(
|
restHelper.toUrl(Mapping.URL_CLASSIFICATIONS),
|
||||||
restHelper.toUrl(Mapping.URL_CLASSIFICATIONS),
|
HttpMethod.POST,
|
||||||
HttpMethod.POST,
|
new HttpEntity<>(newClassification, restHelper.getHeaders()),
|
||||||
new HttpEntity<>(newClassification, restHelper.getHeaders()),
|
ParameterizedTypeReference.forType(ClassificationResource.class));
|
||||||
ParameterizedTypeReference.forType(ClassificationResource.class));
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
assertNotNull(responseEntity);
|
assertEquals(HttpStatus.CREATED, responseEntity.getStatusCode());
|
||||||
assertEquals(HttpStatus.CREATED, responseEntity.getStatusCode());
|
}
|
||||||
}
|
|
||||||
|
@Test
|
||||||
@Test
|
@DirtiesContext
|
||||||
@DirtiesContext
|
void testCreateClassificationWithParentKeyInDomain_aShouldCreateAClassificationInRootDomain() {
|
||||||
void testCreateClassificationWithParentKeyInDomain_aShouldCreateAClassificationInRootDomain()
|
String newClassification =
|
||||||
throws IOException {
|
"{\"classificationId\":\"\",\"category\":\"MANUAL\",\"domain\":\"DOMAIN_A\","
|
||||||
String newClassification =
|
+ "\"key\":\"NEW_CLASS_P2\",\"name\":\"new classification\","
|
||||||
"{\"classificationId\":\"\",\"category\":\"MANUAL\",\"domain\":\"DOMAIN_A\","
|
+ "\"type\":\"TASK\",\"parentKey\":\"T2100\"}";
|
||||||
+ "\"key\":\"NEW_CLASS_P2\",\"name\":\"new classification\","
|
|
||||||
+ "\"type\":\"TASK\",\"parentKey\":\"T2100\"}";
|
ResponseEntity<ClassificationResource> responseEntity =
|
||||||
|
template.exchange(
|
||||||
ResponseEntity<ClassificationResource> responseEntity =
|
restHelper.toUrl(Mapping.URL_CLASSIFICATIONS),
|
||||||
template.exchange(
|
HttpMethod.POST,
|
||||||
restHelper.toUrl(Mapping.URL_CLASSIFICATIONS),
|
new HttpEntity<>(newClassification, restHelper.getHeaders()),
|
||||||
HttpMethod.POST,
|
ParameterizedTypeReference.forType(ClassificationResource.class));
|
||||||
new HttpEntity<>(newClassification, restHelper.getHeaders()),
|
|
||||||
ParameterizedTypeReference.forType(ClassificationResource.class));
|
assertNotNull(responseEntity);
|
||||||
|
assertEquals(HttpStatus.CREATED, responseEntity.getStatusCode());
|
||||||
assertNotNull(responseEntity);
|
|
||||||
assertEquals(HttpStatus.CREATED, responseEntity.getStatusCode());
|
ResponseEntity<ClassificationSummaryListResource> response =
|
||||||
|
template.exchange(
|
||||||
ResponseEntity<ClassificationSummaryListResource> response =
|
restHelper.toUrl(Mapping.URL_CLASSIFICATIONS),
|
||||||
template.exchange(
|
HttpMethod.GET,
|
||||||
restHelper.toUrl(Mapping.URL_CLASSIFICATIONS),
|
restHelper.defaultRequest(),
|
||||||
HttpMethod.GET,
|
ParameterizedTypeReference.forType(ClassificationSummaryListResource.class));
|
||||||
restHelper.defaultRequest(),
|
assertNotNull(response.getBody().getLink(Link.REL_SELF));
|
||||||
ParameterizedTypeReference.forType(ClassificationSummaryListResource.class));
|
boolean foundClassificationCreated = false;
|
||||||
assertNotNull(response.getBody().getLink(Link.REL_SELF));
|
for (ClassificationSummaryResource classification : response.getBody().getContent()) {
|
||||||
boolean foundClassificationCreated = false;
|
if ("NEW_CLASS_P2".equals(classification.getKey())
|
||||||
for (ClassificationSummaryResource classification : response.getBody().getContent()) {
|
&& "".equals(classification.getDomain())
|
||||||
if ("NEW_CLASS_P2".equals(classification.getKey())
|
&& "T2100".equals(classification.getParentKey())) {
|
||||||
&& "".equals(classification.getDomain())
|
foundClassificationCreated = true;
|
||||||
&& "T2100".equals(classification.getParentKey())) {
|
}
|
||||||
foundClassificationCreated = true;
|
}
|
||||||
}
|
|
||||||
}
|
assertEquals(true, foundClassificationCreated);
|
||||||
|
}
|
||||||
assertEquals(true, foundClassificationCreated);
|
|
||||||
}
|
@Test
|
||||||
|
@DirtiesContext
|
||||||
@Test
|
void testReturn400IfCreateClassificationWithIncompatibleParentIdAndKey() {
|
||||||
@DirtiesContext
|
String newClassification =
|
||||||
void testReturn400IfCreateClassificationWithIncompatibleParentIdAndKey() throws IOException {
|
"{\"classificationId\":\"\",\"category\":\"MANUAL\",\"domain\":\"DOMAIN_B\","
|
||||||
String newClassification =
|
+ "\"key\":\"NEW_CLASS_P3\",\"name\":\"new classification\","
|
||||||
"{\"classificationId\":\"\",\"category\":\"MANUAL\",\"domain\":\"DOMAIN_B\","
|
+ "\"type\":\"TASK\",\"parentId\":\"CLI:200000000000000000000000000000000015\","
|
||||||
+ "\"key\":\"NEW_CLASS_P3\",\"name\":\"new classification\","
|
+ "\"parentKey\":\"T2000\"}";
|
||||||
+ "\"type\":\"TASK\",\"parentId\":\"CLI:200000000000000000000000000000000015\","
|
|
||||||
+ "\"parentKey\":\"T2000\"}";
|
HttpClientErrorException e =
|
||||||
|
Assertions.assertThrows(
|
||||||
HttpClientErrorException e =
|
HttpClientErrorException.class,
|
||||||
Assertions.assertThrows(
|
() ->
|
||||||
HttpClientErrorException.class,
|
template.exchange(
|
||||||
() ->
|
restHelper.toUrl(Mapping.URL_CLASSIFICATIONS),
|
||||||
template.exchange(
|
HttpMethod.POST,
|
||||||
restHelper.toUrl(Mapping.URL_CLASSIFICATIONS),
|
new HttpEntity<>(newClassification, restHelper.getHeaders()),
|
||||||
HttpMethod.POST,
|
ParameterizedTypeReference.forType(ClassificationResource.class)));
|
||||||
new HttpEntity<>(newClassification, restHelper.getHeaders()),
|
|
||||||
ParameterizedTypeReference.forType(ClassificationResource.class)));
|
assertNotNull(e);
|
||||||
|
assertEquals(HttpStatus.BAD_REQUEST, e.getStatusCode());
|
||||||
assertNotNull(e);
|
}
|
||||||
assertEquals(HttpStatus.BAD_REQUEST, e.getStatusCode());
|
|
||||||
}
|
@Test
|
||||||
|
@DirtiesContext
|
||||||
@Test
|
void testCreateClassificationWithClassificationIdReturnsError400() {
|
||||||
@DirtiesContext
|
String newClassification =
|
||||||
void testCreateClassificationWithClassificationIdReturnsError400() throws IOException {
|
"{\"classificationId\":\"someId\",\"category\":\"MANUAL\","
|
||||||
String newClassification =
|
+ "\"domain\":\"DOMAIN_A\",\"key\":\"NEW_CLASS\","
|
||||||
"{\"classificationId\":\"someId\",\"category\":\"MANUAL\","
|
+ "\"name\":\"new classification\",\"type\":\"TASK\"}";
|
||||||
+ "\"domain\":\"DOMAIN_A\",\"key\":\"NEW_CLASS\","
|
|
||||||
+ "\"name\":\"new classification\",\"type\":\"TASK\"}";
|
HttpClientErrorException e =
|
||||||
|
Assertions.assertThrows(
|
||||||
HttpClientErrorException e =
|
HttpClientErrorException.class,
|
||||||
Assertions.assertThrows(
|
() ->
|
||||||
HttpClientErrorException.class,
|
template.exchange(
|
||||||
() ->
|
restHelper.toUrl(Mapping.URL_CLASSIFICATIONS),
|
||||||
template.exchange(
|
HttpMethod.POST,
|
||||||
restHelper.toUrl(Mapping.URL_CLASSIFICATIONS),
|
new HttpEntity<>(newClassification, restHelper.getHeaders()),
|
||||||
HttpMethod.POST,
|
ParameterizedTypeReference.forType(ClassificationResource.class)));
|
||||||
new HttpEntity<>(newClassification, restHelper.getHeaders()),
|
|
||||||
ParameterizedTypeReference.forType(ClassificationResource.class)));
|
assertNotNull(e);
|
||||||
|
assertEquals(HttpStatus.BAD_REQUEST, e.getStatusCode());
|
||||||
assertNotNull(e);
|
}
|
||||||
assertEquals(HttpStatus.BAD_REQUEST, e.getStatusCode());
|
|
||||||
}
|
@Test
|
||||||
|
void testGetClassificationWithSpecialCharacter() {
|
||||||
@Test
|
|
||||||
void testGetClassificationWithSpecialCharacter() {
|
HttpEntity<String> request = new HttpEntity<String>(restHelper.getHeadersAdmin());
|
||||||
|
ResponseEntity<ClassificationSummaryResource> response =
|
||||||
HttpEntity<String> request = new HttpEntity<String>(restHelper.getHeadersAdmin());
|
template.exchange(
|
||||||
ResponseEntity<ClassificationSummaryResource> response =
|
restHelper.toUrl(
|
||||||
template.exchange(
|
Mapping.URL_CLASSIFICATIONS_ID, "CLI:100000000000000000000000000000000009"),
|
||||||
restHelper.toUrl(
|
HttpMethod.GET,
|
||||||
Mapping.URL_CLASSIFICATIONS_ID, "CLI:100000000000000000000000000000000009"),
|
request,
|
||||||
HttpMethod.GET,
|
ParameterizedTypeReference.forType(ClassificationSummaryResource.class));
|
||||||
request,
|
assertEquals("Zustimmungserklärung", response.getBody().name);
|
||||||
ParameterizedTypeReference.forType(ClassificationSummaryResource.class));
|
}
|
||||||
assertEquals("Zustimmungserklärung", response.getBody().name);
|
|
||||||
}
|
@Test
|
||||||
|
@DirtiesContext
|
||||||
@Test
|
void testDeleteClassification() {
|
||||||
@DirtiesContext
|
HttpEntity<String> request = new HttpEntity<String>(restHelper.getHeaders());
|
||||||
void testDeleteClassification() {
|
|
||||||
HttpEntity<String> request = new HttpEntity<String>(restHelper.getHeaders());
|
ResponseEntity<ClassificationSummaryResource> response =
|
||||||
|
template.exchange(
|
||||||
ResponseEntity<ClassificationSummaryResource> response =
|
restHelper.toUrl(
|
||||||
template.exchange(
|
Mapping.URL_CLASSIFICATIONS_ID, "CLI:200000000000000000000000000000000004"),
|
||||||
restHelper.toUrl(
|
HttpMethod.DELETE,
|
||||||
Mapping.URL_CLASSIFICATIONS_ID, "CLI:200000000000000000000000000000000004"),
|
request,
|
||||||
HttpMethod.DELETE,
|
ParameterizedTypeReference.forType(ClassificationSummaryResource.class));
|
||||||
request,
|
assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode());
|
||||||
ParameterizedTypeReference.forType(ClassificationSummaryResource.class));
|
|
||||||
assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode());
|
assertThrows(
|
||||||
|
HttpClientErrorException.class,
|
||||||
assertThrows(
|
() -> {
|
||||||
HttpClientErrorException.class,
|
template.exchange(
|
||||||
() -> {
|
restHelper.toUrl(
|
||||||
template.exchange(
|
Mapping.URL_CLASSIFICATIONS_ID, "CLI:200000000000000000000000000000000004"),
|
||||||
restHelper.toUrl(
|
HttpMethod.GET,
|
||||||
Mapping.URL_CLASSIFICATIONS_ID, "CLI:200000000000000000000000000000000004"),
|
request,
|
||||||
HttpMethod.GET,
|
ParameterizedTypeReference.forType(ClassificationSummaryResource.class));
|
||||||
request,
|
});
|
||||||
ParameterizedTypeReference.forType(ClassificationSummaryResource.class));
|
}
|
||||||
});
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,73 +1,72 @@
|
||||||
package pro.taskana.rest;
|
package pro.taskana.rest;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.annotation.PostConstruct;
|
import javax.sql.DataSource;
|
||||||
import javax.sql.DataSource;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
|
||||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.DependsOn;
|
||||||
import org.springframework.context.annotation.DependsOn;
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Primary;
|
||||||
import org.springframework.context.annotation.Primary;
|
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
import org.springframework.transaction.PlatformTransactionManager;
|
||||||
import org.springframework.transaction.PlatformTransactionManager;
|
|
||||||
|
import pro.taskana.ldap.LdapCacheTestImpl;
|
||||||
import pro.taskana.ldap.LdapCacheTestImpl;
|
import pro.taskana.sampledata.SampleDataGenerator;
|
||||||
import pro.taskana.sampledata.SampleDataGenerator;
|
|
||||||
|
/** Example Application to create the documentation. */
|
||||||
/** Example Application to create the documentation. */
|
@SpringBootApplication
|
||||||
@SpringBootApplication
|
@EnableScheduling
|
||||||
@EnableScheduling
|
@ComponentScan(basePackages = "pro.taskana")
|
||||||
@ComponentScan(basePackages = "pro.taskana")
|
@Import({RestConfiguration.class})
|
||||||
@Import({RestConfiguration.class})
|
public class ExampleDocumentationApp {
|
||||||
public class ExampleDocumentationApp {
|
|
||||||
|
@Value("${taskana.schemaName:TASKANA}")
|
||||||
@Value("${taskana.schemaName:TASKANA}")
|
private String schemaName;
|
||||||
private String schemaName;
|
|
||||||
|
@Autowired private SampleDataGenerator sampleDataGenerator;
|
||||||
@Autowired private SampleDataGenerator sampleDataGenerator;
|
|
||||||
|
public static void main(String[] args) {
|
||||||
public static void main(String[] args) {
|
SpringApplication.run(ExampleDocumentationApp.class, args);
|
||||||
SpringApplication.run(ExampleDocumentationApp.class, args);
|
}
|
||||||
}
|
|
||||||
|
@Bean
|
||||||
@Bean
|
@Primary
|
||||||
@Primary
|
@ConfigurationProperties(prefix = "datasource")
|
||||||
@ConfigurationProperties(prefix = "datasource")
|
public DataSourceProperties dataSourceProperties() {
|
||||||
public DataSourceProperties dataSourceProperties() {
|
DataSourceProperties props = new DataSourceProperties();
|
||||||
DataSourceProperties props = new DataSourceProperties();
|
props.setUrl(
|
||||||
props.setUrl(
|
"jdbc:h2:mem:taskana;IGNORECASE=TRUE;LOCK_MODE=0;INIT=CREATE SCHEMA IF NOT EXISTS "
|
||||||
"jdbc:h2:mem:taskana;IGNORECASE=TRUE;LOCK_MODE=0;INIT=CREATE SCHEMA IF NOT EXISTS "
|
+ schemaName);
|
||||||
+ schemaName);
|
return props;
|
||||||
return props;
|
}
|
||||||
}
|
|
||||||
|
@Bean
|
||||||
@Bean
|
public DataSource dataSource(DataSourceProperties properties) {
|
||||||
public DataSource dataSource(DataSourceProperties properties) {
|
return properties.initializeDataSourceBuilder().build();
|
||||||
return properties.initializeDataSourceBuilder().build();
|
}
|
||||||
}
|
|
||||||
|
@Bean
|
||||||
@Bean
|
public PlatformTransactionManager txManager(DataSource dataSource) {
|
||||||
public PlatformTransactionManager txManager(DataSource dataSource) {
|
return new DataSourceTransactionManager(dataSource);
|
||||||
return new DataSourceTransactionManager(dataSource);
|
}
|
||||||
}
|
|
||||||
|
@Bean
|
||||||
@Bean
|
@DependsOn("getTaskanaEngine") // generate sample data after schema was inserted
|
||||||
@DependsOn("getTaskanaEngine") // generate sample data after schema was inserted
|
public SampleDataGenerator generateSampleData(DataSource dataSource) {
|
||||||
public SampleDataGenerator generateSampleData(DataSource dataSource) {
|
sampleDataGenerator = new SampleDataGenerator(dataSource, schemaName);
|
||||||
sampleDataGenerator = new SampleDataGenerator(dataSource, schemaName);
|
return sampleDataGenerator;
|
||||||
return sampleDataGenerator;
|
}
|
||||||
}
|
|
||||||
|
@PostConstruct
|
||||||
@PostConstruct
|
private void init() {
|
||||||
private void init() throws SQLException {
|
AccessIdController.setLdapCache(new LdapCacheTestImpl());
|
||||||
AccessIdController.setLdapCache(new LdapCacheTestImpl());
|
sampleDataGenerator.generateSampleData();
|
||||||
sampleDataGenerator.generateSampleData();
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -1,280 +1,280 @@
|
||||||
package pro.taskana.rest;
|
package pro.taskana.rest;
|
||||||
|
|
||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
import static org.hamcrest.Matchers.instanceOf;
|
import static org.hamcrest.Matchers.instanceOf;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.core.ParameterizedTypeReference;
|
import org.springframework.core.ParameterizedTypeReference;
|
||||||
import org.springframework.core.io.FileSystemResource;
|
import org.springframework.core.io.FileSystemResource;
|
||||||
import org.springframework.http.HttpEntity;
|
import org.springframework.http.HttpEntity;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.util.LinkedMultiValueMap;
|
import org.springframework.util.LinkedMultiValueMap;
|
||||||
import org.springframework.util.MultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
||||||
import org.springframework.web.client.HttpClientErrorException;
|
import org.springframework.web.client.HttpClientErrorException;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
import pro.taskana.RestHelper;
|
import pro.taskana.RestHelper;
|
||||||
import pro.taskana.TaskanaSpringBootTest;
|
import pro.taskana.TaskanaSpringBootTest;
|
||||||
import pro.taskana.rest.resource.WorkbasketDefinitionResource;
|
import pro.taskana.rest.resource.WorkbasketDefinitionResource;
|
||||||
import pro.taskana.sampledata.SampleDataGenerator;
|
import pro.taskana.sampledata.SampleDataGenerator;
|
||||||
|
|
||||||
/** Integration tests for WorkbasketDefinitionController. */
|
/** Integration tests for WorkbasketDefinitionController. */
|
||||||
@TaskanaSpringBootTest
|
@TaskanaSpringBootTest
|
||||||
class WorkbasketDefinitionControllerIntTest {
|
class WorkbasketDefinitionControllerIntTest {
|
||||||
|
|
||||||
private static RestTemplate template;
|
private static RestTemplate template;
|
||||||
|
|
||||||
@Value("${taskana.schemaName:TASKANA}")
|
@Value("${taskana.schemaName:TASKANA}")
|
||||||
String schemaName;
|
String schemaName;
|
||||||
|
|
||||||
ObjectMapper objMapper = new ObjectMapper();
|
ObjectMapper objMapper = new ObjectMapper();
|
||||||
|
|
||||||
@Autowired RestHelper restHelper;
|
@Autowired RestHelper restHelper;
|
||||||
|
|
||||||
@Autowired private DataSource dataSource;
|
@Autowired private DataSource dataSource;
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
static void init() {
|
static void init() {
|
||||||
template = RestHelper.getRestTemplate();
|
template = RestHelper.getRestTemplate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void resetDb() {
|
void resetDb() {
|
||||||
SampleDataGenerator sampleDataGenerator = new SampleDataGenerator(dataSource, schemaName);
|
SampleDataGenerator sampleDataGenerator = new SampleDataGenerator(dataSource, schemaName);
|
||||||
sampleDataGenerator.generateSampleData();
|
sampleDataGenerator.generateSampleData();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testExportWorkbasketFromDomain() {
|
void testExportWorkbasketFromDomain() {
|
||||||
ResponseEntity<List<WorkbasketDefinitionResource>> response =
|
ResponseEntity<List<WorkbasketDefinitionResource>> response =
|
||||||
executeExportRequestForDomain("DOMAIN_A");
|
executeExportRequestForDomain("DOMAIN_A");
|
||||||
|
|
||||||
assertNotNull(response.getBody());
|
assertNotNull(response.getBody());
|
||||||
assertEquals(HttpStatus.OK, response.getStatusCode());
|
assertEquals(HttpStatus.OK, response.getStatusCode());
|
||||||
assertThat(response.getBody().get(0), instanceOf(WorkbasketDefinitionResource.class));
|
assertThat(response.getBody().get(0), instanceOf(WorkbasketDefinitionResource.class));
|
||||||
|
|
||||||
boolean allAuthorizationsAreEmpty = true;
|
boolean allAuthorizationsAreEmpty = true;
|
||||||
boolean allDistributionTargetsAreEmpty = true;
|
boolean allDistributionTargetsAreEmpty = true;
|
||||||
for (WorkbasketDefinitionResource workbasketDefinition : response.getBody()) {
|
for (WorkbasketDefinitionResource workbasketDefinition : response.getBody()) {
|
||||||
if (allAuthorizationsAreEmpty && !workbasketDefinition.getAuthorizations().isEmpty()) {
|
if (allAuthorizationsAreEmpty && !workbasketDefinition.getAuthorizations().isEmpty()) {
|
||||||
allAuthorizationsAreEmpty = false;
|
allAuthorizationsAreEmpty = false;
|
||||||
}
|
}
|
||||||
if (allDistributionTargetsAreEmpty
|
if (allDistributionTargetsAreEmpty
|
||||||
&& !workbasketDefinition.getDistributionTargets().isEmpty()) {
|
&& !workbasketDefinition.getDistributionTargets().isEmpty()) {
|
||||||
allDistributionTargetsAreEmpty = false;
|
allDistributionTargetsAreEmpty = false;
|
||||||
}
|
}
|
||||||
if (!allAuthorizationsAreEmpty && !allDistributionTargetsAreEmpty) {
|
if (!allAuthorizationsAreEmpty && !allDistributionTargetsAreEmpty) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assertFalse(allDistributionTargetsAreEmpty);
|
assertFalse(allDistributionTargetsAreEmpty);
|
||||||
assertFalse(allAuthorizationsAreEmpty);
|
assertFalse(allAuthorizationsAreEmpty);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testExportWorkbasketsFromWrongDomain() {
|
void testExportWorkbasketsFromWrongDomain() {
|
||||||
ResponseEntity<List<WorkbasketDefinitionResource>> response =
|
ResponseEntity<List<WorkbasketDefinitionResource>> response =
|
||||||
executeExportRequestForDomain("wrongDomain");
|
executeExportRequestForDomain("wrongDomain");
|
||||||
assertEquals(0, response.getBody().size());
|
assertEquals(0, response.getBody().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testImportEveryWorkbasketFromDomainA() throws IOException {
|
void testImportEveryWorkbasketFromDomainA() throws IOException {
|
||||||
List<WorkbasketDefinitionResource> wbList = executeExportRequestForDomain("DOMAIN_A").getBody();
|
List<WorkbasketDefinitionResource> wbList = executeExportRequestForDomain("DOMAIN_A").getBody();
|
||||||
for (WorkbasketDefinitionResource w : wbList) {
|
for (WorkbasketDefinitionResource w : wbList) {
|
||||||
expectStatusWhenExecutingImportRequestOfWorkbaskets(HttpStatus.NO_CONTENT, w);
|
expectStatusWhenExecutingImportRequestOfWorkbaskets(HttpStatus.NO_CONTENT, w);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testImportWorkbasketWithoutDistributionTargets() throws IOException {
|
void testImportWorkbasketWithoutDistributionTargets() throws IOException {
|
||||||
WorkbasketDefinitionResource w = executeExportRequestForDomain("DOMAIN_A").getBody().get(0);
|
WorkbasketDefinitionResource w = executeExportRequestForDomain("DOMAIN_A").getBody().get(0);
|
||||||
w.setDistributionTargets(new HashSet<>());
|
w.setDistributionTargets(new HashSet<>());
|
||||||
|
|
||||||
this.expectStatusWhenExecutingImportRequestOfWorkbaskets(HttpStatus.NO_CONTENT, w);
|
this.expectStatusWhenExecutingImportRequestOfWorkbaskets(HttpStatus.NO_CONTENT, w);
|
||||||
|
|
||||||
w.getWorkbasket().setKey("newKey");
|
w.getWorkbasket().setKey("newKey");
|
||||||
w.getAuthorizations().forEach(authorization -> authorization.setWorkbasketKey("newKey"));
|
w.getAuthorizations().forEach(authorization -> authorization.setWorkbasketKey("newKey"));
|
||||||
expectStatusWhenExecutingImportRequestOfWorkbaskets(HttpStatus.NO_CONTENT, w);
|
expectStatusWhenExecutingImportRequestOfWorkbaskets(HttpStatus.NO_CONTENT, w);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testImportWorkbasketWithDistributionTargetsInImportFile() throws IOException {
|
void testImportWorkbasketWithDistributionTargetsInImportFile() throws IOException {
|
||||||
List<WorkbasketDefinitionResource> wbList = executeExportRequestForDomain("DOMAIN_A").getBody();
|
List<WorkbasketDefinitionResource> wbList = executeExportRequestForDomain("DOMAIN_A").getBody();
|
||||||
|
|
||||||
WorkbasketDefinitionResource w = wbList.get(0);
|
WorkbasketDefinitionResource w = wbList.get(0);
|
||||||
w.setDistributionTargets(new HashSet<>());
|
w.setDistributionTargets(new HashSet<>());
|
||||||
String letMeBeYourDistributionTarget = w.getWorkbasket().workbasketId;
|
String letMeBeYourDistributionTarget = w.getWorkbasket().workbasketId;
|
||||||
WorkbasketDefinitionResource w2 = wbList.get(1);
|
WorkbasketDefinitionResource w2 = wbList.get(1);
|
||||||
w2.setDistributionTargets(Collections.singleton(letMeBeYourDistributionTarget));
|
w2.setDistributionTargets(Collections.singleton(letMeBeYourDistributionTarget));
|
||||||
expectStatusWhenExecutingImportRequestOfWorkbaskets(HttpStatus.NO_CONTENT, w, w2);
|
expectStatusWhenExecutingImportRequestOfWorkbaskets(HttpStatus.NO_CONTENT, w, w2);
|
||||||
|
|
||||||
this.changeWorkbasketIdOrKey(w, "fancyNewId", null);
|
this.changeWorkbasketIdOrKey(w, "fancyNewId", null);
|
||||||
w2.setDistributionTargets(Collections.singleton("fancyNewId"));
|
w2.setDistributionTargets(Collections.singleton("fancyNewId"));
|
||||||
expectStatusWhenExecutingImportRequestOfWorkbaskets(HttpStatus.NO_CONTENT, w, w2);
|
expectStatusWhenExecutingImportRequestOfWorkbaskets(HttpStatus.NO_CONTENT, w, w2);
|
||||||
|
|
||||||
this.changeWorkbasketIdOrKey(w, null, "nowImANewWB");
|
this.changeWorkbasketIdOrKey(w, null, "nowImANewWB");
|
||||||
expectStatusWhenExecutingImportRequestOfWorkbaskets(HttpStatus.NO_CONTENT, w, w2);
|
expectStatusWhenExecutingImportRequestOfWorkbaskets(HttpStatus.NO_CONTENT, w, w2);
|
||||||
|
|
||||||
this.changeWorkbasketIdOrKey(w2, null, "nowImAlsoANewWB");
|
this.changeWorkbasketIdOrKey(w2, null, "nowImAlsoANewWB");
|
||||||
expectStatusWhenExecutingImportRequestOfWorkbaskets(HttpStatus.NO_CONTENT, w, w2);
|
expectStatusWhenExecutingImportRequestOfWorkbaskets(HttpStatus.NO_CONTENT, w, w2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testImportWorkbasketWithDistributionTargetsInSystem() throws IOException {
|
void testImportWorkbasketWithDistributionTargetsInSystem() throws IOException {
|
||||||
List<WorkbasketDefinitionResource> wbList = executeExportRequestForDomain("DOMAIN_A").getBody();
|
List<WorkbasketDefinitionResource> wbList = executeExportRequestForDomain("DOMAIN_A").getBody();
|
||||||
|
|
||||||
wbList.removeIf(definition -> definition.getDistributionTargets().isEmpty());
|
wbList.removeIf(definition -> definition.getDistributionTargets().isEmpty());
|
||||||
WorkbasketDefinitionResource w = wbList.get(0);
|
WorkbasketDefinitionResource w = wbList.get(0);
|
||||||
expectStatusWhenExecutingImportRequestOfWorkbaskets(HttpStatus.NO_CONTENT, w);
|
expectStatusWhenExecutingImportRequestOfWorkbaskets(HttpStatus.NO_CONTENT, w);
|
||||||
|
|
||||||
changeWorkbasketIdOrKey(w, null, "new");
|
changeWorkbasketIdOrKey(w, null, "new");
|
||||||
expectStatusWhenExecutingImportRequestOfWorkbaskets(HttpStatus.NO_CONTENT, w);
|
expectStatusWhenExecutingImportRequestOfWorkbaskets(HttpStatus.NO_CONTENT, w);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testImportWorkbasketWithDistributionTargetsNotInSystem() throws IOException {
|
void testImportWorkbasketWithDistributionTargetsNotInSystem() throws IOException {
|
||||||
List<WorkbasketDefinitionResource> wbList = executeExportRequestForDomain("DOMAIN_A").getBody();
|
List<WorkbasketDefinitionResource> wbList = executeExportRequestForDomain("DOMAIN_A").getBody();
|
||||||
|
|
||||||
WorkbasketDefinitionResource w = wbList.get(0);
|
WorkbasketDefinitionResource w = wbList.get(0);
|
||||||
w.setDistributionTargets(Collections.singleton("invalidWorkbasketId"));
|
w.setDistributionTargets(Collections.singleton("invalidWorkbasketId"));
|
||||||
try {
|
try {
|
||||||
expectStatusWhenExecutingImportRequestOfWorkbaskets(HttpStatus.BAD_REQUEST, w);
|
expectStatusWhenExecutingImportRequestOfWorkbaskets(HttpStatus.BAD_REQUEST, w);
|
||||||
fail("Expected http-Status 400");
|
fail("Expected http-Status 400");
|
||||||
} catch (HttpClientErrorException e) {
|
} catch (HttpClientErrorException e) {
|
||||||
assertEquals(HttpStatus.BAD_REQUEST, e.getStatusCode());
|
assertEquals(HttpStatus.BAD_REQUEST, e.getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
w.getWorkbasket().setKey("anotherNewKey");
|
w.getWorkbasket().setKey("anotherNewKey");
|
||||||
try {
|
try {
|
||||||
expectStatusWhenExecutingImportRequestOfWorkbaskets(HttpStatus.BAD_REQUEST, w);
|
expectStatusWhenExecutingImportRequestOfWorkbaskets(HttpStatus.BAD_REQUEST, w);
|
||||||
fail("Expected http-Status 400");
|
fail("Expected http-Status 400");
|
||||||
} catch (HttpClientErrorException e) {
|
} catch (HttpClientErrorException e) {
|
||||||
assertEquals(HttpStatus.BAD_REQUEST, e.getStatusCode());
|
assertEquals(HttpStatus.BAD_REQUEST, e.getStatusCode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testFailOnImportDuplicates() throws IOException {
|
void testFailOnImportDuplicates() throws IOException {
|
||||||
WorkbasketDefinitionResource w = executeExportRequestForDomain("DOMAIN_A").getBody().get(0);
|
WorkbasketDefinitionResource w = executeExportRequestForDomain("DOMAIN_A").getBody().get(0);
|
||||||
try {
|
try {
|
||||||
expectStatusWhenExecutingImportRequestOfWorkbaskets(HttpStatus.CONFLICT, w, w);
|
expectStatusWhenExecutingImportRequestOfWorkbaskets(HttpStatus.CONFLICT, w, w);
|
||||||
fail("Expected http-Status 409");
|
fail("Expected http-Status 409");
|
||||||
} catch (HttpClientErrorException e) {
|
} catch (HttpClientErrorException e) {
|
||||||
assertEquals(HttpStatus.CONFLICT, e.getStatusCode());
|
assertEquals(HttpStatus.CONFLICT, e.getStatusCode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testNoErrorWhenImportWithSameIdButDifferentKeyAndDomain() throws IOException {
|
void testNoErrorWhenImportWithSameIdButDifferentKeyAndDomain() throws IOException {
|
||||||
List<WorkbasketDefinitionResource> wbList = executeExportRequestForDomain("DOMAIN_A").getBody();
|
List<WorkbasketDefinitionResource> wbList = executeExportRequestForDomain("DOMAIN_A").getBody();
|
||||||
|
|
||||||
WorkbasketDefinitionResource w = wbList.get(0);
|
WorkbasketDefinitionResource w = wbList.get(0);
|
||||||
WorkbasketDefinitionResource differentLogicalId = wbList.get(1);
|
WorkbasketDefinitionResource differentLogicalId = wbList.get(1);
|
||||||
this.changeWorkbasketIdOrKey(differentLogicalId, w.getWorkbasket().getWorkbasketId(), null);
|
this.changeWorkbasketIdOrKey(differentLogicalId, w.getWorkbasket().getWorkbasketId(), null);
|
||||||
|
|
||||||
// breaks the logic but not the script- should we really allow this case?
|
// breaks the logic but not the script- should we really allow this case?
|
||||||
WorkbasketDefinitionResource theDestroyer = wbList.get(2);
|
WorkbasketDefinitionResource theDestroyer = wbList.get(2);
|
||||||
theDestroyer.setDistributionTargets(
|
theDestroyer.setDistributionTargets(
|
||||||
Collections.singleton(differentLogicalId.getWorkbasket().workbasketId));
|
Collections.singleton(differentLogicalId.getWorkbasket().workbasketId));
|
||||||
|
|
||||||
expectStatusWhenExecutingImportRequestOfWorkbaskets(
|
expectStatusWhenExecutingImportRequestOfWorkbaskets(
|
||||||
HttpStatus.NO_CONTENT, w, differentLogicalId, theDestroyer);
|
HttpStatus.NO_CONTENT, w, differentLogicalId, theDestroyer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testErrorWhenImportWithSameAccessIdAndWorkbasket() throws IOException {
|
void testErrorWhenImportWithSameAccessIdAndWorkbasket() {
|
||||||
WorkbasketDefinitionResource w = executeExportRequestForDomain("DOMAIN_A").getBody().get(0);
|
WorkbasketDefinitionResource w = executeExportRequestForDomain("DOMAIN_A").getBody().get(0);
|
||||||
|
|
||||||
String w1String = workbasketToString(w);
|
String w1String = workbasketToString(w);
|
||||||
w.getWorkbasket().setKey("new Key for this WB");
|
w.getWorkbasket().setKey("new Key for this WB");
|
||||||
String w2String = workbasketToString(w);
|
String w2String = workbasketToString(w);
|
||||||
Assertions.assertThrows(
|
Assertions.assertThrows(
|
||||||
HttpClientErrorException.class,
|
HttpClientErrorException.class,
|
||||||
() ->
|
() ->
|
||||||
expectStatusWhenExecutingImportRequestOfWorkbaskets(
|
expectStatusWhenExecutingImportRequestOfWorkbaskets(
|
||||||
HttpStatus.CONFLICT, Arrays.asList(w1String, w2String)));
|
HttpStatus.CONFLICT, Arrays.asList(w1String, w2String)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void changeWorkbasketIdOrKey(
|
private void changeWorkbasketIdOrKey(
|
||||||
WorkbasketDefinitionResource w, String newId, String newKey) {
|
WorkbasketDefinitionResource w, String newId, String newKey) {
|
||||||
if (newId != null && !newId.isEmpty()) {
|
if (newId != null && !newId.isEmpty()) {
|
||||||
w.getWorkbasket().setWorkbasketId(newId);
|
w.getWorkbasket().setWorkbasketId(newId);
|
||||||
w.getAuthorizations().forEach(auth -> auth.setWorkbasketId(newId));
|
w.getAuthorizations().forEach(auth -> auth.setWorkbasketId(newId));
|
||||||
}
|
}
|
||||||
if (newKey != null && !newKey.isEmpty()) {
|
if (newKey != null && !newKey.isEmpty()) {
|
||||||
w.getWorkbasket().setKey(newKey);
|
w.getWorkbasket().setKey(newKey);
|
||||||
w.getAuthorizations().forEach(auth -> auth.setWorkbasketKey(newKey));
|
w.getAuthorizations().forEach(auth -> auth.setWorkbasketKey(newKey));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ResponseEntity<List<WorkbasketDefinitionResource>> executeExportRequestForDomain(
|
private ResponseEntity<List<WorkbasketDefinitionResource>> executeExportRequestForDomain(
|
||||||
String domain) {
|
String domain) {
|
||||||
return template.exchange(
|
return template.exchange(
|
||||||
restHelper.toUrl(Mapping.URL_WORKBASKETDEFIITIONS) + "?domain=" + domain,
|
restHelper.toUrl(Mapping.URL_WORKBASKETDEFIITIONS) + "?domain=" + domain,
|
||||||
HttpMethod.GET,
|
HttpMethod.GET,
|
||||||
restHelper.defaultRequest(),
|
restHelper.defaultRequest(),
|
||||||
new ParameterizedTypeReference<List<WorkbasketDefinitionResource>>() {});
|
new ParameterizedTypeReference<List<WorkbasketDefinitionResource>>() {});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void expectStatusWhenExecutingImportRequestOfWorkbaskets(
|
private void expectStatusWhenExecutingImportRequestOfWorkbaskets(
|
||||||
HttpStatus expectedStatus, WorkbasketDefinitionResource... workbaskets) throws IOException {
|
HttpStatus expectedStatus, WorkbasketDefinitionResource... workbaskets) throws IOException {
|
||||||
List<String> workbasketStrings =
|
List<String> workbasketStrings =
|
||||||
Arrays.stream(workbaskets).map(wb -> workbasketToString(wb)).collect(Collectors.toList());
|
Arrays.stream(workbaskets).map(wb -> workbasketToString(wb)).collect(Collectors.toList());
|
||||||
expectStatusWhenExecutingImportRequestOfWorkbaskets(expectedStatus, workbasketStrings);
|
expectStatusWhenExecutingImportRequestOfWorkbaskets(expectedStatus, workbasketStrings);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void expectStatusWhenExecutingImportRequestOfWorkbaskets(
|
private void expectStatusWhenExecutingImportRequestOfWorkbaskets(
|
||||||
HttpStatus expectedStatus, List<String> workbasketStrings) throws IOException {
|
HttpStatus expectedStatus, List<String> workbasketStrings) throws IOException {
|
||||||
File tmpFile = File.createTempFile("test", ".tmp");
|
File tmpFile = File.createTempFile("test", ".tmp");
|
||||||
OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(tmpFile), UTF_8);
|
OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(tmpFile), UTF_8);
|
||||||
writer.write(workbasketStrings.toString());
|
writer.write(workbasketStrings.toString());
|
||||||
writer.close();
|
writer.close();
|
||||||
|
|
||||||
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
|
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
|
||||||
HttpHeaders headers = restHelper.getHeaders();
|
HttpHeaders headers = restHelper.getHeaders();
|
||||||
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
|
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
|
||||||
body.add("file", new FileSystemResource(tmpFile));
|
body.add("file", new FileSystemResource(tmpFile));
|
||||||
|
|
||||||
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
|
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
|
||||||
String serverUrl = restHelper.toUrl(Mapping.URL_WORKBASKETDEFIITIONS);
|
String serverUrl = restHelper.toUrl(Mapping.URL_WORKBASKETDEFIITIONS);
|
||||||
|
|
||||||
ResponseEntity<Void> responseImport =
|
ResponseEntity<Void> responseImport =
|
||||||
template.postForEntity(serverUrl, requestEntity, Void.class);
|
template.postForEntity(serverUrl, requestEntity, Void.class);
|
||||||
assertEquals(expectedStatus, responseImport.getStatusCode());
|
assertEquals(expectedStatus, responseImport.getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
private String workbasketToString(WorkbasketDefinitionResource workbasketDefinitionResource) {
|
private String workbasketToString(WorkbasketDefinitionResource workbasketDefinitionResource) {
|
||||||
try {
|
try {
|
||||||
return objMapper.writeValueAsString(workbasketDefinitionResource);
|
return objMapper.writeValueAsString(workbasketDefinitionResource);
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,140 +1,138 @@
|
||||||
package pro.taskana.rest.resource;
|
package pro.taskana.rest.resource;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
import pro.taskana.TaskanaSpringBootTest;
|
import pro.taskana.TaskanaSpringBootTest;
|
||||||
import pro.taskana.common.api.exceptions.NotAuthorizedException;
|
import pro.taskana.rest.Mapping;
|
||||||
import pro.taskana.rest.Mapping;
|
import pro.taskana.workbasket.api.Workbasket;
|
||||||
import pro.taskana.workbasket.api.Workbasket;
|
import pro.taskana.workbasket.api.WorkbasketService;
|
||||||
import pro.taskana.workbasket.api.WorkbasketService;
|
import pro.taskana.workbasket.api.WorkbasketType;
|
||||||
import pro.taskana.workbasket.api.WorkbasketType;
|
import pro.taskana.workbasket.internal.WorkbasketImpl;
|
||||||
import pro.taskana.workbasket.api.exceptions.WorkbasketNotFoundException;
|
|
||||||
import pro.taskana.workbasket.internal.WorkbasketImpl;
|
/** Test for {@link WorkbasketResourceAssembler}. */
|
||||||
|
@TaskanaSpringBootTest
|
||||||
/** Test for {@link WorkbasketResourceAssembler}. */
|
class WorkbasketResourceAssemblerTest {
|
||||||
@TaskanaSpringBootTest
|
|
||||||
class WorkbasketResourceAssemblerTest {
|
@Autowired WorkbasketService workbasketService;
|
||||||
|
@Autowired WorkbasketResourceAssembler workbasketResourceAssembler;
|
||||||
@Autowired WorkbasketService workbasketService;
|
|
||||||
@Autowired WorkbasketResourceAssembler workbasketResourceAssembler;
|
@Test
|
||||||
|
void workbasketToResource() {
|
||||||
@Test
|
// given
|
||||||
void workbasketToResource() throws NotAuthorizedException, WorkbasketNotFoundException {
|
Workbasket workbasket = workbasketService.newWorkbasket("1", "DOMAIN_A");
|
||||||
// given
|
((WorkbasketImpl) workbasket).setId("ID");
|
||||||
Workbasket workbasket = workbasketService.newWorkbasket("1", "DOMAIN_A");
|
workbasket.setType(WorkbasketType.PERSONAL);
|
||||||
((WorkbasketImpl) workbasket).setId("ID");
|
workbasket.setName("Testbasket");
|
||||||
workbasket.setType(WorkbasketType.PERSONAL);
|
workbasket.setOrgLevel1("Org1");
|
||||||
workbasket.setName("Testbasket");
|
workbasket.setOrgLevel2("Org2");
|
||||||
workbasket.setOrgLevel1("Org1");
|
workbasket.setOrgLevel3("Org3");
|
||||||
workbasket.setOrgLevel2("Org2");
|
workbasket.setOrgLevel4("Org4");
|
||||||
workbasket.setOrgLevel3("Org3");
|
workbasket.setDescription("A test workbasket");
|
||||||
workbasket.setOrgLevel4("Org4");
|
workbasket.setCustom1("1");
|
||||||
workbasket.setDescription("A test workbasket");
|
workbasket.setCustom2("2");
|
||||||
workbasket.setCustom1("1");
|
workbasket.setCustom3("3");
|
||||||
workbasket.setCustom2("2");
|
workbasket.setCustom4("4");
|
||||||
workbasket.setCustom3("3");
|
workbasket.setOwner("Lars");
|
||||||
workbasket.setCustom4("4");
|
((WorkbasketImpl) workbasket).setCreated(Instant.parse("2010-01-01T12:00:00Z"));
|
||||||
workbasket.setOwner("Lars");
|
((WorkbasketImpl) workbasket).setModified(Instant.parse("2010-01-01T12:00:00Z"));
|
||||||
((WorkbasketImpl) workbasket).setCreated(Instant.parse("2010-01-01T12:00:00Z"));
|
// when
|
||||||
((WorkbasketImpl) workbasket).setModified(Instant.parse("2010-01-01T12:00:00Z"));
|
WorkbasketResource resource = workbasketResourceAssembler.toResource(workbasket);
|
||||||
// when
|
// then
|
||||||
WorkbasketResource resource = workbasketResourceAssembler.toResource(workbasket);
|
testEquality(workbasket, resource);
|
||||||
// then
|
verifyLinks(resource);
|
||||||
testEquality(workbasket, resource);
|
}
|
||||||
verifyLinks(resource);
|
|
||||||
}
|
@Test
|
||||||
|
void resourceWithoutCreated() {
|
||||||
@Test
|
// given
|
||||||
void resourceWithoutCreated() {
|
WorkbasketResource resource = new WorkbasketResource();
|
||||||
// given
|
resource.setWorkbasketId("1");
|
||||||
WorkbasketResource resource = new WorkbasketResource();
|
resource.setModified("2010-01-01T12:00:00Z");
|
||||||
resource.setWorkbasketId("1");
|
resource.setType(WorkbasketType.PERSONAL);
|
||||||
resource.setModified("2010-01-01T12:00:00Z");
|
// when
|
||||||
resource.setType(WorkbasketType.PERSONAL);
|
Workbasket workbasket = workbasketResourceAssembler.toModel(resource);
|
||||||
// when
|
// then
|
||||||
Workbasket workbasket = workbasketResourceAssembler.toModel(resource);
|
testEquality(workbasket, resource);
|
||||||
// then
|
}
|
||||||
testEquality(workbasket, resource);
|
|
||||||
}
|
@Test
|
||||||
|
void resourceWithoutModified() {
|
||||||
@Test
|
// given
|
||||||
void resourceWithoutModified() {
|
WorkbasketResource resource = new WorkbasketResource();
|
||||||
// given
|
resource.setWorkbasketId("1");
|
||||||
WorkbasketResource resource = new WorkbasketResource();
|
resource.setCreated("2010-01-01T12:00:00Z");
|
||||||
resource.setWorkbasketId("1");
|
resource.setType(WorkbasketType.PERSONAL);
|
||||||
resource.setCreated("2010-01-01T12:00:00Z");
|
// when
|
||||||
resource.setType(WorkbasketType.PERSONAL);
|
Workbasket workbasket = workbasketResourceAssembler.toModel(resource);
|
||||||
// when
|
// then
|
||||||
Workbasket workbasket = workbasketResourceAssembler.toModel(resource);
|
testEquality(workbasket, resource);
|
||||||
// then
|
}
|
||||||
testEquality(workbasket, resource);
|
|
||||||
}
|
@Test
|
||||||
|
void resourceToWorkbasket() {
|
||||||
@Test
|
// given
|
||||||
void resourceToWorkbasket() {
|
WorkbasketResource workbasketResource = new WorkbasketResource();
|
||||||
// given
|
workbasketResource.setWorkbasketId("1");
|
||||||
WorkbasketResource workbasketResource = new WorkbasketResource();
|
workbasketResource.setCreated("2010-01-01T12:00:00Z");
|
||||||
workbasketResource.setWorkbasketId("1");
|
workbasketResource.setModified("2010-01-01T12:00:00Z");
|
||||||
workbasketResource.setCreated("2010-01-01T12:00:00Z");
|
workbasketResource.setCustom1("Custom1");
|
||||||
workbasketResource.setModified("2010-01-01T12:00:00Z");
|
workbasketResource.setCustom2("Custom2");
|
||||||
workbasketResource.setCustom1("Custom1");
|
workbasketResource.setCustom3("Custom3");
|
||||||
workbasketResource.setCustom2("Custom2");
|
workbasketResource.setCustom4("Custom4");
|
||||||
workbasketResource.setCustom3("Custom3");
|
workbasketResource.setDescription("Test Ressource");
|
||||||
workbasketResource.setCustom4("Custom4");
|
workbasketResource.setDomain("DOMAIN_A");
|
||||||
workbasketResource.setDescription("Test Ressource");
|
workbasketResource.setKey("1");
|
||||||
workbasketResource.setDomain("DOMAIN_A");
|
workbasketResource.setName("Ressource");
|
||||||
workbasketResource.setKey("1");
|
workbasketResource.setOrgLevel1("Org1");
|
||||||
workbasketResource.setName("Ressource");
|
workbasketResource.setOrgLevel2("Org2");
|
||||||
workbasketResource.setOrgLevel1("Org1");
|
workbasketResource.setOrgLevel3("Org3");
|
||||||
workbasketResource.setOrgLevel2("Org2");
|
workbasketResource.setOrgLevel4("Org4");
|
||||||
workbasketResource.setOrgLevel3("Org3");
|
workbasketResource.setOwner("Lars");
|
||||||
workbasketResource.setOrgLevel4("Org4");
|
workbasketResource.setType(WorkbasketType.PERSONAL);
|
||||||
workbasketResource.setOwner("Lars");
|
// when
|
||||||
workbasketResource.setType(WorkbasketType.PERSONAL);
|
Workbasket workbasket = workbasketResourceAssembler.toModel(workbasketResource);
|
||||||
// when
|
// then
|
||||||
Workbasket workbasket = workbasketResourceAssembler.toModel(workbasketResource);
|
testEquality(workbasket, workbasketResource);
|
||||||
// then
|
}
|
||||||
testEquality(workbasket, workbasketResource);
|
|
||||||
}
|
private void verifyLinks(WorkbasketResource workbasket) {
|
||||||
|
Assert.assertEquals(5, workbasket.getLinks().size());
|
||||||
private void verifyLinks(WorkbasketResource workbasket) {
|
Assert.assertEquals(
|
||||||
Assert.assertEquals(5, workbasket.getLinks().size());
|
Mapping.URL_WORKBASKET_ID.replaceAll("\\{.*}", workbasket.getWorkbasketId()),
|
||||||
Assert.assertEquals(
|
workbasket.getLink("self").getHref());
|
||||||
Mapping.URL_WORKBASKET_ID.replaceAll("\\{.*}", workbasket.getWorkbasketId()),
|
Assert.assertEquals(
|
||||||
workbasket.getLink("self").getHref());
|
Mapping.URL_WORKBASKET_ID_DISTRIBUTION.replaceAll("\\{.*}", workbasket.getWorkbasketId()),
|
||||||
Assert.assertEquals(
|
workbasket.getLink("distributionTargets").getHref());
|
||||||
Mapping.URL_WORKBASKET_ID_DISTRIBUTION.replaceAll("\\{.*}", workbasket.getWorkbasketId()),
|
Assert.assertEquals(Mapping.URL_WORKBASKET, workbasket.getLink("allWorkbaskets").getHref());
|
||||||
workbasket.getLink("distributionTargets").getHref());
|
Assert.assertEquals(
|
||||||
Assert.assertEquals(Mapping.URL_WORKBASKET, workbasket.getLink("allWorkbaskets").getHref());
|
Mapping.URL_WORKBASKET_DISTRIBUTION_ID.replaceAll("\\{.*}", workbasket.getWorkbasketId()),
|
||||||
Assert.assertEquals(
|
workbasket.getLink("removeDistributionTargets").getHref());
|
||||||
Mapping.URL_WORKBASKET_DISTRIBUTION_ID.replaceAll("\\{.*}", workbasket.getWorkbasketId()),
|
}
|
||||||
workbasket.getLink("removeDistributionTargets").getHref());
|
|
||||||
}
|
private void testEquality(Workbasket workbasket, WorkbasketResource workbasketResource) {
|
||||||
|
Assert.assertEquals(workbasket.getId(), workbasketResource.workbasketId);
|
||||||
private void testEquality(Workbasket workbasket, WorkbasketResource workbasketResource) {
|
Assert.assertEquals(workbasket.getKey(), workbasketResource.key);
|
||||||
Assert.assertEquals(workbasket.getId(), workbasketResource.workbasketId);
|
Assert.assertEquals(
|
||||||
Assert.assertEquals(workbasket.getKey(), workbasketResource.key);
|
workbasket.getCreated() == null ? null : workbasket.getCreated().toString(),
|
||||||
Assert.assertEquals(
|
workbasketResource.created);
|
||||||
workbasket.getCreated() == null ? null : workbasket.getCreated().toString(),
|
Assert.assertEquals(
|
||||||
workbasketResource.created);
|
workbasket.getModified() == null ? null : workbasket.getModified().toString(),
|
||||||
Assert.assertEquals(
|
workbasketResource.modified);
|
||||||
workbasket.getModified() == null ? null : workbasket.getModified().toString(),
|
Assert.assertEquals(workbasket.getName(), workbasketResource.name);
|
||||||
workbasketResource.modified);
|
Assert.assertEquals(workbasket.getDescription(), workbasketResource.description);
|
||||||
Assert.assertEquals(workbasket.getName(), workbasketResource.name);
|
Assert.assertEquals(workbasket.getOwner(), workbasketResource.owner);
|
||||||
Assert.assertEquals(workbasket.getDescription(), workbasketResource.description);
|
Assert.assertEquals(workbasket.getDomain(), workbasketResource.domain);
|
||||||
Assert.assertEquals(workbasket.getOwner(), workbasketResource.owner);
|
Assert.assertEquals(workbasket.getType(), workbasketResource.type);
|
||||||
Assert.assertEquals(workbasket.getDomain(), workbasketResource.domain);
|
Assert.assertEquals(workbasket.getCustom1(), workbasketResource.custom1);
|
||||||
Assert.assertEquals(workbasket.getType(), workbasketResource.type);
|
Assert.assertEquals(workbasket.getCustom2(), workbasketResource.custom2);
|
||||||
Assert.assertEquals(workbasket.getCustom1(), workbasketResource.custom1);
|
Assert.assertEquals(workbasket.getCustom3(), workbasketResource.custom3);
|
||||||
Assert.assertEquals(workbasket.getCustom2(), workbasketResource.custom2);
|
Assert.assertEquals(workbasket.getCustom4(), workbasketResource.custom4);
|
||||||
Assert.assertEquals(workbasket.getCustom3(), workbasketResource.custom3);
|
Assert.assertEquals(workbasket.getOrgLevel1(), workbasketResource.orgLevel1);
|
||||||
Assert.assertEquals(workbasket.getCustom4(), workbasketResource.custom4);
|
Assert.assertEquals(workbasket.getOrgLevel2(), workbasketResource.orgLevel2);
|
||||||
Assert.assertEquals(workbasket.getOrgLevel1(), workbasketResource.orgLevel1);
|
Assert.assertEquals(workbasket.getOrgLevel3(), workbasketResource.orgLevel3);
|
||||||
Assert.assertEquals(workbasket.getOrgLevel2(), workbasketResource.orgLevel2);
|
Assert.assertEquals(workbasket.getOrgLevel4(), workbasketResource.orgLevel4);
|
||||||
Assert.assertEquals(workbasket.getOrgLevel3(), workbasketResource.orgLevel3);
|
}
|
||||||
Assert.assertEquals(workbasket.getOrgLevel4(), workbasketResource.orgLevel4);
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue