Dependency injection applied on DMPs and some API route name changes.
This commit is contained in:
parent
9467d2b9ee
commit
339f65f499
|
@ -46,72 +46,73 @@ public class DMPs extends BaseController {
|
|||
|
||||
private DynamicProjectConfiguration dynamicProjectConfiguration;
|
||||
private Environment environment;
|
||||
private DataManagementPlanManager dataManagementPlanManager;
|
||||
|
||||
@Autowired
|
||||
public DMPs(ApiContext apiContext, DynamicProjectConfiguration dynamicProjectConfiguration, Environment environment) {
|
||||
public DMPs(ApiContext apiContext, DynamicProjectConfiguration dynamicProjectConfiguration, Environment environment, DataManagementPlanManager dataManagementPlanManager) {
|
||||
super(apiContext);
|
||||
this.dynamicProjectConfiguration = dynamicProjectConfiguration;
|
||||
this.environment = environment;
|
||||
|
||||
this.dataManagementPlanManager = dataManagementPlanManager;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@RequestMapping(method = RequestMethod.GET, value = {"{id}/unlock"}, produces = "application/json")
|
||||
public @ResponseBody
|
||||
ResponseEntity<ResponseItem<DMP>> unlock(@PathVariable(value = "id") UUID id, Principal principal) throws Exception {
|
||||
new DataManagementPlanManager().unlock(this.getApiContext(), id);
|
||||
this.dataManagementPlanManager.unlock(this.getApiContext(), id);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Unlocked"));
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, value = {"/getPaged"}, consumes = "application/json", produces = "application/json")
|
||||
@RequestMapping(method = RequestMethod.POST, value = {"/paged"}, consumes = "application/json", produces = "application/json")
|
||||
public @ResponseBody
|
||||
ResponseEntity<ResponseItem<DataTableData<DataManagementPlanListingModel>>> getPaged(@Valid @RequestBody DataManagementPlanTableRequest dataManagementPlanTableRequest, Principal principal) throws Exception {
|
||||
DataTableData<DataManagementPlanListingModel> dataTable = new DataManagementPlanManager().getPaged(this.getApiContext(), dataManagementPlanTableRequest, principal);
|
||||
DataTableData<DataManagementPlanListingModel> dataTable = this.dataManagementPlanManager.getPaged(this.getApiContext(), dataManagementPlanTableRequest, principal);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DataManagementPlanListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable));
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET, value = {"/getSingle/{id}"}, produces = "application/json")
|
||||
@RequestMapping(method = RequestMethod.GET, value = {"{id}"}, produces = "application/json")
|
||||
public @ResponseBody
|
||||
ResponseEntity<ResponseItem<DataManagementPlan>> getSingle(@PathVariable String id, Principal principal) throws IllegalAccessException, InstantiationException {
|
||||
eu.eudat.models.data.dmp.DataManagementPlan dataManagementPlan = new DataManagementPlanManager().getSingle(this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao(), id, principal, this.dynamicProjectConfiguration);
|
||||
eu.eudat.models.data.dmp.DataManagementPlan dataManagementPlan = this.dataManagementPlanManager.getSingle(this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao(), id, principal, this.dynamicProjectConfiguration);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataManagementPlan>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlan));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@RequestMapping(method = RequestMethod.POST, value = {"/createOrUpdate"}, consumes = "application/json", produces = "application/json")
|
||||
@RequestMapping(method = RequestMethod.POST, value = {"/post"}, consumes = "application/json", produces = "application/json")
|
||||
public @ResponseBody
|
||||
ResponseEntity<ResponseItem<DMP>> createOrUpdate(@RequestBody eu.eudat.models.data.dmp.DataManagementPlan dataManagementPlan, Principal principal) throws Exception {
|
||||
DataManagementPlanManager.createOrUpdate(this.getApiContext(), dataManagementPlan, principal);
|
||||
this.dataManagementPlanManager.createOrUpdate(this.getApiContext(), dataManagementPlan, principal);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created"));
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, value = {"/new/{id}"}, consumes = "application/json", produces = "application/json")
|
||||
public @ResponseBody
|
||||
ResponseEntity<ResponseItem<DMP>> newVersion(@PathVariable UUID id, @Valid @RequestBody eu.eudat.models.data.dmp.DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception {
|
||||
DataManagementPlanManager.newVersion(this.getApiContext(), id, dataManagementPlan, principal);
|
||||
this.dataManagementPlanManager.newVersion(this.getApiContext(), id, dataManagementPlan, principal);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.NO_MESSAGE));
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, value = {"/clone/{id}"}, consumes = "application/json", produces = "application/json")
|
||||
public @ResponseBody
|
||||
ResponseEntity<ResponseItem<DMP>> clone(@PathVariable UUID id, @RequestBody eu.eudat.models.data.dmp.DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception {
|
||||
DataManagementPlanManager.clone(this.getApiContext(), id, dataManagementPlan, principal);
|
||||
this.dataManagementPlanManager.clone(this.getApiContext(), id, dataManagementPlan, principal);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.NO_MESSAGE));
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, value = {"/get"}, consumes = "application/json", produces = "application/json")
|
||||
public @ResponseBody
|
||||
ResponseEntity<ResponseItem<List<DataManagementPlan>>> getWithCriteria(@RequestBody DataManagementPlanCriteriaRequest dataManagementPlanCriteria, Principal principal) throws InstantiationException, IllegalAccessException {
|
||||
List<DataManagementPlan> dataTable = new DataManagementPlanManager().getWithCriteria(this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao(), dataManagementPlanCriteria, principal);
|
||||
List<DataManagementPlan> dataTable = this.dataManagementPlanManager.getWithCriteria(this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao(), dataManagementPlanCriteria, principal);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<DataManagementPlan>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@RequestMapping(method = RequestMethod.DELETE, value = {"/delete/{id}"}, consumes = "application/json", produces = "application/json")
|
||||
@RequestMapping(method = RequestMethod.DELETE, value = {"{id}"}, consumes = "application/json", produces = "application/json")
|
||||
public @ResponseBody
|
||||
ResponseEntity<ResponseItem<DMP>> delete(@PathVariable UUID id, Principal principal) {
|
||||
try{
|
||||
DataManagementPlanManager.delete(this.getApiContext(), id);
|
||||
this.dataManagementPlanManager.delete(this.getApiContext(), id);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully Deleted Datamanagement Plan"));
|
||||
}catch (DMPWithDatasetsDeleteException exception){
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DMP>().status(ApiMessageCode.ERROR_MESSAGE).message(exception.getMessage()));
|
||||
|
@ -122,14 +123,14 @@ public class DMPs extends BaseController {
|
|||
@RequestMapping(method = RequestMethod.POST, value = {"/dynamic"}, consumes = "application/json", produces = "application/json")
|
||||
public @ResponseBody
|
||||
ResponseEntity<ResponseItem<List<Tuple<String, String>>>> getWithCriteria(@RequestBody RequestItem<DynamicFieldsCriteria> criteriaRequestItem, Principal principal) throws InstantiationException, IllegalAccessException {
|
||||
List<Tuple<String, String>> dataTable = new DataManagementPlanManager().getDynamicFields(criteriaRequestItem.getCriteria().getId(), this.dynamicProjectConfiguration, criteriaRequestItem.getCriteria());
|
||||
List<Tuple<String, String>> dataTable = this.dataManagementPlanManager.getDynamicFields(criteriaRequestItem.getCriteria().getId(), this.dynamicProjectConfiguration, criteriaRequestItem.getCriteria());
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<Tuple<String, String>>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable));
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET, value = {"/getXml/{id}"})
|
||||
public @ResponseBody
|
||||
ResponseEntity<byte[]> getXml(@PathVariable String id) throws IllegalAccessException, IOException, InstantiationException {
|
||||
FileEnvelope envelope = new DataManagementPlanManager().getXmlDocument(this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao(), id, this.getApiContext().getUtilitiesService().getVisibilityRuleService());
|
||||
FileEnvelope envelope = this.dataManagementPlanManager.getXmlDocument(this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao(), id, this.getApiContext().getUtilitiesService().getVisibilityRuleService());
|
||||
InputStream resource = new FileInputStream(envelope.getFile());
|
||||
System.out.println("Mime Type of " + envelope.getFilename() + " is " +
|
||||
new MimetypesFileTypeMap().getContentType(envelope.getFile()));
|
||||
|
@ -149,7 +150,7 @@ public class DMPs extends BaseController {
|
|||
@RequestMapping(method = RequestMethod.GET, value = {"/getWord/{id}"})
|
||||
public @ResponseBody
|
||||
ResponseEntity<byte[]> getWordDocument(@PathVariable String id) throws IOException, IllegalAccessException, InstantiationException {
|
||||
File file = new DataManagementPlanManager().getWordDocument(this.environment, this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao(), id, this.getApiContext().getUtilitiesService().getVisibilityRuleService());
|
||||
File file = this.dataManagementPlanManager.getWordDocument(this.environment, this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao(), id, this.getApiContext().getUtilitiesService().getVisibilityRuleService());
|
||||
InputStream resource = new FileInputStream(file);
|
||||
System.out.println("Mime Type of " + file.getName() + " is " +
|
||||
new MimetypesFileTypeMap().getContentType(file));
|
||||
|
@ -169,7 +170,7 @@ public class DMPs extends BaseController {
|
|||
@RequestMapping(method = RequestMethod.GET, value = {"/getPDF/{id}"})
|
||||
public @ResponseBody
|
||||
ResponseEntity<byte[]> getPDFDocument(@PathVariable String id) throws IllegalAccessException, IOException, InstantiationException, InterruptedException {
|
||||
File file = new DataManagementPlanManager().getWordDocument(this.environment, this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao(), id, this.getApiContext().getUtilitiesService().getVisibilityRuleService());
|
||||
File file = this.dataManagementPlanManager.getWordDocument(this.environment, this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao(), id, this.getApiContext().getUtilitiesService().getVisibilityRuleService());
|
||||
File pdffile = new DatasetManager().convertToPDF(file, environment, file.getName());
|
||||
InputStream resource = new FileInputStream(pdffile);
|
||||
System.out.println("Mime Type of " + file.getName() + " is " +
|
||||
|
|
|
@ -36,6 +36,7 @@ import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
|||
import org.json.JSONObject;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
@ -48,6 +49,7 @@ import java.util.*;
|
|||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
public class DataManagementPlanManager {
|
||||
|
||||
public DataTableData<DataManagementPlanListingModel> getPaged(ApiContext apiContext, DataManagementPlanTableRequest dataManagementPlanTableRequest, Principal principal) throws Exception {
|
||||
|
@ -208,7 +210,7 @@ public class DataManagementPlanManager {
|
|||
return result;
|
||||
}
|
||||
|
||||
public static void createOrUpdate(ApiContext apiContext, DataManagementPlan dataManagementPlan, Principal principal) throws Exception {
|
||||
public void createOrUpdate(ApiContext apiContext, DataManagementPlan dataManagementPlan, Principal principal) throws Exception {
|
||||
DMP newDmp = dataManagementPlan.toDataModel();
|
||||
createOrganisationsIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getOrganisationDao());
|
||||
createResearchersIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao());
|
||||
|
@ -226,7 +228,7 @@ public class DataManagementPlanManager {
|
|||
assignUser(newDmp, user, apiContext);
|
||||
}
|
||||
|
||||
public static void assignUser(DMP dmp, UserInfo userInfo, ApiContext apiContext) {
|
||||
public void assignUser(DMP dmp, UserInfo userInfo, ApiContext apiContext) {
|
||||
UserDMP userDMP = new UserDMP();
|
||||
userDMP.setDmp(dmp);
|
||||
userDMP.setUser(userInfo);
|
||||
|
@ -234,7 +236,7 @@ public class DataManagementPlanManager {
|
|||
apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().createOrUpdate(userDMP);
|
||||
}
|
||||
|
||||
public static void newVersion(ApiContext apiContext, UUID uuid, DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception {
|
||||
public void newVersion(ApiContext apiContext, UUID uuid, DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception {
|
||||
DMP oldDmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(uuid);
|
||||
DMP newDmp = dataManagementPlan.toDataModel();
|
||||
createOrganisationsIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getOrganisationDao());
|
||||
|
@ -249,7 +251,7 @@ public class DataManagementPlanManager {
|
|||
copyDatasets(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao());
|
||||
}
|
||||
|
||||
public static void clone(ApiContext apiContext, UUID uuid, DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception {
|
||||
public void clone(ApiContext apiContext, UUID uuid, DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception {
|
||||
DMP newDmp = dataManagementPlan.toDataModel();
|
||||
createOrganisationsIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getOrganisationDao());
|
||||
createResearchersIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao());
|
||||
|
@ -263,7 +265,7 @@ public class DataManagementPlanManager {
|
|||
copyDatasets(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao());
|
||||
}
|
||||
|
||||
public static void delete(ApiContext apiContext, UUID uuid) throws DMPWithDatasetsDeleteException {
|
||||
public void delete(ApiContext apiContext, UUID uuid) throws DMPWithDatasetsDeleteException {
|
||||
DMP oldDmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(uuid);
|
||||
if (oldDmp.getDataset().size() > 0)
|
||||
throw new DMPWithDatasetsDeleteException("You cannot Remove Datamanagement Plan with Datasets");
|
||||
|
@ -271,7 +273,7 @@ public class DataManagementPlanManager {
|
|||
apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(oldDmp);
|
||||
}
|
||||
|
||||
private static void createResearchersIfTheyDontExist(DMP newDmp, ResearcherDao researcherRepository) {
|
||||
private void createResearchersIfTheyDontExist(DMP newDmp, ResearcherDao researcherRepository) {
|
||||
if (newDmp.getResearchers() != null && !newDmp.getResearchers().isEmpty()) {
|
||||
for (eu.eudat.data.entities.Researcher researcher : newDmp.getResearchers()) {
|
||||
ResearcherCriteria criteria = new ResearcherCriteria();
|
||||
|
@ -283,7 +285,7 @@ public class DataManagementPlanManager {
|
|||
}
|
||||
}
|
||||
|
||||
private static void createOrganisationsIfTheyDontExist(DMP newDmp, OrganisationDao organisationRepository) {
|
||||
private void createOrganisationsIfTheyDontExist(DMP newDmp, OrganisationDao organisationRepository) {
|
||||
if (newDmp.getOrganisations() != null && !newDmp.getOrganisations().isEmpty()) {
|
||||
for (eu.eudat.data.entities.Organisation organisation : newDmp.getOrganisations()) {
|
||||
OrganisationCriteria criteria = new OrganisationCriteria();
|
||||
|
@ -295,7 +297,7 @@ public class DataManagementPlanManager {
|
|||
}
|
||||
}
|
||||
|
||||
private static void createProjectIfItDoesntExist(DMP newDmp, ProjectDao projectDao, UserInfo userInfo) {
|
||||
private void createProjectIfItDoesntExist(DMP newDmp, ProjectDao projectDao, UserInfo userInfo) {
|
||||
if (newDmp.getProject() != null) {
|
||||
Project project = newDmp.getProject();
|
||||
ProjectCriteria criteria = new ProjectCriteria();
|
||||
|
@ -310,7 +312,7 @@ public class DataManagementPlanManager {
|
|||
}
|
||||
|
||||
|
||||
private static void copyDatasets(DMP newDmp, DatasetDao datasetDao) {
|
||||
private void copyDatasets(DMP newDmp, DatasetDao datasetDao) {
|
||||
List<CompletableFuture<Dataset>> futures = new LinkedList<>();
|
||||
for (Dataset dataset : newDmp.getDataset()) {
|
||||
datasetDao.asQueryable().withHint(HintedModelFactory.getHint(DatasetListingModel.class)).where((builder, root) -> builder.equal(root.get("id"), dataset.getId())).getSingleAsync()
|
||||
|
|
|
@ -24,18 +24,18 @@ export class DmpService {
|
|||
}
|
||||
|
||||
getPaged(dataTableRequest: DataTableRequest<DmpCriteria>): Observable<DataTableData<DmpListingModel>> {
|
||||
return this.http.post<DataTableData<DmpListingModel>>(this.actionUrl + 'getPaged', dataTableRequest, { headers: this.headers });
|
||||
return this.http.post<DataTableData<DmpListingModel>>(this.actionUrl + 'paged', dataTableRequest, { headers: this.headers });
|
||||
}
|
||||
|
||||
getSingle(id: String): Observable<DmpModel> {
|
||||
return this.http.get<DmpModel>(this.actionUrl + 'getSingle/' + id, { headers: this.headers });
|
||||
return this.http.get<DmpModel>(this.actionUrl + id, { headers: this.headers }); //'getSingle/' +
|
||||
}
|
||||
|
||||
unlock(id: String): Observable<DmpModel> {
|
||||
return this.http.get<DmpModel>(this.actionUrl + id + '/unlock', { headers: this.headers });
|
||||
}
|
||||
createDmp(dataManagementPlanModel: DmpModel): Observable<DmpModel> {
|
||||
return this.http.post<DmpModel>(this.actionUrl + 'createOrUpdate', dataManagementPlanModel, { headers: this.headers });
|
||||
return this.http.post<DmpModel>(this.actionUrl + 'post', dataManagementPlanModel, { headers: this.headers });
|
||||
}
|
||||
|
||||
inactivate(id: String): Observable<DmpModel> {
|
||||
|
@ -55,7 +55,7 @@ export class DmpService {
|
|||
}
|
||||
|
||||
delete(id: String): Observable<DmpModel> {
|
||||
return this.http.delete<DmpModel>(this.actionUrl + 'delete/' + id, { headers: this.headers });
|
||||
return this.http.delete<DmpModel>(this.actionUrl + id, { headers: this.headers }); // + 'delete/'
|
||||
}
|
||||
|
||||
getDynamicField(requestItem: RequestItem<DynamicFieldProjectCriteria>): any {
|
||||
|
|
Loading…
Reference in New Issue