no message
This commit is contained in:
parent
1d93d2d37e
commit
3f5a627d18
|
@ -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<Object> addDmp(@RequestBody DatasetProfile profile){
|
||||
public ResponseEntity<Object> addDmp(@Valid @RequestBody DatasetProfile profile){
|
||||
try{
|
||||
eu.eudat.entities.DatasetProfile modelDefinition = AdminManager.generateViewStyleDefinition(profile);
|
||||
datasetProfileDao.createOrUpdate(modelDefinition);
|
||||
|
|
|
@ -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));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<eu.eudat.entities.Project> addProject(@RequestBody eu.eudat.models.project.Project project, Principal principal) {
|
||||
public @ResponseBody ResponseItem<eu.eudat.entities.Project> addProject(@Valid @RequestBody eu.eudat.models.project.Project project, Principal principal) {
|
||||
try {
|
||||
ProjectManager.createOrUpdate(projectDao,userInfoDao,project,principal);
|
||||
return new ResponseItem<eu.eudat.entities.Project>().status(HttpStatus.OK);
|
||||
|
|
|
@ -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<Field>{
|
||||
private String id;
|
||||
|
@ -18,6 +22,8 @@ public class Field implements DatabaseViewStyleDefinition,XmlSerializable<Field>
|
|||
private DefaultValue defaultValue;
|
||||
private Visibility visible;
|
||||
private FieldData data;
|
||||
private List<eu.eudat.models.admin.components.datasetprofile.Field.ValidationType> validations;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
@ -58,6 +64,15 @@ public class Field implements DatabaseViewStyleDefinition,XmlSerializable<Field>
|
|||
public void setVisible(Visibility visible) {
|
||||
this.visible = visible;
|
||||
}
|
||||
|
||||
public List<eu.eudat.models.admin.components.datasetprofile.Field.ValidationType> getValidations() {
|
||||
return validations;
|
||||
}
|
||||
|
||||
public void setValidations(List<eu.eudat.models.admin.components.datasetprofile.Field.ValidationType> 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<Field>
|
|||
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<Field>
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package eu.eudat.models.admin.components.datasetprofile;
|
||||
|
||||
import eu.eudat.entities.xmlmodels.modeldefinition.*;
|
||||
import eu.eudat.models.project.Project;
|
||||
import eu.eudat.utilities.ModelDefinition;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
|
||||
|
@ -11,7 +12,29 @@ import eu.eudat.models.components.commons.Visibility;
|
|||
import eu.eudat.utilities.ViewStyleDefinition;
|
||||
import eu.eudat.utilities.builders.ModelBuilder;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Field implements ViewStyleDefinition<eu.eudat.entities.xmlmodels.datasetprofiledefinition.Field>,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<ValidationType> fromIntegers(List<Integer> 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<eu.eudat.entities.xmlmodels.da
|
|||
private DefaultValue defaultValue;
|
||||
private Object data;
|
||||
private Visibility visible;
|
||||
|
||||
private List<ValidationType> validations;
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
@ -84,6 +107,14 @@ public class Field implements ViewStyleDefinition<eu.eudat.entities.xmlmodels.da
|
|||
this.visible = visible;
|
||||
}
|
||||
|
||||
public List<Integer> getValidations() {
|
||||
return this.validations.stream().map(item->(int)item.getValue()).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public void setValidations(List<Integer> 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<eu.eudat.entities.xmlmodels.da
|
|||
field.setData(new ModelBuilder().toFieldData(data, this.viewStyle.getRenderStyle()));
|
||||
field.setVisible(this.visible);
|
||||
field.setDefaultValue(this.defaultValue);
|
||||
field.setValidations(this.validations);
|
||||
return field;
|
||||
}
|
||||
@Override
|
||||
|
@ -104,6 +136,7 @@ public class Field implements ViewStyleDefinition<eu.eudat.entities.xmlmodels.da
|
|||
this.data = item.getData();
|
||||
this.visible = item.getVisible();
|
||||
this.defaultValue = item.getDefaultValue();
|
||||
this.validations = item.getValidations();
|
||||
}
|
||||
@Override
|
||||
public int compareTo(Object o) {
|
||||
|
|
|
@ -8,22 +8,12 @@ import java.util.Map;
|
|||
/**
|
||||
* Created by ikalyvas on 12/22/2017.
|
||||
*/
|
||||
public class ValidationErrorContext {
|
||||
private Map<String,String> error = new HashMap<>();
|
||||
|
||||
public Map<String, String> getError() {
|
||||
return error;
|
||||
}
|
||||
|
||||
public void setError(Map<String, String> error) {
|
||||
this.error = error;
|
||||
}
|
||||
public class ValidationErrorContext extends HashMap<String,String>{
|
||||
|
||||
public ValidationErrorContext() {
|
||||
|
||||
}
|
||||
|
||||
public void addFieldError(String path, String message) {
|
||||
error.put(path,message);
|
||||
this.put(path,message);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ public class Field implements Comparable,PropertiesModelBuilder,ViewStyleDefinit
|
|||
private Multiplicity multiplicity;
|
||||
private Object data;
|
||||
private List<Field> multiplicityItems;
|
||||
private List<eu.eudat.models.admin.components.datasetprofile.Field.ValidationType> validations;
|
||||
private Visibility visible;
|
||||
public List<Field> getMultiplicityItems() {
|
||||
return multiplicityItems;
|
||||
|
@ -104,6 +105,14 @@ public class Field implements Comparable,PropertiesModelBuilder,ViewStyleDefinit
|
|||
this.visible = visible;
|
||||
}
|
||||
|
||||
public List<eu.eudat.models.admin.components.datasetprofile.Field.ValidationType> getValidations() {
|
||||
return validations;
|
||||
}
|
||||
|
||||
public void setValidations(List<eu.eudat.models.admin.components.datasetprofile.Field.ValidationType> validations) {
|
||||
this.validations = validations;
|
||||
}
|
||||
|
||||
public Field cloneForMultiplicity(String key, Map<String, Object> 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<String, Object> properties) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -3,3 +3,5 @@ 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
|
||||
datasetprofile.label.null = Dataset Profile Label cannot be null
|
||||
project.startDate.overlapping = Period Start cannot overlap Period End
|
|
@ -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<DatasetWizardModel>().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<DatasetWizardModel>().fromJSONObject(result,DatasetWizardModel);
|
||||
this.datasetWizardModel = JsonSerializer.fromJSONObject(result,DatasetWizardModel);
|
||||
}
|
||||
)
|
||||
this.onCallbackSuccess()
|
||||
|
|
|
@ -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<DataManagementPlanModel>().fromJSONObject(data, DataManagementPlanModel);
|
||||
this.dataManagementPlan = JsonSerializer.fromJSONObject(data, DataManagementPlanModel);
|
||||
this.formGroup = this.dataManagementPlan.buildForm();
|
||||
});
|
||||
} else {
|
||||
|
|
|
@ -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<Rule>().fromJSONArray(this.datasetProfileDefinitionModel.rules, Rule);
|
||||
let rules: Rule[] = JsonSerializer.fromJSONArray(this.datasetProfileDefinitionModel.rules, Rule);
|
||||
this.visibilityRulesService.buildVisibilityRules(rules)
|
||||
this.progressbar = true;
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ export class HomepageComponent implements OnInit {
|
|||
|
||||
this.dashBoardService.getStatistics().subscribe(results => {
|
||||
//let data = results['payload'];
|
||||
this.dashboardStatisticsData = new JsonSerializer<DashboardStatisticsModel>().fromJSONObject(results, DashboardStatisticsModel);
|
||||
this.dashboardStatisticsData = JsonSerializer.fromJSONObject(results, DashboardStatisticsModel);
|
||||
})
|
||||
|
||||
}
|
||||
|
|
|
@ -14,14 +14,14 @@ export class CompositeField extends BaseModel implements Serializable<CompositeF
|
|||
|
||||
fromJSONObject(item: any): CompositeField {
|
||||
|
||||
this.fields = new JsonSerializer<Field>().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<Multiplicity>().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<CompositeField>().fromJSONArray(item.multiplicityItems, CompositeField);
|
||||
if(item.multiplicityItems)this.multiplicityItems = JsonSerializer.fromJSONArray(item.multiplicityItems, CompositeField);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,8 +11,8 @@ export class DatasetProfileDefinitionModel extends BaseModel implements Serializ
|
|||
public sections:Array<Section>
|
||||
fromJSONObject(item:any):DatasetProfileDefinitionModel{
|
||||
this.status = item.status;
|
||||
this.sections = new JsonSerializer<Section>().fromJSONArray(item.sections,Section);
|
||||
this.rules = new JsonSerializer<Rule>().fromJSONArray(item.rules,Rule);
|
||||
this.sections = JsonSerializer.fromJSONArray(item.sections,Section);
|
||||
this.rules = JsonSerializer.fromJSONArray(item.rules,Rule);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,12 +29,12 @@ export class Field extends BaseModel implements Serializable<Field>, FormGenerat
|
|||
this.viewStyle = item.viewStyle;
|
||||
this.defaultVisibility = item.defaultVisibility;
|
||||
this.page = item.page;
|
||||
this.multiplicity = new JsonSerializer<Multiplicity>().fromJSONObject(item.multiplicity, Multiplicity);
|
||||
this.defaultValue = new JsonSerializer<DefaultValue>().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<Field>().fromJSONArray(item.multiplicityItems, Field);
|
||||
if(item.multiplicityItems)this.multiplicityItems = JsonSerializer.fromJSONArray(item.multiplicityItems, Field);
|
||||
this.data = item.data;
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ export class FieldGroup extends BaseModel implements Serializable<FieldGroup>, F
|
|||
this.extendedDescription = item.extendedDescription;
|
||||
this.defaultVisibility = item.defaultVisibility;
|
||||
this.page = item.page;
|
||||
this.compositeFields = new JsonSerializer<CompositeField>().fromJSONArray(item.compositeFields, CompositeField);
|
||||
this.compositeFields = JsonSerializer.fromJSONArray(item.compositeFields, CompositeField);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,14 +17,14 @@ export class Section extends BaseModel implements Serializable<Section>, FormGen
|
|||
public compositeFields: Array<CompositeField> = new Array<CompositeField>();
|
||||
|
||||
fromJSONObject(item: any): Section {
|
||||
this.sections = new JsonSerializer<Section>().fromJSONArray(item.sections, Section);
|
||||
this.sections = JsonSerializer.fromJSONArray(item.sections, Section);
|
||||
//this.fieldGroups = new JsonSerializer<FieldGroup>().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<CompositeField>().fromJSONArray(item.fieldSets, CompositeField);
|
||||
this.compositeFields = JsonSerializer.fromJSONArray(item.fieldSets, CompositeField);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,10 +32,10 @@ export class DataManagementPlanModel implements Serializable<DataManagementPlanM
|
|||
this.version = item.version;
|
||||
this.status = item.status;
|
||||
this.description = item.description;
|
||||
this.project = new JsonSerializer<ProjectModel>().fromJSONObject(item.project, ProjectModel);
|
||||
this.organisations = new JsonSerializer<OrganisationModel>().fromJSONArray(item.organisations, OrganisationModel);
|
||||
this.researchers = new JsonSerializer<ResearcherModel>().fromJSONArray(item.researchers, ResearcherModel);
|
||||
this.profiles = new JsonSerializer<ProfileModel>().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;
|
||||
}
|
||||
|
|
|
@ -29,9 +29,9 @@ export class DatasetModel implements Serializable<DatasetModel> {
|
|||
this.uri = item.uri;
|
||||
this.status = item.status;
|
||||
this.description = item.description;
|
||||
this.services = new JsonSerializer<ServiceModel>().fromJSONArray(item.services, ServiceModel);
|
||||
this.registries = new JsonSerializer<RegisterModel>().fromJSONArray(item.registries, RegisterModel);
|
||||
this.dataRepositories = new JsonSerializer<DataRepositoryModel>().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;
|
||||
}
|
||||
|
|
|
@ -33,12 +33,12 @@ export class DatasetWizardModel implements Serializable<DatasetWizardModel> {
|
|||
this.uri = item.uri;
|
||||
this.status = item.status;
|
||||
this.description = item.description;
|
||||
this.services = new JsonSerializer<ServiceModel>().fromJSONArray(item.services, ServiceModel);
|
||||
this.registries = new JsonSerializer<RegisterModel>().fromJSONArray(item.registries, RegisterModel);
|
||||
this.dataRepositories = new JsonSerializer<DataRepositoryModel>().fromJSONArray(item.dataRepositories, DataRepositoryModel);
|
||||
this.dmp = new JsonSerializer<DataManagementPlanModel>().fromJSONObject(item.dmp, DataManagementPlanModel);
|
||||
this.profile = new JsonSerializer<DatasetWizardModel>().fromJSONObject(item.profile, DatasetWizardModel);
|
||||
this.datasetProfileDefinition = new JsonSerializer<DatasetProfileDefinitionModel>().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;
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
class="table-input" [matDatepicker]="startDate" formControlName="startDate" required>
|
||||
<mat-datepicker-toggle matSuffix [for]="startDate"></mat-datepicker-toggle>
|
||||
<mat-datepicker #startDate></mat-datepicker>
|
||||
<mat-error *ngIf="formGroup.get('startDate').errors?.backendError">{{baseErrorModel.startDate}}</mat-error>
|
||||
<mat-error *ngIf="formGroup.get('startDate').errors?.backendError">{{this.project.errorModel.startDate}}</mat-error>
|
||||
<mat-error *ngIf="formGroup.get('startDate').errors?.required">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
|
||||
</mat-form-field>
|
||||
</td>
|
||||
|
|
|
@ -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<ProjectModel>().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);
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<Principal>().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<Principal>().fromJSONObject(r.json(), Principal));
|
||||
const princ = this.current(JsonSerializer.fromJSONObject(r.json(), Principal));
|
||||
//this.loginContextSubject.next(true);
|
||||
return princ;
|
||||
})
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Serializable } from '../models/interfaces/Serializable';
|
||||
export class JsonSerializer<T extends Serializable<T>>{
|
||||
export class JsonSerializer{
|
||||
|
||||
public fromJSONArray(items: any[], type: { new(): T; }): T[] {
|
||||
public static fromJSONArray<T extends Serializable<T>>(items: any[], type: { new(): T; }): T[] {
|
||||
if(!items)return new Array<T>();
|
||||
const objectList: T[] = new Array<T>();
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
|
@ -10,7 +10,7 @@ export class JsonSerializer<T extends Serializable<T>>{
|
|||
return objectList;
|
||||
}
|
||||
|
||||
public fromJSONObject(item: any, type: { new(): T; }): T {
|
||||
public static fromJSONObject<T extends Serializable<T>>(item: any, type: { new(): T; }): T {
|
||||
if(!item)return null;
|
||||
return new type().fromJSONObject(item);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue