summaryrefslogtreecommitdiffstats
path: root/dcaedt_be/src/main/java/org/onap/sdc/dcae/rule/editor/validators/CopyActionValidator.java
blob: 74102a6800327777627ca761a5af79650b99628f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package org.onap.sdc.dcae.rule.editor.validators;

import org.onap.sdc.dcae.composition.restmodels.ruleeditor.BaseCopyAction;
import org.onap.sdc.dcae.errormng.ActionStatus;
import org.onap.sdc.dcae.errormng.ErrConfMgr;
import org.onap.sdc.dcae.errormng.ResponseFormat;
import org.onap.sdc.dcae.rule.editor.utils.ValidationUtils;

import java.util.List;

public class CopyActionValidator<A extends BaseCopyAction> implements IRuleElementValidator<A> {

	private static CopyActionValidator copyActionValidator = new CopyActionValidator();

	public static CopyActionValidator getInstance() {
		return copyActionValidator;
	}

	CopyActionValidator(){}

	public boolean validate(A action, List<ResponseFormat> errors) {

		// validate from is populated
		boolean valid = validateFromValue(action, errors);
		//validate target is populated
		if (!ValidationUtils.validateTargetField(action.getTarget())) {
			valid = false;
			errors.add(ErrConfMgr.INSTANCE.getResponseFormat(ActionStatus.MISSING_ACTION_FIELD, null, "target", action.getActionType(), action.getTarget()));
		}
		return valid;
	}

	protected boolean validateFromValue(A action, List<ResponseFormat> errors) {
		if(!ValidationUtils.validateNotEmpty(action.getFromValue())) {
			errors.add(ErrConfMgr.INSTANCE.getResponseFormat(ActionStatus.MISSING_ACTION_FIELD, null, "from", action.getActionType(), action.getTarget()));
			return false;
		}
		return true;
	}
}