class urn_perun_group_attribute_def_def_groupStructureSynchronizationEnabled extends GroupAttributesModuleAbstract implements GroupAttributesModuleImplApi {

	@Override
	public void checkAttributeSemantics(PerunSessionImpl perunSession, Group group, Attribute attribute) throws WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
		//Null value is ok, means no settings for group
		if(attribute.getValue() == null) return;

		if (attribute.valueAsBoolean()) {

			if (perunSession.getPerunBl().getGroupsManagerBl().isGroupSynchronizedFromExternallSource(perunSession, group)) {
				throw new InternalErrorException("Synchronization is already enabled for one of the parent groups.");
			}

			try {
				Attribute attrSynchronizeEnabled = perunSession.getPerunBl().getAttributesManagerBl().getAttribute(perunSession, group, GroupsManager.GROUPSYNCHROENABLED_ATTRNAME);
				if (Objects.equals("true", attrSynchronizeEnabled.getValue())) {
					throw new WrongReferenceAttributeValueException(attribute, attrSynchronizeEnabled);
				}

				Attribute requiredAttribute = perunSession.getPerunBl().getAttributesManagerBl().getAttribute(perunSession, group, GroupsManager.GROUPSQUERY_ATTRNAME);
				if (requiredAttribute.getValue() == null) {
					throw new WrongReferenceAttributeValueException(attribute, requiredAttribute, requiredAttribute.toString() + " must be set in order to enable synchronization.");
				}

				requiredAttribute = perunSession.getPerunBl().getAttributesManagerBl().getAttribute(perunSession, group, GroupsManager.GROUPMEMBERSQUERY_ATTRNAME);
				if (requiredAttribute.getValue() == null) {
					throw new WrongReferenceAttributeValueException(attribute, requiredAttribute, requiredAttribute.toString() + " must be set in order to enable synchronization.");
				}

				requiredAttribute = perunSession.getPerunBl().getAttributesManagerBl().getAttribute(perunSession, group, GroupsManager.GROUPEXTSOURCE_ATTRNAME);
				if (requiredAttribute.getValue() == null) {
					throw new WrongReferenceAttributeValueException(attribute, requiredAttribute, requiredAttribute.toString() + " must be set in order to enable synchronization.");
				}
			} catch (AttributeNotExistsException e) {
				throw new ConsistencyErrorException(e);
			}
		}
	}

}