class urn_perun_vo_attribute_def_def_aup extends VoAttributesModuleAbstract implements VoAttributesModuleImplApi {

	@Override
	public void checkAttributeSyntax(PerunSessionImpl perunSession, Vo vo, Attribute attribute) throws WrongAttributeValueException {

		String value = attribute.valueAsString();

		if (value == null) return;

		// we expect array or AUPs
		try {
			JSONArray array = new JSONArray(value);
			for (int i = 0; i < array.length(); i++) {
				JSONObject object = array.getJSONObject(i);
				if (!object.has("version")) throw new WrongAttributeValueException(attribute, "AUP is missing key version in JSON.");
				if (!object.has("date")) throw new WrongAttributeValueException(attribute, "AUP is missing key date in JSON.");
				if (!object.has("link")) throw new WrongAttributeValueException(attribute, "AUP is missing key link in JSON.");
				if (!object.has("text")) throw new WrongAttributeValueException(attribute, "AUP is missing key text in JSON.");
			}
		} catch (JSONException ex) {
			throw new WrongAttributeValueException(attribute, "AUP is not valid JSON.", ex);
		}

	}

}