From 3f5a627d18b37ea8c7d8da6cefc7ad15b81ad0ea Mon Sep 17 00:00:00 2001 From: annabakouli Date: Wed, 3 Jan 2018 18:36:31 +0200 Subject: [PATCH 1/2] no message --- .../main/java/eu/eudat/controllers/Admin.java | 11 ++++- .../eu/eudat/controllers/BaseController.java | 5 +++ .../java/eu/eudat/controllers/Projects.java | 2 +- .../datasetprofiledefinition/Field.java | 38 +++++++++++++++- .../datasetprofiledefinition/FieldSet.java | 2 +- .../components/datasetprofile/Field.java | 35 ++++++++++++++- .../errormodels/ValidationErrorContext.java | 14 +----- .../user/components/datasetprofile/Field.java | 13 +++++- .../validators/DatasetProfileValidator.java | 30 +++++++++++++ .../validators/ProjectModelValidator.java | 29 ++++++++++++ .../src/main/resources/messages.properties | 4 +- .../dataset-wizard.component.ts | 4 +- .../app/dmps/editor/dmp-editor.component.ts | 2 +- .../src/app/form/dynamic-form.component.ts | 2 +- .../src/app/homepage/homepage.component.ts | 2 +- dmp-frontend/src/app/models/CompositeField.ts | 6 +-- .../models/DatasetProfileDefinitionModel.ts | 4 +- dmp-frontend/src/app/models/Field.ts | 6 +-- dmp-frontend/src/app/models/FieldGroup.ts | 2 +- dmp-frontend/src/app/models/Section.ts | 4 +- .../DataManagementPlanModel.ts | 8 ++-- .../src/app/models/datasets/DatasetModel.ts | 6 +-- .../app/models/datasets/DatasetWizardModel.ts | 12 ++--- .../editor/project-editor.component.html | 2 +- .../editor/project-editor.component.ts | 44 ++++++++++++++++--- .../src/app/services/auth/auth.service.ts | 4 +- .../src/app/utilities/JsonSerializer.ts | 6 +-- 27 files changed, 236 insertions(+), 61 deletions(-) create mode 100644 dmp-backend/src/main/java/eu/eudat/validators/DatasetProfileValidator.java create mode 100644 dmp-backend/src/main/java/eu/eudat/validators/ProjectModelValidator.java diff --git a/dmp-backend/src/main/java/eu/eudat/controllers/Admin.java b/dmp-backend/src/main/java/eu/eudat/controllers/Admin.java index acacd3b52..e183071d2 100644 --- a/dmp-backend/src/main/java/eu/eudat/controllers/Admin.java +++ b/dmp-backend/src/main/java/eu/eudat/controllers/Admin.java @@ -6,6 +6,7 @@ import eu.eudat.dao.entities.*; import eu.eudat.managers.DashBoardManager; import eu.eudat.models.dashboard.DashBoardStatistics; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.CrossOrigin; @@ -19,10 +20,16 @@ import eu.eudat.managers.AdminManager; import eu.eudat.models.admin.composite.DatasetProfile; import javax.transaction.Transactional; +import javax.validation.Valid; @RestController @CrossOrigin -public class Admin { +public class Admin extends BaseController{ + + @Autowired + public Admin(ApplicationContext springContext) { + super(springContext); + } @Autowired private DatasetProfileDao datasetProfileDao; @Autowired private DatasetProfileRulesetDao datasetProfileRulesetDao; @@ -30,7 +37,7 @@ public class Admin { @Transactional @RequestMapping(method = RequestMethod.POST, value = { "/admin/addDmp" },consumes = "application/json", produces="application/json") - public ResponseEntity addDmp(@RequestBody DatasetProfile profile){ + public ResponseEntity addDmp(@Valid @RequestBody DatasetProfile profile){ try{ eu.eudat.entities.DatasetProfile modelDefinition = AdminManager.generateViewStyleDefinition(profile); datasetProfileDao.createOrUpdate(modelDefinition); diff --git a/dmp-backend/src/main/java/eu/eudat/controllers/BaseController.java b/dmp-backend/src/main/java/eu/eudat/controllers/BaseController.java index 164657957..a766aec8d 100644 --- a/dmp-backend/src/main/java/eu/eudat/controllers/BaseController.java +++ b/dmp-backend/src/main/java/eu/eudat/controllers/BaseController.java @@ -1,6 +1,8 @@ package eu.eudat.controllers; import eu.eudat.validators.DataManagementPlanTableRequestValidator; +import eu.eudat.validators.DatasetProfileValidator; +import eu.eudat.validators.ProjectModelValidator; import eu.eudat.validators.ProjectTableRequestValidator; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; @@ -22,5 +24,8 @@ public abstract class BaseController { protected void initBinder(WebDataBinder binder) { if (binder.getTarget() != null && DataManagementPlanTableRequestValidator.supportsType((binder.getTarget().getClass()))) binder.addValidators(this.springContext.getBean("dataManagementPlanTableRequestValidator",DataManagementPlanTableRequestValidator.class)); if (binder.getTarget() != null && ProjectTableRequestValidator.supportsType((binder.getTarget().getClass()))) binder.addValidators(this.springContext.getBean("projectTableRequestValidator",ProjectTableRequestValidator.class)); + if (binder.getTarget() != null && DatasetProfileValidator.supportsType((binder.getTarget().getClass()))) binder.addValidators(this.springContext.getBean("datasetProfileValidator",DatasetProfileValidator.class)); + if (binder.getTarget() != null && ProjectModelValidator.supportsType((binder.getTarget().getClass()))) binder.addValidators(this.springContext.getBean("projectModelValidator",ProjectModelValidator.class)); + } } diff --git a/dmp-backend/src/main/java/eu/eudat/controllers/Projects.java b/dmp-backend/src/main/java/eu/eudat/controllers/Projects.java index 862a4a1ea..424f4bbda 100644 --- a/dmp-backend/src/main/java/eu/eudat/controllers/Projects.java +++ b/dmp-backend/src/main/java/eu/eudat/controllers/Projects.java @@ -110,7 +110,7 @@ public class Projects extends BaseController{ @Transactional @RequestMapping(method = RequestMethod.POST, value = { "/projects/createOrUpdate" }, consumes = "application/json", produces="application/json") - public @ResponseBody ResponseItem addProject(@RequestBody eu.eudat.models.project.Project project, Principal principal) { + public @ResponseBody ResponseItem addProject(@Valid @RequestBody eu.eudat.models.project.Project project, Principal principal) { try { ProjectManager.createOrUpdate(projectDao,userInfoDao,project,principal); return new ResponseItem().status(HttpStatus.OK); diff --git a/dmp-backend/src/main/java/eu/eudat/entities/xmlmodels/datasetprofiledefinition/Field.java b/dmp-backend/src/main/java/eu/eudat/entities/xmlmodels/datasetprofiledefinition/Field.java index 43044298d..48f91df17 100644 --- a/dmp-backend/src/main/java/eu/eudat/entities/xmlmodels/datasetprofiledefinition/Field.java +++ b/dmp-backend/src/main/java/eu/eudat/entities/xmlmodels/datasetprofiledefinition/Field.java @@ -1,7 +1,6 @@ package eu.eudat.entities.xmlmodels.datasetprofiledefinition; import eu.eudat.models.components.commons.DefaultValue; -import eu.eudat.models.components.commons.Multiplicity; import org.w3c.dom.Document; import org.w3c.dom.Element; import eu.eudat.models.components.commons.ViewStyle; @@ -10,6 +9,11 @@ import eu.eudat.models.components.commons.datafield.FieldData; import eu.eudat.utilities.XmlSerializable; import eu.eudat.utilities.builders.ModelBuilder; import eu.eudat.utilities.builders.XmlBuilder; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import java.util.LinkedList; +import java.util.List; public class Field implements DatabaseViewStyleDefinition,XmlSerializable{ private String id; @@ -18,6 +22,8 @@ public class Field implements DatabaseViewStyleDefinition,XmlSerializable private DefaultValue defaultValue; private Visibility visible; private FieldData data; + private List validations; + public String getId() { return id; } @@ -58,6 +64,15 @@ public class Field implements DatabaseViewStyleDefinition,XmlSerializable public void setVisible(Visibility visible) { this.visible = visible; } + + public List getValidations() { + return validations; + } + + public void setValidations(List validations) { + this.validations = validations; + } + @Override public Element toXml(Document doc) { Element rootElement = doc.createElement("field"); @@ -74,6 +89,14 @@ public class Field implements DatabaseViewStyleDefinition,XmlSerializable defaultValue.setAttribute("type",this.defaultValue.getType()); defaultValue.setAttribute("value",this.defaultValue.getValue()); + Element validations = doc.createElement("validations"); + for(eu.eudat.models.admin.components.datasetprofile.Field.ValidationType validationType: this.validations){ + Element validation = doc.createElement("validation"); + validation.setAttribute("type",""+validationType.getValue()); + validations.appendChild(validation); + } + + rootElement.appendChild(validations); rootElement.appendChild(defaultValue); rootElement.appendChild(visibility); rootElement.appendChild(viewStyle); @@ -105,6 +128,19 @@ public class Field implements DatabaseViewStyleDefinition,XmlSerializable this.data = new ModelBuilder().toFieldData(null, this.viewStyle.getRenderStyle(),dataElement); if(this.data!=null)this.data.fromXml(dataElement); + this.validations = new LinkedList<>(); + Element validations = (Element)XmlBuilder.getNodeFromListByTagName(element.getChildNodes(), "validations"); + if(validations!=null){ + NodeList validationElements = validations.getChildNodes(); + for (int temp = 0; temp < validationElements.getLength(); temp++) { + Node validationElement = validationElements.item(temp); + if (validationElement.getNodeType() == Node.ELEMENT_NODE) { + int enumValue = Integer.parseInt(((Element)validationElement).getAttribute("type")); + eu.eudat.models.admin.components.datasetprofile.Field.ValidationType validationType = eu.eudat.models.admin.components.datasetprofile.Field.ValidationType.fromInteger(enumValue); + this.validations.add(validationType); + } + } + } return this; } diff --git a/dmp-backend/src/main/java/eu/eudat/entities/xmlmodels/datasetprofiledefinition/FieldSet.java b/dmp-backend/src/main/java/eu/eudat/entities/xmlmodels/datasetprofiledefinition/FieldSet.java index 2128c1058..914f7ccba 100644 --- a/dmp-backend/src/main/java/eu/eudat/entities/xmlmodels/datasetprofiledefinition/FieldSet.java +++ b/dmp-backend/src/main/java/eu/eudat/entities/xmlmodels/datasetprofiledefinition/FieldSet.java @@ -126,7 +126,7 @@ public class FieldSet implements DatabaseViewStyleDefinition,XmlSerializable,Comparable{ + + public enum ValidationType { + REQUIRED((short) 1); + private short value; + private ValidationType(short value) { this.value = value; } + public short getValue(){return value;} + public static ValidationType fromInteger(int value) { + switch (value) { + case 1: + return REQUIRED; + default: + throw new RuntimeException("Unsupported Project Status"); + } + } + public static List fromIntegers(List values){ + return values.stream().map(ValidationType::fromInteger).collect(Collectors.toList()); + } + } + private String id; private Integer ordinal; private String value; @@ -21,7 +44,7 @@ public class Field implements ViewStyleDefinition validations; public String getId() { return id; } @@ -84,6 +107,14 @@ public class Field implements ViewStyleDefinition getValidations() { + return this.validations.stream().map(item->(int)item.getValue()).collect(Collectors.toList()); + } + + public void setValidations(List validations) { + this.validations = ValidationType.fromIntegers(validations); + } + @Override public eu.eudat.entities.xmlmodels.datasetprofiledefinition.Field toDatabaseDefinition(eu.eudat.entities.xmlmodels.datasetprofiledefinition.Field field) { if(this.id == null||this.id.isEmpty())this.id = "field_"+RandomStringUtils.random(5, true, true); @@ -94,6 +125,7 @@ public class Field implements ViewStyleDefinition error = new HashMap<>(); - - public Map getError() { - return error; - } - - public void setError(Map error) { - this.error = error; - } +public class ValidationErrorContext extends HashMap{ public ValidationErrorContext() { } - public void addFieldError(String path, String message) { - error.put(path,message); + this.put(path,message); } } diff --git a/dmp-backend/src/main/java/eu/eudat/models/user/components/datasetprofile/Field.java b/dmp-backend/src/main/java/eu/eudat/models/user/components/datasetprofile/Field.java index 30984948f..85bae57b5 100644 --- a/dmp-backend/src/main/java/eu/eudat/models/user/components/datasetprofile/Field.java +++ b/dmp-backend/src/main/java/eu/eudat/models/user/components/datasetprofile/Field.java @@ -26,6 +26,7 @@ public class Field implements Comparable,PropertiesModelBuilder,ViewStyleDefinit private Multiplicity multiplicity; private Object data; private List multiplicityItems; + private List validations; private Visibility visible; public List getMultiplicityItems() { return multiplicityItems; @@ -104,6 +105,14 @@ public class Field implements Comparable,PropertiesModelBuilder,ViewStyleDefinit this.visible = visible; } + public List getValidations() { + return validations; + } + + public void setValidations(List validations) { + this.validations = validations; + } + public Field cloneForMultiplicity(String key, Map properties){ Field newField = new Field(); newField.id = key; @@ -114,7 +123,7 @@ public class Field implements Comparable,PropertiesModelBuilder,ViewStyleDefinit newField.page = this.page; newField.defaultValue = this.defaultValue; newField.data = this.data; - + newField.validations = this.validations; return newField; } @@ -126,6 +135,7 @@ public class Field implements Comparable,PropertiesModelBuilder,ViewStyleDefinit field.setData(new ModelBuilder().toFieldData(data, this.viewStyle.getRenderStyle())); field.setDefaultValue(this.defaultValue); field.setVisible(this.visible); + field.setValidations(this.validations); return field; } @Override @@ -136,6 +146,7 @@ public class Field implements Comparable,PropertiesModelBuilder,ViewStyleDefinit this.data = item.getData(); this.defaultValue = item.getDefaultValue(); this.visible= item.getVisible(); + this.validations = item.getValidations(); } @Override public void fromJsonObject(Map properties) { diff --git a/dmp-backend/src/main/java/eu/eudat/validators/DatasetProfileValidator.java b/dmp-backend/src/main/java/eu/eudat/validators/DatasetProfileValidator.java new file mode 100644 index 000000000..5898411bc --- /dev/null +++ b/dmp-backend/src/main/java/eu/eudat/validators/DatasetProfileValidator.java @@ -0,0 +1,30 @@ +package eu.eudat.validators; + +import eu.eudat.models.admin.composite.DatasetProfile; +import eu.eudat.models.project.ProjectTableRequest; +import org.springframework.stereotype.Component; +import org.springframework.validation.Errors; +import org.springframework.validation.Validator; + +/** + * Created by ikalyvas on 1/3/2018. + */ +@Component("datasetProfileValidator") +public class DatasetProfileValidator implements Validator { + @Override + public boolean supports(Class aClass) { + return DatasetProfile.class.equals(aClass); + } + + @Override + public void validate(Object obj, Errors errors) { + DatasetProfile datasetProfile = (DatasetProfile) obj; + if(datasetProfile.getLabel()==null){ + errors.rejectValue("label", "datasetprofile.label.null"); + } + } + public static boolean supportsType(Class clazz) { + return DatasetProfile.class.equals(clazz); + } + +} diff --git a/dmp-backend/src/main/java/eu/eudat/validators/ProjectModelValidator.java b/dmp-backend/src/main/java/eu/eudat/validators/ProjectModelValidator.java new file mode 100644 index 000000000..2bd6849ef --- /dev/null +++ b/dmp-backend/src/main/java/eu/eudat/validators/ProjectModelValidator.java @@ -0,0 +1,29 @@ +package eu.eudat.validators; + +import eu.eudat.models.project.Project; +import org.springframework.stereotype.Component; +import org.springframework.validation.Errors; +import org.springframework.validation.Validator; + +/** + * Created by ikalyvas on 1/3/2018. + */ +@Component("projectModelValidator") +public class ProjectModelValidator implements Validator { + @Override + public boolean supports(Class aClass) { + return Project.class.equals(aClass); + } + + @Override + public void validate(Object obj, Errors errors) { + Project project = (Project)obj; + if(project.getStartDate().after(project.getEndDate())){ + errors.rejectValue("startDate","project.startDate.overlapping"); + } + } + + public static boolean supportsType(Class aClass){ + return Project.class.equals(aClass); + } +} diff --git a/dmp-backend/src/main/resources/messages.properties b/dmp-backend/src/main/resources/messages.properties index 296cbb932..3c109db7e 100644 --- a/dmp-backend/src/main/resources/messages.properties +++ b/dmp-backend/src/main/resources/messages.properties @@ -2,4 +2,6 @@ datamanagementplanrequest.length.negative=table length cannot be negative datamanagementplanrequest.offset.negative=table offset cannot be negative projectTableRequest.periodStart.overlapping = Period Start cannot overlap Period End projectTableRequest.offset.negative=table offset cannot be negative -projectTableRequest.length.negative=table length cannot be negative \ No newline at end of file +projectTableRequest.length.negative=table length cannot be negative +datasetprofile.label.null = Dataset Profile Label cannot be null +project.startDate.overlapping = Period Start cannot overlap Period End \ No newline at end of file diff --git a/dmp-frontend/src/app/dataset-wizard/dataset-wizard.component.ts b/dmp-frontend/src/app/dataset-wizard/dataset-wizard.component.ts index 86d815708..b09e2b5e5 100644 --- a/dmp-frontend/src/app/dataset-wizard/dataset-wizard.component.ts +++ b/dmp-frontend/src/app/dataset-wizard/dataset-wizard.component.ts @@ -61,7 +61,7 @@ export class DatasetWizardComponent implements AfterViewInit { this.isNew = false; this.datasetWizardService.getSingle(itemId).map(data => data as DatasetWizardModel) .subscribe(data => { - this.datasetWizardModel = new JsonSerializer().fromJSONObject(data, DatasetWizardModel); + this.datasetWizardModel = JsonSerializer.fromJSONObject(data, DatasetWizardModel); this.formGroup = this.datasetWizardModel.buildForm(); this.datasetProfileAutoCompleteConfiguration = new AutoCompleteConfiguration(this.datasetWizardService.getAvailableProfiles.bind(this.datasetWizardService), datasetProfileRequestItem); this.formGroup.get("dmp").valueChanges.subscribe(change=>{ @@ -126,7 +126,7 @@ export class DatasetWizardComponent implements AfterViewInit { complete => { this.datasetWizardService.getSingle(complete.id).subscribe( result=>{ - this.datasetWizardModel = new JsonSerializer().fromJSONObject(result,DatasetWizardModel); + this.datasetWizardModel = JsonSerializer.fromJSONObject(result,DatasetWizardModel); } ) this.onCallbackSuccess() diff --git a/dmp-frontend/src/app/dmps/editor/dmp-editor.component.ts b/dmp-frontend/src/app/dmps/editor/dmp-editor.component.ts index 1139ea32f..8fe54498a 100644 --- a/dmp-frontend/src/app/dmps/editor/dmp-editor.component.ts +++ b/dmp-frontend/src/app/dmps/editor/dmp-editor.component.ts @@ -70,7 +70,7 @@ export class DataManagementPlanEditorComponent implements AfterViewInit { this.isNew = false; this.dataManagementPlanService.getSingle(itemId).map(data => data as DataManagementPlanModel) .subscribe(data => { - this.dataManagementPlan = new JsonSerializer().fromJSONObject(data, DataManagementPlanModel); + this.dataManagementPlan = JsonSerializer.fromJSONObject(data, DataManagementPlanModel); this.formGroup = this.dataManagementPlan.buildForm(); }); } else { diff --git a/dmp-frontend/src/app/form/dynamic-form.component.ts b/dmp-frontend/src/app/form/dynamic-form.component.ts index bd39d83e6..329245b01 100644 --- a/dmp-frontend/src/app/form/dynamic-form.component.ts +++ b/dmp-frontend/src/app/form/dynamic-form.component.ts @@ -61,7 +61,7 @@ export class DynamicFormComponent implements OnInit { this.createPagination(); this.form = this.datasetProfileDefinitionModel.buildForm(); this.visibilityRulesService.formGroup = this.form; - let rules: Rule[] = new JsonSerializer().fromJSONArray(this.datasetProfileDefinitionModel.rules, Rule); + let rules: Rule[] = JsonSerializer.fromJSONArray(this.datasetProfileDefinitionModel.rules, Rule); this.visibilityRulesService.buildVisibilityRules(rules) this.progressbar = true; diff --git a/dmp-frontend/src/app/homepage/homepage.component.ts b/dmp-frontend/src/app/homepage/homepage.component.ts index c2c0da111..ccfb7b604 100644 --- a/dmp-frontend/src/app/homepage/homepage.component.ts +++ b/dmp-frontend/src/app/homepage/homepage.component.ts @@ -30,7 +30,7 @@ export class HomepageComponent implements OnInit { this.dashBoardService.getStatistics().subscribe(results => { //let data = results['payload']; - this.dashboardStatisticsData = new JsonSerializer().fromJSONObject(results, DashboardStatisticsModel); + this.dashboardStatisticsData = JsonSerializer.fromJSONObject(results, DashboardStatisticsModel); }) } diff --git a/dmp-frontend/src/app/models/CompositeField.ts b/dmp-frontend/src/app/models/CompositeField.ts index bb6bbeccc..a1e22b860 100644 --- a/dmp-frontend/src/app/models/CompositeField.ts +++ b/dmp-frontend/src/app/models/CompositeField.ts @@ -14,14 +14,14 @@ export class CompositeField extends BaseModel implements Serializable().fromJSONArray(item.fields, Field); + this.fields = JsonSerializer.fromJSONArray(item.fields, Field); this.ordinal = item.ordinal; this.id = item.id; this.title = item.title; - this.multiplicity = new JsonSerializer().fromJSONObject(item.multiplicity, Multiplicity); + this.multiplicity = JsonSerializer.fromJSONObject(item.multiplicity, Multiplicity); //this.multiplicity = new Multiplicity(); //this.multiplicity.max = 2; - if(item.multiplicityItems)this.multiplicityItems = new JsonSerializer().fromJSONArray(item.multiplicityItems, CompositeField); + if(item.multiplicityItems)this.multiplicityItems = JsonSerializer.fromJSONArray(item.multiplicityItems, CompositeField); return this; } diff --git a/dmp-frontend/src/app/models/DatasetProfileDefinitionModel.ts b/dmp-frontend/src/app/models/DatasetProfileDefinitionModel.ts index 268897593..a28c72fc1 100644 --- a/dmp-frontend/src/app/models/DatasetProfileDefinitionModel.ts +++ b/dmp-frontend/src/app/models/DatasetProfileDefinitionModel.ts @@ -11,8 +11,8 @@ export class DatasetProfileDefinitionModel extends BaseModel implements Serializ public sections:Array
fromJSONObject(item:any):DatasetProfileDefinitionModel{ this.status = item.status; - this.sections = new JsonSerializer
().fromJSONArray(item.sections,Section); - this.rules = new JsonSerializer().fromJSONArray(item.rules,Rule); + this.sections = JsonSerializer.fromJSONArray(item.sections,Section); + this.rules = JsonSerializer.fromJSONArray(item.rules,Rule); return this; } diff --git a/dmp-frontend/src/app/models/Field.ts b/dmp-frontend/src/app/models/Field.ts index 260c6e278..be5dfc674 100644 --- a/dmp-frontend/src/app/models/Field.ts +++ b/dmp-frontend/src/app/models/Field.ts @@ -29,12 +29,12 @@ export class Field extends BaseModel implements Serializable, FormGenerat this.viewStyle = item.viewStyle; this.defaultVisibility = item.defaultVisibility; this.page = item.page; - this.multiplicity = new JsonSerializer().fromJSONObject(item.multiplicity, Multiplicity); - this.defaultValue = new JsonSerializer().fromJSONObject(item.defaultValue, DefaultValue); + this.multiplicity = JsonSerializer.fromJSONObject(item.multiplicity, Multiplicity); + this.defaultValue = JsonSerializer.fromJSONObject(item.defaultValue, DefaultValue); this.value = this.defaultValue.value && !item.value ? this.defaultValue.value : item.value; //this.multiplicity = new Multiplicity(); //this.multiplicity.max = 2; - if(item.multiplicityItems)this.multiplicityItems = new JsonSerializer().fromJSONArray(item.multiplicityItems, Field); + if(item.multiplicityItems)this.multiplicityItems = JsonSerializer.fromJSONArray(item.multiplicityItems, Field); this.data = item.data; return this; } diff --git a/dmp-frontend/src/app/models/FieldGroup.ts b/dmp-frontend/src/app/models/FieldGroup.ts index ae608f78f..20eed5f8e 100644 --- a/dmp-frontend/src/app/models/FieldGroup.ts +++ b/dmp-frontend/src/app/models/FieldGroup.ts @@ -27,7 +27,7 @@ export class FieldGroup extends BaseModel implements Serializable, F this.extendedDescription = item.extendedDescription; this.defaultVisibility = item.defaultVisibility; this.page = item.page; - this.compositeFields = new JsonSerializer().fromJSONArray(item.compositeFields, CompositeField); + this.compositeFields = JsonSerializer.fromJSONArray(item.compositeFields, CompositeField); return this; } diff --git a/dmp-frontend/src/app/models/Section.ts b/dmp-frontend/src/app/models/Section.ts index 109e49fc6..2ca192c8c 100644 --- a/dmp-frontend/src/app/models/Section.ts +++ b/dmp-frontend/src/app/models/Section.ts @@ -17,14 +17,14 @@ export class Section extends BaseModel implements Serializable
, FormGen public compositeFields: Array = new Array(); fromJSONObject(item: any): Section { - this.sections = new JsonSerializer
().fromJSONArray(item.sections, Section); + this.sections = JsonSerializer.fromJSONArray(item.sections, Section); //this.fieldGroups = new JsonSerializer().fromJSONArray(item.fieldGroups, FieldGroup); this.page = item.page; this.defaultVisibility = item.defaultVisibility; this.id = item.id; this.title = item.title; this.description = item.description; - this.compositeFields = new JsonSerializer().fromJSONArray(item.fieldSets, CompositeField); + this.compositeFields = JsonSerializer.fromJSONArray(item.fieldSets, CompositeField); return this; } diff --git a/dmp-frontend/src/app/models/data-managemnt-plans/DataManagementPlanModel.ts b/dmp-frontend/src/app/models/data-managemnt-plans/DataManagementPlanModel.ts index 795ed42a0..7ce3d5ea3 100644 --- a/dmp-frontend/src/app/models/data-managemnt-plans/DataManagementPlanModel.ts +++ b/dmp-frontend/src/app/models/data-managemnt-plans/DataManagementPlanModel.ts @@ -32,10 +32,10 @@ export class DataManagementPlanModel implements Serializable().fromJSONObject(item.project, ProjectModel); - this.organisations = new JsonSerializer().fromJSONArray(item.organisations, OrganisationModel); - this.researchers = new JsonSerializer().fromJSONArray(item.researchers, ResearcherModel); - this.profiles = new JsonSerializer().fromJSONArray(item.profiles, ProfileModel); + this.project = JsonSerializer.fromJSONObject(item.project, ProjectModel); + this.organisations = JsonSerializer.fromJSONArray(item.organisations, OrganisationModel); + this.researchers = JsonSerializer.fromJSONArray(item.researchers, ResearcherModel); + this.profiles = JsonSerializer.fromJSONArray(item.profiles, ProfileModel); return this; } diff --git a/dmp-frontend/src/app/models/datasets/DatasetModel.ts b/dmp-frontend/src/app/models/datasets/DatasetModel.ts index 07dbbc9ca..002673c32 100644 --- a/dmp-frontend/src/app/models/datasets/DatasetModel.ts +++ b/dmp-frontend/src/app/models/datasets/DatasetModel.ts @@ -29,9 +29,9 @@ export class DatasetModel implements Serializable { this.uri = item.uri; this.status = item.status; this.description = item.description; - this.services = new JsonSerializer().fromJSONArray(item.services, ServiceModel); - this.registries = new JsonSerializer().fromJSONArray(item.registries, RegisterModel); - this.dataRepositories = new JsonSerializer().fromJSONArray(item.dataRepositories, DataRepositoryModel); + this.services = JsonSerializer.fromJSONArray(item.services, ServiceModel); + this.registries = JsonSerializer.fromJSONArray(item.registries, RegisterModel); + this.dataRepositories = JsonSerializer.fromJSONArray(item.dataRepositories, DataRepositoryModel); return this; } diff --git a/dmp-frontend/src/app/models/datasets/DatasetWizardModel.ts b/dmp-frontend/src/app/models/datasets/DatasetWizardModel.ts index d6f373dce..2be355f9e 100644 --- a/dmp-frontend/src/app/models/datasets/DatasetWizardModel.ts +++ b/dmp-frontend/src/app/models/datasets/DatasetWizardModel.ts @@ -33,12 +33,12 @@ export class DatasetWizardModel implements Serializable { this.uri = item.uri; this.status = item.status; this.description = item.description; - this.services = new JsonSerializer().fromJSONArray(item.services, ServiceModel); - this.registries = new JsonSerializer().fromJSONArray(item.registries, RegisterModel); - this.dataRepositories = new JsonSerializer().fromJSONArray(item.dataRepositories, DataRepositoryModel); - this.dmp = new JsonSerializer().fromJSONObject(item.dmp, DataManagementPlanModel); - this.profile = new JsonSerializer().fromJSONObject(item.profile, DatasetWizardModel); - this.datasetProfileDefinition = new JsonSerializer().fromJSONObject(item.datasetProfileDefinition, DatasetProfileDefinitionModel); + this.services = JsonSerializer.fromJSONArray(item.services, ServiceModel); + this.registries = JsonSerializer.fromJSONArray(item.registries, RegisterModel); + this.dataRepositories = JsonSerializer.fromJSONArray(item.dataRepositories, DataRepositoryModel); + this.dmp = JsonSerializer.fromJSONObject(item.dmp, DataManagementPlanModel); + this.profile = JsonSerializer.fromJSONObject(item.profile, DatasetWizardModel); + this.datasetProfileDefinition = JsonSerializer.fromJSONObject(item.datasetProfileDefinition, DatasetProfileDefinitionModel); return this; } diff --git a/dmp-frontend/src/app/projects/editor/project-editor.component.html b/dmp-frontend/src/app/projects/editor/project-editor.component.html index b0cd9d48a..bd2ef3aa8 100644 --- a/dmp-frontend/src/app/projects/editor/project-editor.component.html +++ b/dmp-frontend/src/app/projects/editor/project-editor.component.html @@ -33,7 +33,7 @@ class="table-input" [matDatepicker]="startDate" formControlName="startDate" required> - {{baseErrorModel.startDate}} + {{this.project.errorModel.startDate}} {{'GENERAL.VALIDATION.REQUIRED' | translate}} diff --git a/dmp-frontend/src/app/projects/editor/project-editor.component.ts b/dmp-frontend/src/app/projects/editor/project-editor.component.ts index 5d8f5e405..d7817f28b 100644 --- a/dmp-frontend/src/app/projects/editor/project-editor.component.ts +++ b/dmp-frontend/src/app/projects/editor/project-editor.component.ts @@ -8,7 +8,7 @@ import { DataManagementPlanService } from "../../services/data-management-plan/d import { ProjectModel } from "../../models/projects/ProjectModel"; import { ProjectService } from "../../services/project/project.service"; import { JsonSerializer } from "../../utilities/JsonSerializer"; -import { FormGroup } from "@angular/forms"; +import { FormGroup, AbstractControl, FormControl, FormArray } from "@angular/forms"; import { SnackBarNotificationComponent } from "../../shared/components/notificaiton/snack-bar-notification.component"; import { BaseErrorModel } from "../../models/error/BaseErrorModel"; import { TdDialogService } from "@covalent/core"; @@ -47,7 +47,7 @@ export class ProjectEditorComponent implements AfterViewInit { this.isNew = false; this.projectService.getSingle(itemId).map(data => data as ProjectModel) .subscribe(data => { - this.project = new JsonSerializer().fromJSONObject(data, ProjectModel); + this.project = JsonSerializer.fromJSONObject(data, ProjectModel); this.formGroup = this.project.buildForm(); }); } else { @@ -60,7 +60,7 @@ export class ProjectEditorComponent implements AfterViewInit { } formSubmit(): void { - //this.touchAllFormFields(this.formGroup); + this.touchAllFormFields(this.formGroup); if (!this.isFormValid()) { return; } this.onSubmit(); } @@ -85,9 +85,9 @@ export class ProjectEditorComponent implements AfterViewInit { this.router.navigate(['/projects']); } - onCallbackError(error: any) { - this.setErrorModel(error.error); - //this.validateAllFormFields(this.formGroup); + onCallbackError(errorResponse: any) { + this.setErrorModel(errorResponse.error); + this.validateAllFormFields(this.formGroup); } public setErrorModel(errorModel: BaseErrorModel) { @@ -117,4 +117,36 @@ export class ProjectEditorComponent implements AfterViewInit { }); }); } + + public touchAllFormFields(formControl: AbstractControl) { + if (formControl instanceof FormControl) { + formControl.markAsTouched(); + } else if (formControl instanceof FormGroup) { + Object.keys(formControl.controls).forEach(item => { + const control = formControl.get(item); + this.touchAllFormFields(control); + }) + } + else if (formControl instanceof FormArray) { + formControl.controls.forEach(item => { + this.touchAllFormFields(item); + }) + } + } + + public validateAllFormFields(formControl: AbstractControl) { + if (formControl instanceof FormControl) { + formControl.updateValueAndValidity({ emitEvent: false }) + } else if (formControl instanceof FormGroup) { + Object.keys(formControl.controls).forEach(item => { + const control = formControl.get(item); + this.validateAllFormFields(control); + }) + } + else if (formControl instanceof FormArray) { + formControl.controls.forEach(item => { + this.validateAllFormFields(item); + }) + } + } } \ No newline at end of file diff --git a/dmp-frontend/src/app/services/auth/auth.service.ts b/dmp-frontend/src/app/services/auth/auth.service.ts index c960812df..6a074b8be 100644 --- a/dmp-frontend/src/app/services/auth/auth.service.ts +++ b/dmp-frontend/src/app/services/auth/auth.service.ts @@ -66,7 +66,7 @@ export class AuthService { return this.http.post(url, loginInfo, { headers: this.headers }) .map((res: any) => { - const principal = this.current(new JsonSerializer().fromJSONObject(res.payload, Principal)); + const principal = this.current(JsonSerializer.fromJSONObject(res.payload, Principal)); //this.loginContextSubject.next(true); return principal; }) @@ -101,7 +101,7 @@ export class AuthService { headers = headers.set('AuthToken', principal.token) return this.http.post(url, null, { headers: headers }) .map((r: Response) => { - const princ = this.current(new JsonSerializer().fromJSONObject(r.json(), Principal)); + const princ = this.current(JsonSerializer.fromJSONObject(r.json(), Principal)); //this.loginContextSubject.next(true); return princ; }) diff --git a/dmp-frontend/src/app/utilities/JsonSerializer.ts b/dmp-frontend/src/app/utilities/JsonSerializer.ts index b3b23d812..da284c1ad 100644 --- a/dmp-frontend/src/app/utilities/JsonSerializer.ts +++ b/dmp-frontend/src/app/utilities/JsonSerializer.ts @@ -1,7 +1,7 @@ import { Serializable } from '../models/interfaces/Serializable'; -export class JsonSerializer>{ +export class JsonSerializer{ - public fromJSONArray(items: any[], type: { new(): T; }): T[] { + public static fromJSONArray>(items: any[], type: { new(): T; }): T[] { if(!items)return new Array(); const objectList: T[] = new Array(); for (let i = 0; i < items.length; i++) { @@ -10,7 +10,7 @@ export class JsonSerializer>{ return objectList; } - public fromJSONObject(item: any, type: { new(): T; }): T { + public static fromJSONObject>(item: any, type: { new(): T; }): T { if(!item)return null; return new type().fromJSONObject(item); } From 9407442bcbc518c011b38f3bd4a4b2288e75e391 Mon Sep 17 00:00:00 2001 From: annabakouli Date: Thu, 4 Jan 2018 11:32:39 +0200 Subject: [PATCH 2/2] no message --- .../main/java/eu/eudat/controllers/Admin.java | 17 +- .../eu/eudat/controllers/BaseController.java | 19 +- .../main/java/eu/eudat/controllers/DMPs.java | 30 +-- .../controllers/DashBoardController.java | 17 +- .../eudat/controllers/DataRepositories.java | 29 +-- .../controllers/DatasetProfileController.java | 24 ++- .../eu/eudat/controllers/DatasetProfiles.java | 26 +-- .../controllers/DatasetWizardController.java | 29 +-- .../java/eu/eudat/controllers/Datasets.java | 25 +-- .../eu/eudat/controllers/DmpProfiles.java | 36 ++-- .../eu/eudat/controllers/Organisations.java | 39 ++-- .../java/eu/eudat/controllers/Projects.java | 38 +--- .../java/eu/eudat/controllers/Registries.java | 40 ++-- .../eu/eudat/controllers/Researchers.java | 40 ++-- .../java/eu/eudat/controllers/Services.java | 38 ++-- .../main/java/eu/eudat/controllers/Users.java | 28 +-- .../managers/DataManagementPlanManager.java | 13 +- .../eu/eudat/managers/DatasetManager.java | 11 +- .../QueryableHibernateList.java | 19 +- .../java/eu/eudat/services/ApiContext.java | 13 ++ .../eu/eudat/services/ApiContextImpl.java | 47 +++++ .../eu/eudat/services/DatabaseRepository.java | 23 +++ .../services/DatabaseRepositoryImpl.java | 177 ++++++++++++++++++ .../eu/eudat/validators/ApiValidator.java | 9 - 24 files changed, 456 insertions(+), 331 deletions(-) create mode 100644 dmp-backend/src/main/java/eu/eudat/services/ApiContext.java create mode 100644 dmp-backend/src/main/java/eu/eudat/services/ApiContextImpl.java create mode 100644 dmp-backend/src/main/java/eu/eudat/services/DatabaseRepository.java create mode 100644 dmp-backend/src/main/java/eu/eudat/services/DatabaseRepositoryImpl.java delete mode 100644 dmp-backend/src/main/java/eu/eudat/validators/ApiValidator.java diff --git a/dmp-backend/src/main/java/eu/eudat/controllers/Admin.java b/dmp-backend/src/main/java/eu/eudat/controllers/Admin.java index e183071d2..9e5199437 100644 --- a/dmp-backend/src/main/java/eu/eudat/controllers/Admin.java +++ b/dmp-backend/src/main/java/eu/eudat/controllers/Admin.java @@ -5,6 +5,7 @@ import java.util.UUID; import eu.eudat.dao.entities.*; import eu.eudat.managers.DashBoardManager; import eu.eudat.models.dashboard.DashBoardStatistics; +import eu.eudat.services.ApiContext; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.http.HttpStatus; @@ -27,20 +28,16 @@ import javax.validation.Valid; public class Admin extends BaseController{ @Autowired - public Admin(ApplicationContext springContext) { - super(springContext); + public Admin(ApiContext apiContext) { + super(apiContext); } - @Autowired private DatasetProfileDao datasetProfileDao; - @Autowired private DatasetProfileRulesetDao datasetProfileRulesetDao; - @Autowired private DatasetProfileViewstyleDao datasetProfileViewstyleDao; - @Transactional @RequestMapping(method = RequestMethod.POST, value = { "/admin/addDmp" },consumes = "application/json", produces="application/json") public ResponseEntity addDmp(@Valid @RequestBody DatasetProfile profile){ try{ eu.eudat.entities.DatasetProfile modelDefinition = AdminManager.generateViewStyleDefinition(profile); - datasetProfileDao.createOrUpdate(modelDefinition); + this.getApiContext().getDatabaseRepository().getDatasetProfileDao().createOrUpdate(modelDefinition); return ResponseEntity.status(HttpStatus.OK).body(modelDefinition.getId()); }catch(Exception ex){ @@ -55,9 +52,9 @@ public class Admin extends BaseController{ try{ eu.eudat.entities.DatasetProfile modelDefinition = AdminManager.generateViewStyleDefinition(profile); - eu.eudat.entities.DatasetProfile datasetprofile = datasetProfileDao.find(UUID.fromString(id)); + eu.eudat.entities.DatasetProfile datasetprofile = this.getApiContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id)); datasetprofile.setDefinition(modelDefinition.getDefinition()); - datasetProfileDao.createOrUpdate(datasetprofile); + this.getApiContext().getDatabaseRepository().getDatasetProfileDao().createOrUpdate(datasetprofile); return ResponseEntity.status(HttpStatus.OK).body(null); }catch(Exception ex){ @@ -69,7 +66,7 @@ public class Admin extends BaseController{ @RequestMapping(method = RequestMethod.GET, value = { "/admin/get/{id}" }, produces="application/json") public ResponseEntity get(@PathVariable String id){ try{ - eu.eudat.entities.DatasetProfile profile = datasetProfileDao.find(UUID.fromString(id)); + eu.eudat.entities.DatasetProfile profile = this.getApiContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id)); eu.eudat.models.admin.composite.DatasetProfile datasetprofile = AdminManager.generateDatasetProfileModel(profile); return ResponseEntity.status(HttpStatus.OK).body(datasetprofile); }catch(Exception ex){ diff --git a/dmp-backend/src/main/java/eu/eudat/controllers/BaseController.java b/dmp-backend/src/main/java/eu/eudat/controllers/BaseController.java index a766aec8d..3911618d0 100644 --- a/dmp-backend/src/main/java/eu/eudat/controllers/BaseController.java +++ b/dmp-backend/src/main/java/eu/eudat/controllers/BaseController.java @@ -1,5 +1,6 @@ package eu.eudat.controllers; +import eu.eudat.services.ApiContext; import eu.eudat.validators.DataManagementPlanTableRequestValidator; import eu.eudat.validators.DatasetProfileValidator; import eu.eudat.validators.ProjectModelValidator; @@ -14,18 +15,22 @@ import org.springframework.web.bind.annotation.InitBinder; */ public abstract class BaseController { - private ApplicationContext springContext; + private ApiContext apiContext; - public BaseController(ApplicationContext springContext){ - this.springContext = springContext; + public ApiContext getApiContext() { + return apiContext; + } + + public BaseController(ApiContext apiContext){ + this.apiContext = apiContext; } @InitBinder() protected void initBinder(WebDataBinder binder) { - if (binder.getTarget() != null && DataManagementPlanTableRequestValidator.supportsType((binder.getTarget().getClass()))) binder.addValidators(this.springContext.getBean("dataManagementPlanTableRequestValidator",DataManagementPlanTableRequestValidator.class)); - if (binder.getTarget() != null && ProjectTableRequestValidator.supportsType((binder.getTarget().getClass()))) binder.addValidators(this.springContext.getBean("projectTableRequestValidator",ProjectTableRequestValidator.class)); - if (binder.getTarget() != null && DatasetProfileValidator.supportsType((binder.getTarget().getClass()))) binder.addValidators(this.springContext.getBean("datasetProfileValidator",DatasetProfileValidator.class)); - if (binder.getTarget() != null && ProjectModelValidator.supportsType((binder.getTarget().getClass()))) binder.addValidators(this.springContext.getBean("projectModelValidator",ProjectModelValidator.class)); + if (binder.getTarget() != null && DataManagementPlanTableRequestValidator.supportsType((binder.getTarget().getClass()))) binder.addValidators(this.apiContext.getApplicationContext().getBean("dataManagementPlanTableRequestValidator",DataManagementPlanTableRequestValidator.class)); + if (binder.getTarget() != null && ProjectTableRequestValidator.supportsType((binder.getTarget().getClass()))) binder.addValidators(this.apiContext.getApplicationContext().getBean("projectTableRequestValidator",ProjectTableRequestValidator.class)); + if (binder.getTarget() != null && DatasetProfileValidator.supportsType((binder.getTarget().getClass()))) binder.addValidators(this.apiContext.getApplicationContext().getBean("datasetProfileValidator",DatasetProfileValidator.class)); + if (binder.getTarget() != null && ProjectModelValidator.supportsType((binder.getTarget().getClass()))) binder.addValidators(this.apiContext.getApplicationContext().getBean("projectModelValidator",ProjectModelValidator.class)); } } diff --git a/dmp-backend/src/main/java/eu/eudat/controllers/DMPs.java b/dmp-backend/src/main/java/eu/eudat/controllers/DMPs.java index 34f4a4e90..7fad2657d 100644 --- a/dmp-backend/src/main/java/eu/eudat/controllers/DMPs.java +++ b/dmp-backend/src/main/java/eu/eudat/controllers/DMPs.java @@ -14,6 +14,7 @@ import eu.eudat.models.helpers.DataTableData; import eu.eudat.models.helpers.responses.*; import eu.eudat.models.listingmodels.DataManagementPlanListingModel; import eu.eudat.models.security.Principal; +import eu.eudat.services.ApiContext; import eu.eudat.validators.DataManagementPlanTableRequestValidator; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; @@ -41,29 +42,16 @@ import eu.eudat.managers.DataManagementPlanManager; @RestController @CrossOrigin public class DMPs extends BaseController { - @Autowired - public DMPs(ApplicationContext applicationContext){ - super(applicationContext); - } - @Autowired private DataRepositoryDao dataRepositoryDao; - @Autowired private DatasetDao datasetDao; - @Autowired private DatasetProfileDao datasetProfileDao; - @Autowired private DatasetProfileRulesetDao datasetProfileRulesetDao; - @Autowired private DatasetProfileViewstyleDao datasetProfileViewstyleDao; - @Autowired private DMPDao dMPDao; - @Autowired private DMPProfileDao dMPProfileDao; - @Autowired private OrganisationDao organisationDao; - @Autowired private ProjectDao projectDao; - @Autowired private RegistryDao registryDao; - @Autowired private ResearcherDao researcherDao; - @Autowired private ServiceDao serviceDao; - @Autowired private UserInfoDao userInfoDao; + @Autowired + public DMPs(ApiContext apiContext){ + super(apiContext); + } @RequestMapping(method = RequestMethod.POST, value = { "/dmps/getPaged" }, consumes = "application/json", produces="application/json") public @ResponseBody ResponseItem> getPaged(@Valid @RequestBody DataManagementPlanTableRequest dataManagementPlanTableRequest) { try { - DataTableData dataTable = new DataManagementPlanManager().getPaged(dMPDao, dataManagementPlanTableRequest); + DataTableData dataTable = new DataManagementPlanManager().getPaged(this.getApiContext().getDatabaseRepository().getDmpDao(), dataManagementPlanTableRequest); return new ResponseItem>().status(HttpStatus.OK).payload(dataTable); } catch (Exception ex) { @@ -75,7 +63,7 @@ public class DMPs extends BaseController { @RequestMapping(method = RequestMethod.GET, value = { "/dmps/getSingle/{id}" }, produces="application/json") public @ResponseBody ResponseItem getSingle(@PathVariable String id) { try { - eu.eudat.models.dmp.DataManagementPlan project = new DataManagementPlanManager().getSingle(dMPDao, id); + eu.eudat.models.dmp.DataManagementPlan project = new DataManagementPlanManager().getSingle(this.getApiContext().getDatabaseRepository().getDmpDao(), id); return new ResponseItem().status(HttpStatus.OK).payload(project); } catch (Exception ex) { @@ -88,7 +76,7 @@ public class DMPs extends BaseController { @RequestMapping(method = RequestMethod.POST, value = { "/dmps/createOrUpdate" }, consumes = "application/json", produces="application/json") public @ResponseBody ResponseItem createOrUpdate(@RequestBody eu.eudat.models.dmp.DataManagementPlan dataManagementPlan, Principal principal) { try{ - DataManagementPlanManager.createOrUpdate(dMPDao,projectDao,researcherDao,userInfoDao,organisationDao,dataManagementPlan,principal); + DataManagementPlanManager.createOrUpdate(this.getApiContext(),dataManagementPlan,principal); return new ResponseItem().status(HttpStatus.CREATED); }catch (Exception ex){ ex.printStackTrace(); @@ -102,7 +90,7 @@ public class DMPs extends BaseController { @RequestMapping(method = RequestMethod.POST, value = { "/dmps/get" }, consumes = "application/json", produces="application/json") public @ResponseBody ResponseItem> getWithCriteria(@RequestBody DataManagementPlanCriteriaRequest dataManagementPlanCriteria) { try { - List dataTable = new DataManagementPlanManager().getWithCriteria(dMPDao, dataManagementPlanCriteria); + List dataTable = new DataManagementPlanManager().getWithCriteria(this.getApiContext().getDatabaseRepository().getDmpDao(), dataManagementPlanCriteria); return new ResponseItem>().status(HttpStatus.OK).payload(dataTable); diff --git a/dmp-backend/src/main/java/eu/eudat/controllers/DashBoardController.java b/dmp-backend/src/main/java/eu/eudat/controllers/DashBoardController.java index ec96dbd48..1d5256c70 100644 --- a/dmp-backend/src/main/java/eu/eudat/controllers/DashBoardController.java +++ b/dmp-backend/src/main/java/eu/eudat/controllers/DashBoardController.java @@ -2,6 +2,7 @@ package eu.eudat.controllers; import eu.eudat.models.helpers.responses.ResponseItem; import eu.eudat.models.security.Principal; +import eu.eudat.services.ApiContext; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.CrossOrigin; @@ -17,16 +18,18 @@ import eu.eudat.models.dashboard.DashBoardStatistics; @RestController @CrossOrigin -public class DashBoardController { - - @Autowired private DatasetDao datasetDao; - @Autowired private DMPDao dMPDao; - @Autowired private ProjectDao projectDao; - +public class DashBoardController extends BaseController{ + + @Autowired + public DashBoardController(ApiContext apiContext) { + super(apiContext); + } + @RequestMapping(method = RequestMethod.GET, value = { "/dashboard/getStatistics" }, produces="application/json") public ResponseItem getStatistics(Principal principal){ try { - DashBoardStatistics statistics = new DashBoardManager().getStatistics(datasetDao, dMPDao, projectDao); + DashBoardStatistics statistics = new DashBoardManager().getStatistics(this.getApiContext().getDatabaseRepository().getDatasetDao(), this.getApiContext().getDatabaseRepository().getDmpDao() + , this.getApiContext().getDatabaseRepository().getProjectDao()); return new ResponseItem().status(HttpStatus.OK).payload(statistics); } catch(Exception ex) { diff --git a/dmp-backend/src/main/java/eu/eudat/controllers/DataRepositories.java b/dmp-backend/src/main/java/eu/eudat/controllers/DataRepositories.java index 589e486d8..dacfad99d 100644 --- a/dmp-backend/src/main/java/eu/eudat/controllers/DataRepositories.java +++ b/dmp-backend/src/main/java/eu/eudat/controllers/DataRepositories.java @@ -7,6 +7,7 @@ import java.util.UUID; import javax.transaction.Transactional; import eu.eudat.entities.DataRepository; +import eu.eudat.services.ApiContext; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -38,29 +39,17 @@ import eu.eudat.proxy.fetching.RemoteFetcher; @RestController @CrossOrigin -public class DataRepositories { - - @Autowired private DataRepositoryDao dataRepositoryDao; - @Autowired private DatasetDao datasetDao; - @Autowired private DatasetProfileDao datasetProfileDao; - @Autowired private DatasetProfileRulesetDao datasetProfileRulesetDao; - @Autowired private DatasetProfileViewstyleDao datasetProfileViewstyleDao; - @Autowired private DMPDao dMPDao; - @Autowired private DMPProfileDao dMPProfileDao; - @Autowired private OrganisationDao organisationDao; - @Autowired private ProjectDao projectDao; - @Autowired private RegistryDao registryDao; - @Autowired private ResearcherDao researcherDao; - @Autowired private ServiceDao serviceDao; - - @Autowired private RemoteFetcher remoteFetcher; - - - +public class DataRepositories extends BaseController{ + + @Autowired + public DataRepositories(ApiContext apiContext) { + super(apiContext); + } + @RequestMapping(method = RequestMethod.GET, value = { "/external/datarepos" }, produces="application/json") public @ResponseBody ResponseEntity>> listExternalDataRepositories(@RequestParam(value="query", required=false) String query ){ try { - List> remoteRepos = remoteFetcher.getRepositories(query); + List> remoteRepos = this.getApiContext().getRemoteFetcher().getRepositories(query); return ResponseEntity.status(HttpStatus.OK).body(remoteRepos); } catch(NoURLFound ex) { diff --git a/dmp-backend/src/main/java/eu/eudat/controllers/DatasetProfileController.java b/dmp-backend/src/main/java/eu/eudat/controllers/DatasetProfileController.java index 156104c5f..a25472ea7 100644 --- a/dmp-backend/src/main/java/eu/eudat/controllers/DatasetProfileController.java +++ b/dmp-backend/src/main/java/eu/eudat/controllers/DatasetProfileController.java @@ -7,6 +7,7 @@ import java.util.Map; import java.util.UUID; import eu.eudat.models.components.commons.datafield.AutoCompleteData; +import eu.eudat.services.ApiContext; import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; @@ -31,17 +32,17 @@ import eu.eudat.utilities.builders.XmlBuilder; @RestController @CrossOrigin -public class DatasetProfileController { - - @Autowired private DatasetProfileDao datasetProfileDao; - @Autowired private DatasetProfileRulesetDao datasetProfileRulesetDao; - @Autowired private DatasetProfileViewstyleDao datasetProfileViewstyleDao; - @Autowired private DatasetDao datasetDao; +public class DatasetProfileController extends BaseController{ + + @Autowired + public DatasetProfileController(ApiContext apiContext) { + super(apiContext); + } @RequestMapping(method = RequestMethod.GET, value = { "/datasetwizard/get/{id}" }, produces="application/json") public ResponseEntity getSingle(@PathVariable String id){ try { - eu.eudat.entities.Dataset dataset = datasetDao.find(UUID.fromString(id)); + eu.eudat.entities.Dataset dataset = this.getApiContext().getDatabaseRepository().getDatasetDao().find(UUID.fromString(id)); eu.eudat.models.user.composite.DatasetProfile datasetprofile = UserManager.generateDatasetProfileModel(dataset.getProfile()); datasetprofile.setStatus(dataset.getStatus()); if(dataset.getProperties()!=null){ @@ -61,13 +62,13 @@ public class DatasetProfileController { @RequestMapping(method = RequestMethod.POST, value = { "/datasetprofile/save/{id}" }, consumes="application/json",produces="application/json") public ResponseEntity updateDataset(@PathVariable String id,@RequestBody PropertiesModel properties){ try { - eu.eudat.entities.Dataset dataset = datasetDao.find(UUID.fromString(id)); + eu.eudat.entities.Dataset dataset = this.getApiContext().getDatabaseRepository().getDatasetDao().find(UUID.fromString(id)); Map values = new HashMap(); properties.toMap(values); JSONObject jobject = new JSONObject(values); dataset.setProperties(jobject.toString()); dataset.setStatus((short)properties.getStatus()); - datasetDao.createOrUpdate(dataset); //TODO + this.getApiContext().getDatabaseRepository().getDatasetDao().createOrUpdate(dataset); //TODO return ResponseEntity.status(HttpStatus.OK).body(properties); } @@ -79,11 +80,8 @@ public class DatasetProfileController { @RequestMapping(method = RequestMethod.POST, value = { "/search/autocomplete" }, consumes="application/json",produces="application/json") public ResponseEntity getDataForAutocomplete(@RequestBody AutoCompleteLookupItem lookupItem){ try { - eu.eudat.entities.Dataset dataset = datasetDao.find(UUID.fromString(lookupItem.getProfileID())); - //Document viewStyleDoc = XmlBuilder.fromXml(dataset.getProfile().getViewstyle().getDefinition()); - //Element field = viewStyleDoc.getElementById(lookupItem.getFieldID()); + eu.eudat.entities.Dataset dataset = this.getApiContext().getDatabaseRepository().getDatasetDao().find(UUID.fromString(lookupItem.getProfileID())); eu.eudat.entities.xmlmodels.datasetprofiledefinition.Field modelfield = new eu.eudat.entities.xmlmodels.datasetprofiledefinition.Field(); - //modelfield.fromXml(field); AutoCompleteData data = new AutoCompleteData().fromData(modelfield.getData()); URL url = new URL(data.getUrl()+lookupItem.getSearchTerm()); diff --git a/dmp-backend/src/main/java/eu/eudat/controllers/DatasetProfiles.java b/dmp-backend/src/main/java/eu/eudat/controllers/DatasetProfiles.java index b216f96bd..ac34dabe3 100644 --- a/dmp-backend/src/main/java/eu/eudat/controllers/DatasetProfiles.java +++ b/dmp-backend/src/main/java/eu/eudat/controllers/DatasetProfiles.java @@ -16,6 +16,7 @@ import eu.eudat.models.datasetprofile.DatasetProfileListingModel; import eu.eudat.models.datasetprofile.DatasetProfileTableRequestItem; import eu.eudat.models.helpers.DataTableData; import eu.eudat.models.helpers.responses.ResponseItem; +import eu.eudat.services.ApiContext; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -43,26 +44,17 @@ import eu.eudat.dao.entities.ServiceDao; @RestController @CrossOrigin -public class DatasetProfiles { - - @Autowired private DataRepositoryDao dataRepositoryDao; - @Autowired private DatasetDao datasetDao; - @Autowired private DatasetProfileDao datasetProfileDao; - @Autowired private DatasetProfileRulesetDao datasetProfileRulesetDao; - @Autowired private DatasetProfileViewstyleDao datasetProfileViewstyleDao; - @Autowired private DMPDao dMPDao; - @Autowired private DMPProfileDao dMPProfileDao; - @Autowired private OrganisationDao organisationDao; - @Autowired private ProjectDao projectDao; - @Autowired private RegistryDao registryDao; - @Autowired private ResearcherDao researcherDao; - @Autowired private ServiceDao serviceDao; +public class DatasetProfiles extends BaseController{ + @Autowired + public DatasetProfiles(ApiContext apiContext) { + super(apiContext); + } @RequestMapping(method = RequestMethod.POST, value = { "/dmps/datasetprofiles/get" }, produces="application/json") public @ResponseBody ResponseItem> get(@RequestBody DatasetProfileAutocompleteRequest datasetProfileAutocompleteRequest) { try { - List datasetProfileAutocompleteItems = DatasetProfileManager.getWithCriteria(datasetProfileDao,datasetProfileAutocompleteRequest); + List datasetProfileAutocompleteItems = DatasetProfileManager.getWithCriteria(this.getApiContext().getDatabaseRepository().getDatasetProfileDao(),datasetProfileAutocompleteRequest); return new ResponseItem>().status(HttpStatus.OK).payload(datasetProfileAutocompleteItems); } catch(Exception ex) { @@ -73,7 +65,7 @@ public class DatasetProfiles { @RequestMapping(method = RequestMethod.POST, value = { "/dmps/datasetprofiles/getPaged" }, produces="application/json") public @ResponseBody ResponseItem> getPaged(@RequestBody DatasetProfileTableRequestItem datasetProfileTableRequestItem) { try { - DataTableData datasetProfileTableData = DatasetProfileManager.getPaged(datasetProfileDao,datasetProfileTableRequestItem); + DataTableData datasetProfileTableData = DatasetProfileManager.getPaged(this.getApiContext().getDatabaseRepository().getDatasetProfileDao(),datasetProfileTableRequestItem); return new ResponseItem>().status(HttpStatus.OK).payload(datasetProfileTableData ); } catch(Exception ex) { @@ -84,7 +76,7 @@ public class DatasetProfiles { @RequestMapping(method = RequestMethod.GET, value = { "/datasetprofiles/getAll" }, produces="application/json") public @ResponseBody ResponseItem> getAll() { try { - List datasetProfileTableData = DatasetProfileManager.getAll(datasetProfileDao); + List datasetProfileTableData = DatasetProfileManager.getAll(this.getApiContext().getDatabaseRepository().getDatasetProfileDao()); return new ResponseItem>().status(HttpStatus.OK).payload(datasetProfileTableData ); } catch(Exception ex) { diff --git a/dmp-backend/src/main/java/eu/eudat/controllers/DatasetWizardController.java b/dmp-backend/src/main/java/eu/eudat/controllers/DatasetWizardController.java index fae259a65..bd9bde84f 100644 --- a/dmp-backend/src/main/java/eu/eudat/controllers/DatasetWizardController.java +++ b/dmp-backend/src/main/java/eu/eudat/controllers/DatasetWizardController.java @@ -15,6 +15,7 @@ import eu.eudat.models.helpers.DataTableData; import eu.eudat.models.helpers.responses.ResponseItem; import eu.eudat.models.listingmodels.DatasetListingModel; import eu.eudat.models.security.Principal; +import eu.eudat.services.ApiContext; import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; @@ -31,28 +32,18 @@ import java.util.Map; @RestController @CrossOrigin @RequestMapping( value = { "/datasetwizard" }) -public class DatasetWizardController { - - @Autowired private DataRepositoryDao dataRepositoryDao; - @Autowired private DatasetDao datasetDao; - @Autowired private DatasetProfileDao datasetProfileDao; - @Autowired private DatasetProfileRulesetDao datasetProfileRulesetDao; - @Autowired private DatasetProfileViewstyleDao datasetProfileViewstyleDao; - @Autowired private DMPDao dMPDao; - @Autowired private DMPProfileDao dMPProfileDao; - @Autowired private OrganisationDao organisationDao; - @Autowired private ProjectDao projectDao; - @Autowired private RegistryDao registryDao; - @Autowired private ResearcherDao researcherDao; - @Autowired private ServiceDao serviceDao; - @Autowired private UserInfoDao userInfoDao; +public class DatasetWizardController extends BaseController{ + @Autowired + public DatasetWizardController(ApiContext apiContext) { + super(apiContext); + } @RequestMapping(method = RequestMethod.POST, value = { "/userDmps" }, produces="application/json") public @ResponseBody ResponseItem> getUserDmps(@RequestBody DatasetWizardAutocompleteRequest datasetWizardAutocompleteRequest, Principal principal) { try { - List dataManagementPlans = DatasetWizardManager.getUserDmps(dMPDao,datasetWizardAutocompleteRequest,principal); + List dataManagementPlans = DatasetWizardManager.getUserDmps(this.getApiContext().getDatabaseRepository().getDmpDao(),datasetWizardAutocompleteRequest,principal); return new ResponseItem>().status(HttpStatus.OK).payload(dataManagementPlans); } catch (Exception ex) { @@ -64,7 +55,7 @@ public class DatasetWizardController { @RequestMapping(method = RequestMethod.POST, value = { "/getAvailableProfiles" }, produces="application/json") public @ResponseBody ResponseItem> getAvailableProfiles(@RequestBody DatasetProfileWizardAutocompleteRequest datasetProfileWizardAutocompleteRequest, Principal principal) { try { - List dataManagementPlans = DatasetWizardManager.getAvailableProfiles(dMPDao,datasetProfileWizardAutocompleteRequest); + List dataManagementPlans = DatasetWizardManager.getAvailableProfiles(this.getApiContext().getDatabaseRepository().getDmpDao(),datasetProfileWizardAutocompleteRequest); return new ResponseItem>().status(HttpStatus.OK).payload(dataManagementPlans); } catch (Exception ex) { @@ -76,7 +67,7 @@ public class DatasetWizardController { @RequestMapping(method = RequestMethod.GET, value = { "/getSingle/{id}" }, produces="application/json") public @ResponseBody ResponseItem getPaged(@PathVariable String id) { try { - DatasetWizardModel dataset = new DatasetManager().getSingle(datasetDao, id); + DatasetWizardModel dataset = new DatasetManager().getSingle(this.getApiContext().getDatabaseRepository().getDatasetDao(), id); return new ResponseItem().status(HttpStatus.OK).payload(dataset); } catch (Exception ex) { @@ -89,7 +80,7 @@ public class DatasetWizardController { @RequestMapping(method = RequestMethod.POST, value = { "/createOrUpdate" }, produces="application/json") public @ResponseBody ResponseItem createOrUpdate(@RequestBody DatasetWizardModel profile) { try { - eu.eudat.entities.Dataset dataset= DatasetManager.createOrUpdate(datasetDao, dataRepositoryDao,serviceDao,registryDao,profile); + eu.eudat.entities.Dataset dataset= DatasetManager.createOrUpdate(this.getApiContext(),profile); return new ResponseItem().status(HttpStatus.OK).payload(dataset); } catch (Exception ex) { ex.printStackTrace(); diff --git a/dmp-backend/src/main/java/eu/eudat/controllers/Datasets.java b/dmp-backend/src/main/java/eu/eudat/controllers/Datasets.java index d4dbf207c..38d39b86b 100644 --- a/dmp-backend/src/main/java/eu/eudat/controllers/Datasets.java +++ b/dmp-backend/src/main/java/eu/eudat/controllers/Datasets.java @@ -13,6 +13,7 @@ import eu.eudat.models.dataset.DatasetTableRequest; import eu.eudat.models.helpers.DataTableData; import eu.eudat.models.helpers.responses.*; import eu.eudat.models.listingmodels.DatasetListingModel; +import eu.eudat.services.ApiContext; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -48,29 +49,17 @@ import javax.transaction.Transactional; @RestController @CrossOrigin -public class Datasets { - - @Autowired private DataRepositoryDao dataRepositoryDao; - @Autowired private DatasetDao datasetDao; - @Autowired private DatasetProfileDao datasetProfileDao; - @Autowired private DatasetProfileRulesetDao datasetProfileRulesetDao; - @Autowired private DatasetProfileViewstyleDao datasetProfileViewstyleDao; - @Autowired private DMPDao dMPDao; - @Autowired private DMPProfileDao dMPProfileDao; - @Autowired private OrganisationDao organisationDao; - @Autowired private ProjectDao projectDao; - @Autowired private RegistryDao registryDao; - @Autowired private ResearcherDao researcherDao; - @Autowired private ServiceDao serviceDao; - @Autowired private UserInfoDao userInfoDao; - - +public class Datasets extends BaseController{ + @Autowired + public Datasets(ApiContext apiContext) { + super(apiContext); + } @RequestMapping(method = RequestMethod.POST, value = { "/datasets/getPaged" }, consumes = "application/json", produces="application/json") public @ResponseBody ResponseItem> getPaged(@RequestBody DatasetTableRequest datasetTableRequest) { try { - DataTableData dataTable = new DatasetManager().getPaged(datasetDao, datasetTableRequest); + DataTableData dataTable = new DatasetManager().getPaged(this.getApiContext().getDatabaseRepository().getDatasetDao(), datasetTableRequest); return new ResponseItem>().status(HttpStatus.OK).payload(dataTable); } catch (Exception ex) { diff --git a/dmp-backend/src/main/java/eu/eudat/controllers/DmpProfiles.java b/dmp-backend/src/main/java/eu/eudat/controllers/DmpProfiles.java index c0b9912c3..ad4a7f918 100644 --- a/dmp-backend/src/main/java/eu/eudat/controllers/DmpProfiles.java +++ b/dmp-backend/src/main/java/eu/eudat/controllers/DmpProfiles.java @@ -6,6 +6,7 @@ import java.util.UUID; import javax.transaction.Transactional; import eu.eudat.entities.DMPProfile; +import eu.eudat.services.ApiContext; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -34,28 +35,17 @@ import eu.eudat.entities.responses.IDLabelPair; @RestController @CrossOrigin -public class DmpProfiles { - - @Autowired private DataRepositoryDao dataRepositoryDao; - @Autowired private DatasetDao datasetDao; - @Autowired private DatasetProfileDao datasetProfileDao; - @Autowired private DatasetProfileRulesetDao datasetProfileRulesetDao; - @Autowired private DatasetProfileViewstyleDao datasetProfileViewstyleDao; - @Autowired private DMPDao dMPDao; - @Autowired private DMPProfileDao dMPProfileDao; - @Autowired private OrganisationDao organisationDao; - @Autowired private ProjectDao projectDao; - @Autowired private RegistryDao registryDao; - @Autowired private ResearcherDao researcherDao; - @Autowired private ServiceDao serviceDao; - - - // MANAGE DMPPROFILE(S) +public class DmpProfiles extends BaseController{ + + @Autowired + public DmpProfiles(ApiContext apiContext) { + super(apiContext); + } @RequestMapping(method = RequestMethod.GET, value = { "/dmpprofiles" }) public @ResponseBody ResponseEntity> listDmpProfiles(){ try { - List allIDs = dMPProfileDao.listAllIDs(); + List allIDs = this.getApiContext().getDatabaseRepository().getDMPProfileDao().listAllIDs(); return ResponseEntity.status(HttpStatus.OK).body(allIDs); } catch(Exception ex) { @@ -69,7 +59,7 @@ public class DmpProfiles { @RequestMapping(method = RequestMethod.GET, value = { "/dmpprofiles/{id}" }) public @ResponseBody ResponseEntity getDmpProfile(@PathVariable("id") String id) { try { - DMPProfile dmpProfile = dMPProfileDao.read(UUID.fromString(id)); + DMPProfile dmpProfile = this.getApiContext().getDatabaseRepository().getDMPProfileDao().read(UUID.fromString(id)); return ResponseEntity.status(HttpStatus.OK).body(dmpProfile); } catch(Exception ex) { @@ -82,7 +72,7 @@ public class DmpProfiles { @RequestMapping(method = RequestMethod.GET, value = { "/dmpprofile/listAllLabelIDs" }) public @ResponseBody ResponseEntity> listLabelIds(){ try { - List allIDs = dMPProfileDao.listAllIDsLabels(); + List allIDs = this.getApiContext().getDatabaseRepository().getDMPProfileDao().listAllIDsLabels(); return ResponseEntity.status(HttpStatus.OK).body(allIDs); } catch(Exception ex) { @@ -94,7 +84,7 @@ public class DmpProfiles { @RequestMapping(method = RequestMethod.GET, value = { "/dmpprofile/getAll" }, produces="application/json") public @ResponseBody ResponseEntity getAllDmpProfiles(){ try { - List allDmpProfiles = dMPProfileDao.getAll(); + List allDmpProfiles = this.getApiContext().getDatabaseRepository().getDMPProfileDao().getAll(); return ResponseEntity.status(HttpStatus.OK).body(allDmpProfiles); } catch(Exception ex) { @@ -107,7 +97,7 @@ public class DmpProfiles { @RequestMapping(method = RequestMethod.POST, value = { "/dmpprofile/create" }, consumes = "application/json", produces="application/json") public @ResponseBody ResponseEntity setDmpProfile(@RequestBody DMPProfile dmpprofile) { try { - DMPProfile createdDMPProfile = dMPProfileDao.update(dmpprofile); + DMPProfile createdDMPProfile = this.getApiContext().getDatabaseRepository().getDMPProfileDao().update(dmpprofile); return ResponseEntity.status(HttpStatus.CREATED).body(createdDMPProfile); } catch (Exception e) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null); @@ -121,7 +111,7 @@ public class DmpProfiles { DMPProfile dmpp = new DMPProfile(); dmpp.setId(dmpprofile.getId()); try { - dMPProfileDao.delete(dmpp); + this.getApiContext().getDatabaseRepository().getDMPProfileDao().delete(dmpp); return ResponseEntity.status(HttpStatus.CREATED).body("{\"msg\":\"Deleted DMP Profile!\"}"); } catch (Exception e) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not Delete DMP Profile!\"}"); diff --git a/dmp-backend/src/main/java/eu/eudat/controllers/Organisations.java b/dmp-backend/src/main/java/eu/eudat/controllers/Organisations.java index 1d938d7e3..b1d912e34 100644 --- a/dmp-backend/src/main/java/eu/eudat/controllers/Organisations.java +++ b/dmp-backend/src/main/java/eu/eudat/controllers/Organisations.java @@ -10,6 +10,7 @@ import eu.eudat.entities.Organisation; import eu.eudat.models.external.OrganisationsExternalSourcesModel; import eu.eudat.models.external.ProjectsExternalSourcesModel; import eu.eudat.models.helpers.responses.ResponseItem; +import eu.eudat.services.ApiContext; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -41,29 +42,17 @@ import eu.eudat.proxy.fetching.RemoteFetcher; @RestController @CrossOrigin -public class Organisations { - - @Autowired private DataRepositoryDao dataRepositoryDao; - @Autowired private DatasetDao datasetDao; - @Autowired private DatasetProfileDao datasetProfileDao; - @Autowired private DatasetProfileRulesetDao datasetProfileRulesetDao; - @Autowired private DatasetProfileViewstyleDao datasetProfileViewstyleDao; - @Autowired private DMPDao dMPDao; - @Autowired private DMPProfileDao dMPProfileDao; - @Autowired private OrganisationDao organisationDao; - @Autowired private ProjectDao projectDao; - @Autowired private RegistryDao registryDao; - @Autowired private ResearcherDao researcherDao; - @Autowired private ServiceDao serviceDao; - - - @Autowired private RemoteFetcher remoteFetcher; - - +public class Organisations extends BaseController{ + + @Autowired + public Organisations(ApiContext apiContext) { + super(apiContext); + } + @RequestMapping(method = RequestMethod.GET, value = { "/external/organisations" }, produces="application/json") public @ResponseBody ResponseItem listExternalOrganisations(@RequestParam(value="query", required=false) String query ){ try { - List> remoteRepos = remoteFetcher.getOrganisations(query); + List> remoteRepos = this.getApiContext().getRemoteFetcher().getOrganisations(query); OrganisationsExternalSourcesModel projectsExternalSourcesModel = new OrganisationsExternalSourcesModel().fromExternalItem(remoteRepos); return new ResponseItem().payload(projectsExternalSourcesModel).status(HttpStatus.OK); } @@ -83,7 +72,7 @@ public class Organisations { @RequestMapping(method = RequestMethod.GET, value = { "/organisations" }) public @ResponseBody ResponseEntity> listOrganisations(){ try { - List allIDs = organisationDao.listAllIDs(); + List allIDs = this.getApiContext().getDatabaseRepository().getOrganisationDao().listAllIDs(); return ResponseEntity.status(HttpStatus.OK).body(allIDs); } catch(Exception ex) { @@ -95,7 +84,7 @@ public class Organisations { @RequestMapping(method = RequestMethod.GET, value = { "/organisations/{id}" }) public @ResponseBody ResponseEntity getOrganisations(@PathVariable("id") String id) { try { - Organisation organisation = organisationDao.read(UUID.fromString(id)); + Organisation organisation = this.getApiContext().getDatabaseRepository().getOrganisationDao().read(UUID.fromString(id)); return ResponseEntity.status(HttpStatus.OK).body(organisation); } catch(Exception ex) { @@ -107,7 +96,7 @@ public class Organisations { @RequestMapping(method = RequestMethod.GET, value = { "/organisation/getAll" }, produces="application/json") public @ResponseBody ResponseEntity getAllOrganisations(){ try { - List allOrganisations = organisationDao.getAll(); + List allOrganisations = this.getApiContext().getDatabaseRepository().getOrganisationDao().getAll(); return ResponseEntity.status(HttpStatus.OK).body(allOrganisations); } catch(Exception ex) { @@ -120,7 +109,7 @@ public class Organisations { @RequestMapping(method = RequestMethod.POST, value = { "/organisation/create" }, consumes = "application/json", produces="application/json") public @ResponseBody ResponseEntity setOrganisation(@RequestBody Organisation organisation) { try { - Organisation createdOrganisation = organisationDao.update(organisation); + Organisation createdOrganisation = this.getApiContext().getDatabaseRepository().getOrganisationDao().update(organisation); return ResponseEntity.status(HttpStatus.CREATED).body(createdOrganisation); } catch (Exception e) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null); @@ -134,7 +123,7 @@ public class Organisations { Organisation org = new Organisation(); org.setId(organisation.getId()); try { - organisationDao.delete(org); + this.getApiContext().getDatabaseRepository().getOrganisationDao().delete(org); return ResponseEntity.status(HttpStatus.CREATED).body(null); } catch (Exception e) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null); diff --git a/dmp-backend/src/main/java/eu/eudat/controllers/Projects.java b/dmp-backend/src/main/java/eu/eudat/controllers/Projects.java index 424f4bbda..e4ccbf5df 100644 --- a/dmp-backend/src/main/java/eu/eudat/controllers/Projects.java +++ b/dmp-backend/src/main/java/eu/eudat/controllers/Projects.java @@ -16,6 +16,7 @@ import eu.eudat.models.external.RegistriesExternalSourcesModel; import eu.eudat.models.helpers.responses.*; import eu.eudat.models.project.ProjectCriteriaRequest; import eu.eudat.models.security.Principal; +import eu.eudat.services.ApiContext; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.http.HttpStatus; @@ -61,33 +62,14 @@ import eu.eudat.proxy.fetching.RemoteFetcher; public class Projects extends BaseController{ @Autowired - public Projects(ApplicationContext applicationContext){ - super(applicationContext); + public Projects(ApiContext apiContext){ + super(apiContext); } - @Autowired private DataRepositoryDao dataRepositoryDao; - @Autowired private DatasetDao datasetDao; - @Autowired private DatasetProfileDao datasetProfileDao; - @Autowired private DatasetProfileRulesetDao datasetProfileRulesetDao; - @Autowired private DatasetProfileViewstyleDao datasetProfileViewstyleDao; - @Autowired private DMPDao dMPDao; - @Autowired private DMPProfileDao dMPProfileDao; - @Autowired private OrganisationDao organisationDao; - @Autowired private ProjectDao projectDao; - @Autowired private RegistryDao registryDao; - @Autowired private ResearcherDao researcherDao; - @Autowired private ServiceDao serviceDao; - @Autowired private UserInfoDao userInfoDao; - - @Autowired private RemoteFetcher remoteFetcher; - - - - @RequestMapping(method = RequestMethod.POST, value = { "/projects/getPaged" }, consumes = "application/json", produces="application/json") public @ResponseBody ResponseItem> getPaged(@Valid @RequestBody ProjectTableRequest projectTableRequest) { try { - DataTableData dataTable = new ProjectManager().getPaged(projectDao, projectTableRequest); + DataTableData dataTable = new ProjectManager().getPaged(this.getApiContext().getDatabaseRepository().getProjectDao(), projectTableRequest); return new ResponseItem>().payload(dataTable).status(HttpStatus.OK); } catch (Exception ex) { @@ -99,7 +81,7 @@ public class Projects extends BaseController{ @RequestMapping(method = RequestMethod.GET, value = { "/projects/getSingle/{id}" }, produces="application/json") public @ResponseBody ResponseItem getPaged(@PathVariable String id) { try { - eu.eudat.models.project.Project project = new ProjectManager().getSingle(projectDao, id); + eu.eudat.models.project.Project project = new ProjectManager().getSingle(this.getApiContext().getDatabaseRepository().getProjectDao(), id); return new ResponseItem().payload(project).status(HttpStatus.OK); } catch (Exception ex) { ex.printStackTrace(); @@ -112,7 +94,7 @@ public class Projects extends BaseController{ @RequestMapping(method = RequestMethod.POST, value = { "/projects/createOrUpdate" }, consumes = "application/json", produces="application/json") public @ResponseBody ResponseItem addProject(@Valid @RequestBody eu.eudat.models.project.Project project, Principal principal) { try { - ProjectManager.createOrUpdate(projectDao,userInfoDao,project,principal); + ProjectManager.createOrUpdate(this.getApiContext().getDatabaseRepository().getProjectDao(),this.getApiContext().getDatabaseRepository().getUserInfoDao(),project,principal); return new ResponseItem().status(HttpStatus.OK); }catch (Exception ex){ return new ResponseItem().status(HttpStatus.BAD_REQUEST).message(ex.getMessage()); @@ -124,7 +106,7 @@ public class Projects extends BaseController{ @RequestMapping(method = RequestMethod.DELETE, value = { "/projects/inactivate/{id}" }, consumes = "application/json", produces="application/json") public @ResponseBody ResponseItem inactivate(@PathVariable String id) { try { - Project project = new ProjectManager().inactivate(projectDao,id); + Project project = new ProjectManager().inactivate(this.getApiContext().getDatabaseRepository().getProjectDao(),id); return new ResponseItem().status(HttpStatus.OK); }catch (Exception ex){ return new ResponseItem().status(HttpStatus.BAD_REQUEST).message(ex.getMessage()); @@ -135,7 +117,7 @@ public class Projects extends BaseController{ @RequestMapping(method = RequestMethod.POST, value = { "/projects/getWithExternal" }, consumes = "application/json", produces="application/json") public @ResponseBody ResponseItem> getWithExternal(@RequestBody ProjectCriteriaRequest projectCriteria) { try { - List dataTable = new ProjectManager().getCriteriaWithExternal(projectDao, projectCriteria,remoteFetcher); + List dataTable = new ProjectManager().getCriteriaWithExternal(this.getApiContext().getDatabaseRepository().getProjectDao(), projectCriteria,this.getApiContext().getRemoteFetcher()); return new ResponseItem>().payload(dataTable).status(HttpStatus.OK); } catch (Exception ex) { ex.printStackTrace(); @@ -146,7 +128,7 @@ public class Projects extends BaseController{ @RequestMapping(method = RequestMethod.POST, value = { "/projects/get" }, consumes = "application/json", produces="application/json") public @ResponseBody ResponseItem> get(@RequestBody ProjectCriteriaRequest projectCriteria) { try { - List dataTable = new ProjectManager().getCriteria(projectDao, projectCriteria,remoteFetcher); + List dataTable = new ProjectManager().getCriteria(this.getApiContext().getDatabaseRepository().getProjectDao(), projectCriteria,this.getApiContext().getRemoteFetcher()); return new ResponseItem>().payload(dataTable).status(HttpStatus.OK); } catch (Exception ex) { ex.printStackTrace(); @@ -160,7 +142,7 @@ public class Projects extends BaseController{ @RequestMapping(method = RequestMethod.GET, value = { "/external/projects" }, produces="application/json") public @ResponseBody ResponseItem listExternalProjects(@RequestParam(value="query", required=false) String query ){ try { - List> remoteRepos = remoteFetcher.getProjects(query); + List> remoteRepos = this.getApiContext().getRemoteFetcher().getProjects(query); ProjectsExternalSourcesModel projectsExternalSourcesModel = new ProjectsExternalSourcesModel().fromExternalItem(remoteRepos); return new ResponseItem().payload(projectsExternalSourcesModel).status(HttpStatus.OK); } diff --git a/dmp-backend/src/main/java/eu/eudat/controllers/Registries.java b/dmp-backend/src/main/java/eu/eudat/controllers/Registries.java index 5665cc8fe..04c34c7ed 100644 --- a/dmp-backend/src/main/java/eu/eudat/controllers/Registries.java +++ b/dmp-backend/src/main/java/eu/eudat/controllers/Registries.java @@ -8,6 +8,7 @@ import eu.eudat.entities.Registry; import eu.eudat.models.external.RegistriesExternalSourcesModel; import eu.eudat.models.external.ResearchersExternalSourcesModel; import eu.eudat.models.helpers.responses.ResponseItem; +import eu.eudat.services.ApiContext; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -42,28 +43,17 @@ import javax.transaction.Transactional; @RestController @CrossOrigin -public class Registries { - - @Autowired private DataRepositoryDao dataRepositoryDao; - @Autowired private DatasetDao datasetDao; - @Autowired private DatasetProfileDao datasetProfileDao; - @Autowired private DatasetProfileRulesetDao datasetProfileRulesetDao; - @Autowired private DatasetProfileViewstyleDao datasetProfileViewstyleDao; - @Autowired private DMPDao dMPDao; - @Autowired private DMPProfileDao dMPProfileDao; - @Autowired private OrganisationDao organisationDao; - @Autowired private ProjectDao projectDao; - @Autowired private RegistryDao registryDao; - @Autowired private ResearcherDao researcherDao; - @Autowired private ServiceDao serviceDao; - - @Autowired private RemoteFetcher remoteFetcher; - - +public class Registries extends BaseController{ + + @Autowired + public Registries(ApiContext apiContext) { + super(apiContext); + } + @RequestMapping(method = RequestMethod.GET, value = { "/external/registries" }, produces="application/json") public @ResponseBody ResponseItem listExternalRegistries(@RequestParam(value="query", required=false) String query ){ try { - List> remoteRepos = remoteFetcher.getRegistries(query); + List> remoteRepos = this.getApiContext().getRemoteFetcher().getRegistries(query); RegistriesExternalSourcesModel registriesExternalSourcesModel = new RegistriesExternalSourcesModel().fromExternalItem(remoteRepos); return new ResponseItem().payload(registriesExternalSourcesModel).status(HttpStatus.OK); } @@ -83,7 +73,7 @@ public class Registries { @RequestMapping(method = RequestMethod.GET, value = { "/registries" }) public @ResponseBody ResponseEntity> listRegistries(){ try { - List allIDs = registryDao.listAllIDs(); + List allIDs = this.getApiContext().getDatabaseRepository().getRegistryDao().listAllIDs(); return ResponseEntity.status(HttpStatus.OK).body(allIDs); } catch(Exception ex) { @@ -95,7 +85,7 @@ public class Registries { @RequestMapping(method = RequestMethod.GET, value = { "/registries/{id}" }) public @ResponseBody ResponseEntity getRegistries(@PathVariable("id") String id) { try { - Registry registry = registryDao.read(UUID.fromString(id)); + Registry registry = this.getApiContext().getDatabaseRepository().getRegistryDao().read(UUID.fromString(id)); return ResponseEntity.status(HttpStatus.OK).body(registry); } catch(Exception ex) { @@ -108,7 +98,7 @@ public class Registries { @RequestMapping(method = RequestMethod.GET, value = { "/registries/listAllLabelIDs" }) public @ResponseBody ResponseEntity> listLabelIds(){ try { - List allIDs = registryDao.listAllIDsLabels(); + List allIDs = this.getApiContext().getDatabaseRepository().getRegistryDao().listAllIDsLabels(); return ResponseEntity.status(HttpStatus.OK).body(allIDs); } catch(Exception ex) { @@ -120,7 +110,7 @@ public class Registries { @RequestMapping(method = RequestMethod.GET, value = { "/registry/getAll" }, produces="application/json") public @ResponseBody ResponseEntity getAllRegistries(){ try { - List allRegistries = registryDao.getAll(); + List allRegistries = this.getApiContext().getDatabaseRepository().getRegistryDao().getAll(); return ResponseEntity.status(HttpStatus.OK).body(allRegistries); @@ -134,7 +124,7 @@ public class Registries { @Transactional @RequestMapping(method = RequestMethod.POST, value = { "/registry/create" }, consumes = "application/json", produces="application/json") public @ResponseBody ResponseEntity setRegistry(@RequestBody Registry registry) { - Registry createdRegistry = registryDao.update(registry); + Registry createdRegistry = this.getApiContext().getDatabaseRepository().getRegistryDao().update(registry); try { return ResponseEntity.status(HttpStatus.CREATED).body(createdRegistry); } catch (Exception e) { @@ -149,7 +139,7 @@ public class Registries { Registry r = new Registry(); r.setId(registry.getId()); try { - registryDao.delete(r); + this.getApiContext().getDatabaseRepository().getRegistryDao().delete(r); return ResponseEntity.status(HttpStatus.CREATED).body("{\"msg\":\"Deleted registry!\"}"); } catch (Exception e) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not Delete registry!\"}"); diff --git a/dmp-backend/src/main/java/eu/eudat/controllers/Researchers.java b/dmp-backend/src/main/java/eu/eudat/controllers/Researchers.java index 66a7fcf56..bdad7445a 100644 --- a/dmp-backend/src/main/java/eu/eudat/controllers/Researchers.java +++ b/dmp-backend/src/main/java/eu/eudat/controllers/Researchers.java @@ -10,6 +10,7 @@ import eu.eudat.entities.Researcher; import eu.eudat.models.external.ResearchersExternalSourcesModel; import eu.eudat.models.external.ServiceExternalSourcesModel; import eu.eudat.models.helpers.responses.ResponseItem; +import eu.eudat.services.ApiContext; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -41,28 +42,17 @@ import eu.eudat.proxy.fetching.RemoteFetcher; @RestController @CrossOrigin -public class Researchers { - - @Autowired private DataRepositoryDao dataRepositoryDao; - @Autowired private DatasetDao datasetDao; - @Autowired private DatasetProfileDao datasetProfileDao; - @Autowired private DatasetProfileRulesetDao datasetProfileRulesetDao; - @Autowired private DatasetProfileViewstyleDao datasetProfileViewstyleDao; - @Autowired private DMPDao dMPDao; - @Autowired private DMPProfileDao dMPProfileDao; - @Autowired private OrganisationDao organisationDao; - @Autowired private ProjectDao projectDao; - @Autowired private RegistryDao registryDao; - @Autowired private ResearcherDao researcherDao; - @Autowired private ServiceDao serviceDao; - - @Autowired private RemoteFetcher remoteFetcher; - - +public class Researchers extends BaseController{ + + @Autowired + public Researchers(ApiContext apiContext) { + super(apiContext); + } + @RequestMapping(method = RequestMethod.GET, value = { "/external/researchers" }, produces="application/json") public @ResponseBody ResponseItem listExternalResearchers(@RequestParam(value="query", required=false) String query ){ try { - List> remoteRepos = remoteFetcher.getResearchers(query); + List> remoteRepos = this.getApiContext().getRemoteFetcher().getResearchers(query); ResearchersExternalSourcesModel researchersExternalSourcesModel = new ResearchersExternalSourcesModel().fromExternalItem(remoteRepos); return new ResponseItem().payload(researchersExternalSourcesModel).status(HttpStatus.OK); } @@ -82,7 +72,7 @@ public class Researchers { @RequestMapping(method = RequestMethod.GET, value = { "/researchers" }) public @ResponseBody ResponseEntity> listResearchers(){ try { - List allIDs = researcherDao.listAllIDs(); + List allIDs = this.getApiContext().getDatabaseRepository().getResearcherDao().listAllIDs(); return ResponseEntity.status(HttpStatus.OK).body(allIDs); } catch(Exception ex) { @@ -94,7 +84,7 @@ public class Researchers { @RequestMapping(method = RequestMethod.GET, value = { "/researchers/{id}" }) public @ResponseBody ResponseEntity getResearchers(@PathVariable("id") String id) { try { - Researcher researcher = researcherDao.read(UUID.fromString(id)); + Researcher researcher = this.getApiContext().getDatabaseRepository().getResearcherDao().read(UUID.fromString(id)); return ResponseEntity.status(HttpStatus.OK).body(researcher); } catch(Exception ex) { @@ -105,7 +95,7 @@ public class Researchers { @RequestMapping(method = RequestMethod.GET, value = { "/researcher/getByEmail" }, produces="application/json") public @ResponseBody ResponseEntity getResearcherByEmail(@RequestParam("email") String email){ try { - Researcher researcher = researcherDao.getResearcherByEmail(email); + Researcher researcher = this.getApiContext().getDatabaseRepository().getResearcherDao().getResearcherByEmail(email); return ResponseEntity.status(HttpStatus.OK).body(researcher); } catch(Exception ex) { @@ -118,7 +108,7 @@ public class Researchers { @RequestMapping(method = RequestMethod.GET, value = { "/researcher/getAll" }, produces="application/json") public @ResponseBody ResponseEntity> getAllResearchers(){ try { - List allResearchers = researcherDao.getAll(); + List allResearchers = this.getApiContext().getDatabaseRepository().getResearcherDao().getAll(); return ResponseEntity.status(HttpStatus.OK).body(allResearchers); @@ -132,7 +122,7 @@ public class Researchers { @Transactional @RequestMapping(method = RequestMethod.POST, value = { "/researcher/create" }, consumes = "application/json", produces="application/json") public @ResponseBody ResponseEntity setResearcher(@RequestBody Researcher researcher) { - Researcher createdResearcher = researcherDao.update(researcher); + Researcher createdResearcher = this.getApiContext().getDatabaseRepository().getResearcherDao().update(researcher); try { return ResponseEntity.status(HttpStatus.CREATED).body(createdResearcher); } catch (Exception e) { @@ -147,7 +137,7 @@ public class Researchers { Researcher res = new Researcher(); res.setId(researcher.getId()); try { - researcherDao.delete(res); + this.getApiContext().getDatabaseRepository().getResearcherDao().delete(res); return ResponseEntity.status(HttpStatus.CREATED).body("{\"msg\":\"Deleted researcher!\"}"); } catch (Exception e) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not delete researcher!\"}"); diff --git a/dmp-backend/src/main/java/eu/eudat/controllers/Services.java b/dmp-backend/src/main/java/eu/eudat/controllers/Services.java index 7aa301b00..3e43490e6 100644 --- a/dmp-backend/src/main/java/eu/eudat/controllers/Services.java +++ b/dmp-backend/src/main/java/eu/eudat/controllers/Services.java @@ -9,6 +9,7 @@ import javax.transaction.Transactional; import eu.eudat.entities.Service; import eu.eudat.models.external.ServiceExternalSourcesModel; import eu.eudat.models.helpers.responses.ResponseItem; +import eu.eudat.services.ApiContext; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -40,28 +41,17 @@ import eu.eudat.proxy.fetching.RemoteFetcher; @RestController @CrossOrigin -public class Services { - - @Autowired private DataRepositoryDao dataRepositoryDao; - @Autowired private DatasetDao datasetDao; - @Autowired private DatasetProfileDao datasetProfileDao; - @Autowired private DatasetProfileRulesetDao datasetProfileRulesetDao; - @Autowired private DatasetProfileViewstyleDao datasetProfileViewstyleDao; - @Autowired private DMPDao dMPDao; - @Autowired private DMPProfileDao dMPProfileDao; - @Autowired private OrganisationDao organisationDao; - @Autowired private ProjectDao projectDao; - @Autowired private RegistryDao registryDao; - @Autowired private ResearcherDao researcherDao; - @Autowired private ServiceDao serviceDao; - - @Autowired private RemoteFetcher remoteFetcher; - - +public class Services extends BaseController{ + + @Autowired + public Services(ApiContext apiContext) { + super(apiContext); + } + @RequestMapping(method = RequestMethod.GET, value = { "/external/services" }, produces="application/json") public @ResponseBody ResponseItem listExternalServices(@RequestParam(value="query", required=false) String query ){ try { - List> remoteRepos = remoteFetcher.getServices(query); + List> remoteRepos = this.getApiContext().getRemoteFetcher().getServices(query); ServiceExternalSourcesModel serviceExternalSourcesModel = new ServiceExternalSourcesModel().fromExternalItem(remoteRepos); return new ResponseItem().payload(serviceExternalSourcesModel).status(HttpStatus.OK); } @@ -87,7 +77,7 @@ public class Services { @RequestMapping(method = RequestMethod.GET, value = { "/services" }) public @ResponseBody ResponseEntity> listServices(){ try { - List allIDs = serviceDao.listAllIDs(); + List allIDs = this.getApiContext().getDatabaseRepository().getServiceDao().listAllIDs(); return ResponseEntity.status(HttpStatus.OK).body(allIDs); } catch(Exception ex) { @@ -99,7 +89,7 @@ public class Services { @RequestMapping(method = RequestMethod.GET, value = { "/services/{id}" }) public @ResponseBody ResponseEntity getServices(@PathVariable("id") String id) { try { - Service service = serviceDao.read(UUID.fromString(id)); + Service service = this.getApiContext().getDatabaseRepository().getServiceDao().read(UUID.fromString(id)); return ResponseEntity.status(HttpStatus.OK).body(service); } catch(Exception ex) { @@ -112,7 +102,7 @@ public class Services { @RequestMapping(method = RequestMethod.GET, value = { "/service/getAll" }, produces="application/json") public @ResponseBody ResponseEntity getAllServices(){ try { - List allServices = serviceDao.getAll(); + List allServices = this.getApiContext().getDatabaseRepository().getServiceDao().getAll(); return ResponseEntity.status(HttpStatus.OK).body(allServices); @@ -127,7 +117,7 @@ public class Services { @RequestMapping(method = RequestMethod.POST, value = { "/service/create" }, consumes = "application/json", produces="application/json") public @ResponseBody ResponseEntity setService(@RequestBody Service service) { - Service createdService = serviceDao.update(service); + Service createdService = this.getApiContext().getDatabaseRepository().getServiceDao().update(service); try { return ResponseEntity.status(HttpStatus.CREATED).body(createdService); } catch (Exception e) { @@ -142,7 +132,7 @@ public class Services { System.out.println(service); try { - serviceDao.delete(service); + this.getApiContext().getDatabaseRepository().getServiceDao().delete(service); return ResponseEntity.status(HttpStatus.CREATED).body("{\"msg\":\"Deleted Service entity!\"}"); } catch (Exception e) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not Delete Service entity!\"}"); diff --git a/dmp-backend/src/main/java/eu/eudat/controllers/Users.java b/dmp-backend/src/main/java/eu/eudat/controllers/Users.java index 8f6b0cff8..8f4cc4a65 100644 --- a/dmp-backend/src/main/java/eu/eudat/controllers/Users.java +++ b/dmp-backend/src/main/java/eu/eudat/controllers/Users.java @@ -6,6 +6,7 @@ import java.util.stream.Collectors; import javax.transaction.Transactional; +import eu.eudat.services.ApiContext; import org.apache.commons.lang3.SerializationUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; @@ -55,28 +56,15 @@ import eu.eudat.helpers.Transformers; @RestController @CrossOrigin -public class Users { - - @Autowired private DataRepositoryDao dataRepositoryDao; - @Autowired private DatasetDao datasetDao; - @Autowired private DatasetProfileDao datasetProfileDao; - @Autowired private DatasetProfileRulesetDao datasetProfileRulesetDao; - @Autowired private DatasetProfileViewstyleDao datasetProfileViewstyleDao; - @Autowired private DMPDao dMPDao; - @Autowired private DMPProfileDao dMPProfileDao; - @Autowired private OrganisationDao organisationDao; - @Autowired private ProjectDao projectDao; - @Autowired private RegistryDao registryDao; - @Autowired private ResearcherDao researcherDao; - @Autowired private ServiceDao serviceDao; - @Autowired private UserInfoDao userInfoDao; - - +public class Users extends BaseController{ + + @Autowired + public Users(ApiContext apiContext) { + super(apiContext); + } @RequestMapping(method = RequestMethod.GET, value = { "/user/whoami" }, produces="application/json;charset=UTF-8") public @ResponseBody ResponseEntity whoami(){ - - String userID = null; try { userID = SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString(); @@ -85,7 +73,7 @@ public class Users { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null); } - UserInfo userInfo = userInfoDao.getUserInfo(userID); + UserInfo userInfo = this.getApiContext().getDatabaseRepository().getUserInfoDao().getUserInfo(userID); if(userInfo==null) //this should normally never happer diff --git a/dmp-backend/src/main/java/eu/eudat/managers/DataManagementPlanManager.java b/dmp-backend/src/main/java/eu/eudat/managers/DataManagementPlanManager.java index 48aa38c6f..9fa25072f 100644 --- a/dmp-backend/src/main/java/eu/eudat/managers/DataManagementPlanManager.java +++ b/dmp-backend/src/main/java/eu/eudat/managers/DataManagementPlanManager.java @@ -18,6 +18,7 @@ import eu.eudat.models.helpers.DataTableData; import eu.eudat.models.listingmodels.DataManagementPlanListingModel; import eu.eudat.models.security.Principal; import eu.eudat.queryable.QueryableList; +import eu.eudat.services.ApiContext; import eu.eudat.utilities.builders.DomainModelConverter; public class DataManagementPlanManager { @@ -45,14 +46,14 @@ public class DataManagementPlanManager { return datamanagementPlans; } - public static void createOrUpdate(DMPDao dmpsRepository, ProjectDao projectDao,ResearcherDao researcherRepository, UserInfoDao userInfoDao, OrganisationDao organisationRepository, DataManagementPlan dataManagementPlan, Principal principal){ + public static void createOrUpdate(ApiContext apiContext, DataManagementPlan dataManagementPlan, Principal principal){ DMP newDmp = dataManagementPlan.toDataModel(); - createOrganisationsIfTheyDontExist(newDmp,organisationRepository); - createResearchersIfTheyDontExist(newDmp,researcherRepository); - UserInfo user = userInfoDao.read(principal.getId()); - createProjectIfItDoesntExist(newDmp,projectDao,user); + createOrganisationsIfTheyDontExist(newDmp,apiContext.getDatabaseRepository().getOrganisationDao()); + createResearchersIfTheyDontExist(newDmp,apiContext.getDatabaseRepository().getResearcherDao()); + UserInfo user = apiContext.getDatabaseRepository().getUserInfoDao().read(principal.getId()); + createProjectIfItDoesntExist(newDmp,apiContext.getDatabaseRepository().getProjectDao(),user); newDmp.setCreator(user); - dmpsRepository.createOrUpdate(newDmp); + apiContext.getDatabaseRepository().getDmpDao().createOrUpdate(newDmp); } diff --git a/dmp-backend/src/main/java/eu/eudat/managers/DatasetManager.java b/dmp-backend/src/main/java/eu/eudat/managers/DatasetManager.java index e9bddcb7a..f22563f0c 100644 --- a/dmp-backend/src/main/java/eu/eudat/managers/DatasetManager.java +++ b/dmp-backend/src/main/java/eu/eudat/managers/DatasetManager.java @@ -12,6 +12,7 @@ import eu.eudat.models.listingmodels.DatasetListingModel; import eu.eudat.models.project.Project; import eu.eudat.models.project.ProjectTableRequest; import eu.eudat.queryable.QueryableList; +import eu.eudat.services.ApiContext; import eu.eudat.utilities.builders.DomainModelConverter; import org.json.JSONObject; @@ -50,12 +51,12 @@ public class DatasetManager { return dataset; } - public static eu.eudat.entities.Dataset createOrUpdate(DatasetDao datatasetRepository, DataRepositoryDao dataRepositoryDao, ServiceDao serviceDao, RegistryDao registryDao, DatasetWizardModel profile) throws InstantiationException, IllegalAccessException{ + public static eu.eudat.entities.Dataset createOrUpdate(ApiContext apiContext, DatasetWizardModel profile) throws InstantiationException, IllegalAccessException{ eu.eudat.entities.Dataset dataset = profile.toDataModel(); - createRegistriesIfTheyDontExist(registryDao,dataset); - createDataRepositoriesIfTheyDontExist(dataRepositoryDao,dataset); - createServicesIfTheyDontExist(serviceDao,dataset); - return datatasetRepository.createOrUpdate(dataset); + createRegistriesIfTheyDontExist(apiContext.getDatabaseRepository().getRegistryDao(),dataset); + createDataRepositoriesIfTheyDontExist(apiContext.getDatabaseRepository().getDataRepositoryDao(),dataset); + createServicesIfTheyDontExist(apiContext.getDatabaseRepository().getServiceDao(),dataset); + return apiContext.getDatabaseRepository().getDatasetDao().createOrUpdate(dataset); } diff --git a/dmp-backend/src/main/java/eu/eudat/queryable/hibernatequeryablelist/QueryableHibernateList.java b/dmp-backend/src/main/java/eu/eudat/queryable/hibernatequeryablelist/QueryableHibernateList.java index 351e84dfa..36800eb70 100644 --- a/dmp-backend/src/main/java/eu/eudat/queryable/hibernatequeryablelist/QueryableHibernateList.java +++ b/dmp-backend/src/main/java/eu/eudat/queryable/hibernatequeryablelist/QueryableHibernateList.java @@ -1,7 +1,6 @@ package eu.eudat.queryable.hibernatequeryablelist; - import eu.eudat.entities.DataEntity; import eu.eudat.queryable.QueryableList; import eu.eudat.queryable.predicates.OrderByPredicate; @@ -30,6 +29,7 @@ public class QueryableHibernateList> implements Queryabl private Integer offset; private Set hints; private String hint; + public QueryableHibernateList(EntityManager manager, Class tClass) { this.manager = manager; this.tClass = tClass; @@ -40,10 +40,11 @@ public class QueryableHibernateList> implements Queryabl return this; } - public void withHint(String hint){ + public void withHint(String hint) { this.hint = hint; } - public QueryableList setHints(Set hints){ + + public QueryableList setHints(Set hints) { this.hints = hints; return this; } @@ -101,7 +102,7 @@ public class QueryableHibernateList> implements Queryabl return this; } - public Long count(){ + public Long count() { CriteriaBuilder criteriaBuilder = this.manager.getCriteriaBuilder(); CriteriaQuery criteriaQuery = criteriaBuilder.createQuery(Long.class); criteriaQuery.select(criteriaBuilder.count(criteriaQuery.from(this.tClass))); @@ -117,16 +118,16 @@ public class QueryableHibernateList> implements Queryabl this.query.where(array); TypedQuery typedQuery = this.manager.createQuery(this.query); - if(this.offset!=null)typedQuery.setFirstResult(this.offset); - if(this.length!=null)typedQuery.setMaxResults(this.length); - if(this.hint!=null&&this.hints.contains(hint)){ - List ids = typedQuery.getResultList().stream().map(item->item.getKeys()[0]).collect(Collectors.toList()); + if (this.offset != null) typedQuery.setFirstResult(this.offset); + if (this.length != null) typedQuery.setMaxResults(this.length); + if (this.hint != null && this.hints.contains(hint)) { + List ids = typedQuery.getResultList().stream().map(item -> item.getKeys()[0]).collect(Collectors.toList()); typedQuery = queryWithHint(ids); } return typedQuery.getResultList(); } - private TypedQuery queryWithHint(List ids){ + private TypedQuery queryWithHint(List ids) { CriteriaBuilder criteriaBuilder = this.manager.getCriteriaBuilder(); CriteriaQuery criteriaQuery = criteriaBuilder.createQuery(tClass); Root criteriaRoot = criteriaQuery.from(this.tClass); diff --git a/dmp-backend/src/main/java/eu/eudat/services/ApiContext.java b/dmp-backend/src/main/java/eu/eudat/services/ApiContext.java new file mode 100644 index 000000000..5849819a4 --- /dev/null +++ b/dmp-backend/src/main/java/eu/eudat/services/ApiContext.java @@ -0,0 +1,13 @@ +package eu.eudat.services; + +import eu.eudat.proxy.fetching.RemoteFetcher; +import org.springframework.context.ApplicationContext; + +/** + * Created by ikalyvas on 1/3/2018. + */ +public interface ApiContext { + DatabaseRepository getDatabaseRepository(); + ApplicationContext getApplicationContext(); + RemoteFetcher getRemoteFetcher(); +} diff --git a/dmp-backend/src/main/java/eu/eudat/services/ApiContextImpl.java b/dmp-backend/src/main/java/eu/eudat/services/ApiContextImpl.java new file mode 100644 index 000000000..45ac340fb --- /dev/null +++ b/dmp-backend/src/main/java/eu/eudat/services/ApiContextImpl.java @@ -0,0 +1,47 @@ +package eu.eudat.services; + +import eu.eudat.proxy.fetching.RemoteFetcher; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.stereotype.Service; + +/** + * Created by ikalyvas on 1/3/2018. + */ +@Service("apiContext") +public class ApiContextImpl implements ApiContext{ + + private DatabaseRepository databaseRepository; + private ApplicationContext applicationContext; + private RemoteFetcher remoteFetcher; + + @Autowired + public void setDatabaseRepository(DatabaseRepository databaseRepository) { + this.databaseRepository = databaseRepository; + } + + @Override + public DatabaseRepository getDatabaseRepository() { + return databaseRepository; + } + + @Override + public ApplicationContext getApplicationContext() { + return applicationContext; + } + + @Autowired + public void setApplicationContext(ApplicationContext applicationContext) { + this.applicationContext = applicationContext; + } + + @Override + public RemoteFetcher getRemoteFetcher() { + return remoteFetcher; + } + + @Autowired + public void setRemoteFetcher(RemoteFetcher remoteFetcher) { + this.remoteFetcher = remoteFetcher; + } +} diff --git a/dmp-backend/src/main/java/eu/eudat/services/DatabaseRepository.java b/dmp-backend/src/main/java/eu/eudat/services/DatabaseRepository.java new file mode 100644 index 000000000..b025f12ea --- /dev/null +++ b/dmp-backend/src/main/java/eu/eudat/services/DatabaseRepository.java @@ -0,0 +1,23 @@ +package eu.eudat.services; + +import eu.eudat.dao.entities.*; + +/** + * Created by ikalyvas on 1/4/2018. + */ +public interface DatabaseRepository { + DataRepositoryDao getDataRepositoryDao(); + DatasetDao getDatasetDao(); + DatasetProfileDao getDatasetProfileDao(); + DatasetRegistryDao getDatasetRegistryDao(); + DatasetServiceDao getDatasetServiceDao(); + DMPDao getDmpDao(); + DMPProfileDao getDMPProfileDao(); + DMPResearcherDao getDMPResearcherDao(); + OrganisationDao getOrganisationDao(); + ProjectDao getProjectDao(); + RegistryDao getRegistryDao(); + ResearcherDao getResearcherDao(); + ServiceDao getServiceDao(); + UserInfoDao getUserInfoDao(); +} diff --git a/dmp-backend/src/main/java/eu/eudat/services/DatabaseRepositoryImpl.java b/dmp-backend/src/main/java/eu/eudat/services/DatabaseRepositoryImpl.java new file mode 100644 index 000000000..425325bde --- /dev/null +++ b/dmp-backend/src/main/java/eu/eudat/services/DatabaseRepositoryImpl.java @@ -0,0 +1,177 @@ +package eu.eudat.services; + +import eu.eudat.dao.entities.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * Created by ikalyvas on 1/4/2018. + */ +@Service("databaseRepository") +public class DatabaseRepositoryImpl implements DatabaseRepository{ + + private DataRepositoryDao dataRepositoryDao; + private DatasetDao datasetDao; + private DatasetProfileDao datasetProfileDao; + private DatasetRegistryDao datasetRegistryDao; + private DatasetServiceDao datasetServiceDao; + private DMPDao dmpDao; + private DMPProfileDao dmpProfileDao; + private DMPResearcherDao dmpResearcherDao; + private OrganisationDao organisationDao; + private ProjectDao projectDao; + private RegistryDao registryDao; + private ResearcherDao researcherDao; + private ServiceDao serviceDao; + private UserInfoDao userInfoDao; + + @Autowired + private void setDataRepositoryDao(DataRepositoryDao dataRepositoryDao) { + this.dataRepositoryDao = dataRepositoryDao; + } + + @Autowired + private void setDatasetDao(DatasetDao datasetDao) { + this.datasetDao = datasetDao; + } + + @Autowired + private void setDatasetProfileDao(DatasetProfileDao datasetProfileDao) { + this.datasetProfileDao = datasetProfileDao; + } + + @Autowired + public void setDatasetRegistryDao(DatasetRegistryDao datasetRegistryDao) { + this.datasetRegistryDao = datasetRegistryDao; + } + + @Autowired + private void setDatasetServiceDao(DatasetServiceDao datasetServiceDao) { + this.datasetServiceDao = datasetServiceDao; + } + + @Autowired + private void setDmpDao(DMPDao dmpDao) { + this.dmpDao = dmpDao; + } + + @Autowired + private DMPProfileDao getDmpProfileDao() { + return dmpProfileDao; + } + + @Autowired + public void setDmpProfileDao(DMPProfileDao dmpProfileDao) { + this.dmpProfileDao = dmpProfileDao; + } + + @Autowired + private DMPResearcherDao getDmpResearcherDao() { + return dmpResearcherDao; + } + + @Autowired + private void setDmpResearcherDao(DMPResearcherDao dmpResearcherDao) { + this.dmpResearcherDao = dmpResearcherDao; + } + + @Autowired + private void setOrganisationDao(OrganisationDao organisationDao) { + this.organisationDao = organisationDao; + } + + @Autowired + private void setProjectDao(ProjectDao projectDao) { + this.projectDao = projectDao; + } + + @Autowired + private void setRegistryDao(RegistryDao registryDao) { + this.registryDao = registryDao; + } + + @Autowired + private void setResearcherDao(ResearcherDao researcherDao) { + this.researcherDao = researcherDao; + } + + @Autowired + public void setServiceDao(ServiceDao serviceDao) { + this.serviceDao = serviceDao; + } + + @Autowired + private void setUserInfoDao(UserInfoDao userInfoDao) { + this.userInfoDao = userInfoDao; + } + + @Override + public DataRepositoryDao getDataRepositoryDao() { + return dataRepositoryDao; + } + + @Override + public DatasetDao getDatasetDao() { + return datasetDao; + } + + @Override + public DatasetProfileDao getDatasetProfileDao() { + return datasetProfileDao; + } + + @Override + public DatasetRegistryDao getDatasetRegistryDao() { + return datasetRegistryDao; + } + + @Override + public DatasetServiceDao getDatasetServiceDao() { + return datasetServiceDao; + } + + @Override + public DMPDao getDmpDao() { + return dmpDao; + } + + @Override + public DMPProfileDao getDMPProfileDao() { + return dmpProfileDao; + } + + @Override + public DMPResearcherDao getDMPResearcherDao() { + return dmpResearcherDao; + } + + @Override + public OrganisationDao getOrganisationDao() { + return organisationDao; + } + + @Override + public ProjectDao getProjectDao() { + return projectDao; + } + + @Override + public RegistryDao getRegistryDao() { + return registryDao; + } + + @Override + public ResearcherDao getResearcherDao() { + return researcherDao; + } + + @Override + public ServiceDao getServiceDao() { + return serviceDao; + } + + @Override + public UserInfoDao getUserInfoDao() { + return userInfoDao; + } +} diff --git a/dmp-backend/src/main/java/eu/eudat/validators/ApiValidator.java b/dmp-backend/src/main/java/eu/eudat/validators/ApiValidator.java deleted file mode 100644 index d4e00f955..000000000 --- a/dmp-backend/src/main/java/eu/eudat/validators/ApiValidator.java +++ /dev/null @@ -1,9 +0,0 @@ -package eu.eudat.validators; - -import org.springframework.validation.Validator; - -/** - * Created by ikalyvas on 1/2/2018. - */ -public abstract class ApiValidator implements Validator { -}