All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.anotheria.anosite.gen.anoaccessconfiguration.service.AnoAccessConfigurationServiceImpl Maven / Gradle / Ivy

There is a newer version: 4.1.2
Show newest version
/**
 ********************************************************************************
 *** AnoAccessConfigurationServiceImpl.java                                   ***
 *** The implementation of the IAnoAccessConfigurationService.                ***
 *** generated by AnoSiteGenerator (ASG), Version: 3.2.2                      ***
 *** Copyright (C) 2005 - 2023 Anotheria.net, www.anotheria.net               ***
 *** All Rights Reserved.                                                     ***
 ********************************************************************************
 *** Don't edit this code, if you aren't sure                                 ***
 *** that you do exactly know what you are doing!                             ***
 *** It's better to invest time in the generator, as into the generated code. ***
 ********************************************************************************
 */

package net.anotheria.anosite.gen.anoaccessconfiguration.service;

import java.nio.charset.Charset;
import java.util.List;
import java.util.ArrayList;
import java.util.Set;
import net.anotheria.anodoc.data.Module;
import net.anotheria.anodoc.data.Property;
import net.anotheria.anodoc.data.NoSuchPropertyException;
import net.anotheria.util.sorter.SortType;
import net.anotheria.util.sorter.StaticQuickSorter;
import net.anotheria.util.slicer.Segment;
import net.anotheria.util.slicer.Slicer;
import net.anotheria.anosite.gen.anoaccessconfiguration.data.ModuleAnoAccessConfiguration;
import net.anotheria.anosite.gen.shared.service.BasicCMSService;
import net.anotheria.anodoc.query2.DocumentQuery;
import net.anotheria.anodoc.query2.QueryResult;
import net.anotheria.anodoc.query2.QueryResultEntry;
import net.anotheria.anodoc.query2.QueryProperty;
import net.anotheria.util.StringUtils;
import net.anotheria.util.xml.XMLNode;
import net.anotheria.util.xml.XMLAttribute;
import net.anotheria.asg.util.listener.IModuleListener;
import org.codehaus.jettison.json.JSONObject;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import com.fasterxml.jackson.core.JsonProcessingException;
import java.io.IOException;
import net.anotheria.anodoc.util.mapper.ObjectMapperUtil;
import net.anotheria.anosite.gen.shared.util.DocumentName;
import net.anotheria.anosite.gen.anoaccessconfiguration.data.AccessOperation;
import net.anotheria.anosite.gen.anoaccessconfiguration.data.AccessOperationXMLHelper;
import net.anotheria.anosite.gen.anoaccessconfiguration.data.AccessOperationDocument;
import net.anotheria.anosite.gen.anoaccessconfiguration.data.Role;
import net.anotheria.anosite.gen.anoaccessconfiguration.data.RoleXMLHelper;
import net.anotheria.anosite.gen.anoaccessconfiguration.data.RoleDocument;
import net.anotheria.anosite.gen.anoaccessconfiguration.service.AnoAccessConfigurationServiceException;
import net.anotheria.anosite.gen.anoaccessconfiguration.data.Permission;
import net.anotheria.anosite.gen.anoaccessconfiguration.data.PermissionXMLHelper;
import net.anotheria.anosite.gen.anoaccessconfiguration.data.PermissionDocument;
import net.anotheria.anosite.gen.anoaccessconfiguration.data.Constraint;
import net.anotheria.anosite.gen.anoaccessconfiguration.data.ConstraintXMLHelper;
import net.anotheria.anosite.gen.anoaccessconfiguration.data.ConstraintDocument;
import net.anotheria.anosite.gen.anoaccessconfiguration.data.ContextInitializer;
import net.anotheria.anosite.gen.anoaccessconfiguration.data.ContextInitializerXMLHelper;
import net.anotheria.anosite.gen.anoaccessconfiguration.data.ContextInitializerDocument;

public class AnoAccessConfigurationServiceImpl extends BasicCMSService implements IAnoAccessConfigurationService, IModuleListener{

	// Generated by: class net.anotheria.asg.generator.model.docs.CMSBasedServiceGenerator.generateImplementation

	private static AnoAccessConfigurationServiceImpl instance;

	private AnoAccessConfigurationServiceImpl(){
		addServiceListener(new net.anotheria.anosite.cms.listener.CRUDLogListener());
		addServiceListener(new net.anotheria.anosite.cms.listener.AutoTransferAnoAccessConfigurationListener());
		addModuleListener(ModuleAnoAccessConfiguration.MODULE_ID, this);
	}

	static final AnoAccessConfigurationServiceImpl getInstance(){
		if (instance==null){
			instance = new AnoAccessConfigurationServiceImpl();
		}
		return instance;
	}

	private ModuleAnoAccessConfiguration _getModuleAnoAccessConfiguration(){
		return (ModuleAnoAccessConfiguration) getModule(ModuleAnoAccessConfiguration.MODULE_ID);
	}

	@Override
	public void moduleLoaded(Module module){
		firePersistenceChangedEvent();
	}

	@Override
	public List getAccessOperations(){
		List accessoperations = new ArrayList<>();
		accessoperations.addAll(_getModuleAnoAccessConfiguration().getAccessOperations());
		return accessoperations;
	}

	@Override
	public List getAccessOperations(SortType sortType){
		return StaticQuickSorter.sort(getAccessOperations(), sortType);
	}

	/**
	 * Returns the AccessOperation objects with the specified ids.
	 */
	public List getAccessOperations(List ids){
		if (ids==null || ids.size()==0)
			return new ArrayList<>(0);
		List all = getAccessOperations();
		List ret = new ArrayList<>();
		for (AccessOperation accessoperation : all){
			if(ids.contains(accessoperation.getId())){
				ret.add(accessoperation);
			}
		}
		return ret;
	}

	/**
	 * Returns the AccessOperation objects with the specified ids, sorted by given sorttype.
	 */
	public List getAccessOperations(List ids, SortType sortType){
		return StaticQuickSorter.sort(getAccessOperations(ids), sortType);
	}

	@Override
	public void deleteAccessOperation(AccessOperation accessoperation){
		deleteAccessOperation(accessoperation.getId());
		if (hasServiceListeners()){
			fireObjectDeletedEvent(accessoperation);
		}
	}

	@Override
	public void deleteAccessOperation(String id){
		ModuleAnoAccessConfiguration module = _getModuleAnoAccessConfiguration();
		AccessOperation varValue = hasServiceListeners()?module.getAccessOperation(id):null;
		module.deleteAccessOperation(id);
		updateModule(module);
		if(varValue!=null){
			fireObjectDeletedEvent(varValue);
		}
	}

	@Override
	public void deleteAccessOperations(List list){
		ModuleAnoAccessConfiguration module = _getModuleAnoAccessConfiguration();
		for (AccessOperation accessoperation : list){
			module.deleteAccessOperation(accessoperation.getId());
		}
		updateModule(module);
		if (hasServiceListeners()){
			for (int t=0; t importAccessOperations(List list){
		ModuleAnoAccessConfiguration module = _getModuleAnoAccessConfiguration();
		List ret = new ArrayList<>();
		for (AccessOperation accessoperation : list){
			AccessOperation imported = module.importAccessOperation((AccessOperationDocument)accessoperation);
			ret.add(imported);
		}
		updateModule(module);
		if (hasServiceListeners()){
			for (AccessOperation accessoperation : ret)
				fireObjectImportedEvent(accessoperation);
		}
		return ret;
	}

	@Override
	public AccessOperation createAccessOperation(AccessOperation accessoperation){
		ModuleAnoAccessConfiguration module = _getModuleAnoAccessConfiguration();
		module.createAccessOperation((AccessOperationDocument)accessoperation);
		updateModule(module);
		fireObjectCreatedEvent(accessoperation);
		return accessoperation;
	}

	@Override
	/**
	 * Creates multiple new AccessOperation objects.
	 * Returns the created versions.
	 */
	public List createAccessOperations(List list){
		ModuleAnoAccessConfiguration module = _getModuleAnoAccessConfiguration();
		List ret = new ArrayList<>();
		for (AccessOperation accessoperation : list){
			AccessOperation created = module.createAccessOperation((AccessOperationDocument)accessoperation);
			ret.add(created);
		}
		updateModule(module);
		if (hasServiceListeners()){
			for (AccessOperation accessoperation : ret)
				fireObjectCreatedEvent(accessoperation);
		}
		return ret;
	}

	@Override
	public AccessOperation updateAccessOperation(AccessOperation accessoperation){
		AccessOperation oldVersion = null;
		ModuleAnoAccessConfiguration module = _getModuleAnoAccessConfiguration();
		if (hasServiceListeners())
			oldVersion = module.getAccessOperation(accessoperation.getId());
		module.updateAccessOperation((AccessOperationDocument)accessoperation);
		updateModule(module);
		if (oldVersion != null){
			fireObjectUpdatedEvent(oldVersion, accessoperation);
		}
		return accessoperation;
	}

	@Override
	public List updateAccessOperations(List list){
		List oldList = null;
		if (hasServiceListeners())
			oldList = new ArrayList<>(list.size());
		ModuleAnoAccessConfiguration module = _getModuleAnoAccessConfiguration();
		for (AccessOperation accessoperation : list){
			if (oldList!=null)
				oldList.add(module.getAccessOperation(accessoperation.getId()));
			module.updateAccessOperation((AccessOperationDocument)accessoperation);
		}
		updateModule(module);
		if (oldList!=null){
			for (int t=0; t getAccessOperationsByProperty(String propertyName, Object value){
		List allAccessOperations = getAccessOperations();
		List ret = new ArrayList<>();
		for (int i=0; i getAccessOperationsByProperty(String propertyName, Object value, SortType sortType){
		return StaticQuickSorter.sort(getAccessOperationsByProperty(propertyName, value), sortType);
	}
	/**
	 * Executes a query on AccessOperations
	 */
	public QueryResult executeQueryOnAccessOperations(DocumentQuery query){
		List allAccessOperations = getAccessOperations();
		QueryResult result = new QueryResult();
		for (int i=0; i partialResult = query.match(allAccessOperations.get(i));
			result.add(partialResult);
		}
		return result;
	}

	/**
	 * Returns all AccessOperation objects, where property matches.
	 */
	public List getAccessOperationsByProperty(QueryProperty... property){
		//first the slow version, the fast version is a todo.
		List ret = new ArrayList<>();
		List src = getAccessOperations();
		for ( AccessOperation accessoperation : src){
			boolean mayPass = true;
			for (QueryProperty qp : property){
				mayPass = mayPass && qp.doesMatch(accessoperation.getPropertyValue(qp.getName()));
			}
			if (mayPass)
				ret.add(accessoperation);
		}
		return ret;
	}

	/**
	 * Returns all AccessOperation objects, where property matches, sorted
	 */
	public List getAccessOperationsByProperty(SortType sortType, QueryProperty... property){
		return StaticQuickSorter.sort(getAccessOperationsByProperty(property), sortType);
	}

	/**
	 * Returns AccessOperation objects count.
	 */
	public int getAccessOperationsCount() {
		return _getModuleAnoAccessConfiguration().getAccessOperations().size();
	}

	/**
	 * Returns AccessOperation objects segment.
	 */
	public List getAccessOperations(Segment aSegment) {
		return Slicer.slice(aSegment, getAccessOperations()).getSliceData();
	}

	/**
	 * Returns AccessOperation objects segment, where property matched.
	 */
	public List getAccessOperationsByProperty(Segment aSegment, QueryProperty... property) {
		int pLimit = aSegment.getElementsPerSlice();
		int pOffset = aSegment.getSliceNumber() * aSegment.getElementsPerSlice() - aSegment.getElementsPerSlice();
		List ret = new ArrayList<>();
		List src = getAccessOperations();
		for (AccessOperation accessoperation : src) {
			boolean mayPass = true;
			for (QueryProperty qp : property) {
				mayPass = mayPass && qp.doesMatch(accessoperation.getPropertyValue(qp.getName()));
			}
			if (mayPass)
				ret.add(accessoperation);
			if (ret.size() > pOffset + pLimit)
				break;
		}
		return Slicer.slice(aSegment, ret).getSliceData();
	}

	/**
	 * Returns AccessOperation objects segment, where property matched, sorted.
	 */
	public List getAccessOperationsByProperty(Segment aSegment, SortType aSortType, QueryProperty... aProperty){
		return StaticQuickSorter.sort(getAccessOperationsByProperty(aSegment, aProperty), aSortType);
	}

	@Override
	public void fetchAccessOperation(final String id, Set addedDocuments, JSONArray data) throws AnoAccessConfigurationServiceException {
		if (id.isEmpty() || addedDocuments.contains("AccessOperation" + id))
			return;

		try {
			final AccessOperationDocument accessoperation = _getModuleAnoAccessConfiguration().getAccessOperation(id);
			addedDocuments.add("AccessOperation" + id);



			JSONObject dataObject = new JSONObject();
			String jsonObject = ObjectMapperUtil.getMapperInstance().writeValueAsString(accessoperation);
			dataObject.put("object", jsonObject);
			dataObject.put("service", "AnoAccessConfiguration");
			dataObject.put("document", "AnoAccessConfiguration_AccessOperation");

			data.put(dataObject);

		}catch(IOException e){
			throw new AnoAccessConfigurationServiceException ("Problem with fetching data for this AccessOperation instance object:" + e.getMessage());
		}catch(JSONException e){
			throw new AnoAccessConfigurationServiceException ("Problem with fetching data for this AccessOperation instance in json :" + e.getMessage());
		}
	}

	private void saveTransferredAccessOperation(final JSONObject data) throws AnoAccessConfigurationServiceException {
		try {
			String objectData = data.getString("object");
			AccessOperation accessoperation = ObjectMapperUtil.getMapperInstance().readValue(objectData.getBytes(Charset.forName("UTF-8")), AccessOperationDocument.class);

			try {
				updateAccessOperation(accessoperation);
			}catch(Exception e){
				importAccessOperation(accessoperation);
			}
		}catch(JSONException e){
			throw new AnoAccessConfigurationServiceException("Problem with getting data from json AccessOperation instance :" + e.getMessage());
		}catch(IOException e){
			throw new AnoAccessConfigurationServiceException("Problem with parsing data for this AccessOperation instance :" + e.getMessage());
		}
	}

	@Override
	public List getRoles(){
		List roles = new ArrayList<>();
		roles.addAll(_getModuleAnoAccessConfiguration().getRoles());
		return roles;
	}

	@Override
	public List getRoles(SortType sortType){
		return StaticQuickSorter.sort(getRoles(), sortType);
	}

	/**
	 * Returns the Role objects with the specified ids.
	 */
	public List getRoles(List ids){
		if (ids==null || ids.size()==0)
			return new ArrayList<>(0);
		List all = getRoles();
		List ret = new ArrayList<>();
		for (Role role : all){
			if(ids.contains(role.getId())){
				ret.add(role);
			}
		}
		return ret;
	}

	/**
	 * Returns the Role objects with the specified ids, sorted by given sorttype.
	 */
	public List getRoles(List ids, SortType sortType){
		return StaticQuickSorter.sort(getRoles(ids), sortType);
	}

	@Override
	public void deleteRole(Role role){
		deleteRole(role.getId());
		if (hasServiceListeners()){
			fireObjectDeletedEvent(role);
		}
	}

	@Override
	public void deleteRole(String id){
		ModuleAnoAccessConfiguration module = _getModuleAnoAccessConfiguration();
		Role varValue = hasServiceListeners()?module.getRole(id):null;
		module.deleteRole(id);
		updateModule(module);
		if(varValue!=null){
			fireObjectDeletedEvent(varValue);
		}
	}

	@Override
	public void deleteRoles(List list){
		ModuleAnoAccessConfiguration module = _getModuleAnoAccessConfiguration();
		for (Role role : list){
			module.deleteRole(role.getId());
		}
		updateModule(module);
		if (hasServiceListeners()){
			for (int t=0; t importRoles(List list){
		ModuleAnoAccessConfiguration module = _getModuleAnoAccessConfiguration();
		List ret = new ArrayList<>();
		for (Role role : list){
			Role imported = module.importRole((RoleDocument)role);
			ret.add(imported);
		}
		updateModule(module);
		if (hasServiceListeners()){
			for (Role role : ret)
				fireObjectImportedEvent(role);
		}
		return ret;
	}

	@Override
	public Role createRole(Role role){
		ModuleAnoAccessConfiguration module = _getModuleAnoAccessConfiguration();
		module.createRole((RoleDocument)role);
		updateModule(module);
		fireObjectCreatedEvent(role);
		return role;
	}

	@Override
	/**
	 * Creates multiple new Role objects.
	 * Returns the created versions.
	 */
	public List createRoles(List list){
		ModuleAnoAccessConfiguration module = _getModuleAnoAccessConfiguration();
		List ret = new ArrayList<>();
		for (Role role : list){
			Role created = module.createRole((RoleDocument)role);
			ret.add(created);
		}
		updateModule(module);
		if (hasServiceListeners()){
			for (Role role : ret)
				fireObjectCreatedEvent(role);
		}
		return ret;
	}

	@Override
	public Role updateRole(Role role){
		Role oldVersion = null;
		ModuleAnoAccessConfiguration module = _getModuleAnoAccessConfiguration();
		if (hasServiceListeners())
			oldVersion = module.getRole(role.getId());
		module.updateRole((RoleDocument)role);
		updateModule(module);
		if (oldVersion != null){
			fireObjectUpdatedEvent(oldVersion, role);
		}
		return role;
	}

	@Override
	public List updateRoles(List list){
		List oldList = null;
		if (hasServiceListeners())
			oldList = new ArrayList<>(list.size());
		ModuleAnoAccessConfiguration module = _getModuleAnoAccessConfiguration();
		for (Role role : list){
			if (oldList!=null)
				oldList.add(module.getRole(role.getId()));
			module.updateRole((RoleDocument)role);
		}
		updateModule(module);
		if (oldList!=null){
			for (int t=0; t getRolesByProperty(String propertyName, Object value){
		List allRoles = getRoles();
		List ret = new ArrayList<>();
		for (int i=0; i getRolesByProperty(String propertyName, Object value, SortType sortType){
		return StaticQuickSorter.sort(getRolesByProperty(propertyName, value), sortType);
	}
	/**
	 * Executes a query on Roles
	 */
	public QueryResult executeQueryOnRoles(DocumentQuery query){
		List allRoles = getRoles();
		QueryResult result = new QueryResult();
		for (int i=0; i partialResult = query.match(allRoles.get(i));
			result.add(partialResult);
		}
		return result;
	}

	/**
	 * Returns all Role objects, where property matches.
	 */
	public List getRolesByProperty(QueryProperty... property){
		//first the slow version, the fast version is a todo.
		List ret = new ArrayList<>();
		List src = getRoles();
		for ( Role role : src){
			boolean mayPass = true;
			for (QueryProperty qp : property){
				mayPass = mayPass && qp.doesMatch(role.getPropertyValue(qp.getName()));
			}
			if (mayPass)
				ret.add(role);
		}
		return ret;
	}

	/**
	 * Returns all Role objects, where property matches, sorted
	 */
	public List getRolesByProperty(SortType sortType, QueryProperty... property){
		return StaticQuickSorter.sort(getRolesByProperty(property), sortType);
	}

	/**
	 * Returns Role objects count.
	 */
	public int getRolesCount() {
		return _getModuleAnoAccessConfiguration().getRoles().size();
	}

	/**
	 * Returns Role objects segment.
	 */
	public List getRoles(Segment aSegment) {
		return Slicer.slice(aSegment, getRoles()).getSliceData();
	}

	/**
	 * Returns Role objects segment, where property matched.
	 */
	public List getRolesByProperty(Segment aSegment, QueryProperty... property) {
		int pLimit = aSegment.getElementsPerSlice();
		int pOffset = aSegment.getSliceNumber() * aSegment.getElementsPerSlice() - aSegment.getElementsPerSlice();
		List ret = new ArrayList<>();
		List src = getRoles();
		for (Role role : src) {
			boolean mayPass = true;
			for (QueryProperty qp : property) {
				mayPass = mayPass && qp.doesMatch(role.getPropertyValue(qp.getName()));
			}
			if (mayPass)
				ret.add(role);
			if (ret.size() > pOffset + pLimit)
				break;
		}
		return Slicer.slice(aSegment, ret).getSliceData();
	}

	/**
	 * Returns Role objects segment, where property matched, sorted.
	 */
	public List getRolesByProperty(Segment aSegment, SortType aSortType, QueryProperty... aProperty){
		return StaticQuickSorter.sort(getRolesByProperty(aSegment, aProperty), aSortType);
	}

	@Override
	public void fetchRole(final String id, Set addedDocuments, JSONArray data) throws AnoAccessConfigurationServiceException {
		if (id.isEmpty() || addedDocuments.contains("Role" + id))
			return;

		try {
			final RoleDocument role = _getModuleAnoAccessConfiguration().getRole(id);
			addedDocuments.add("Role" + id);


			if (!role.getPermissions().isEmpty()) {
				for (String aPermissionsId: role.getPermissions()) {
					getAnoAccessConfigurationService().fetchPermission(aPermissionsId, addedDocuments, data);
				}
			}
			if (!role.getContextInitializers().isEmpty()) {
				for (String aContextInitializersId: role.getContextInitializers()) {
					getAnoAccessConfigurationService().fetchContextInitializer(aContextInitializersId, addedDocuments, data);
				}
			}

			JSONObject dataObject = new JSONObject();
			String jsonObject = ObjectMapperUtil.getMapperInstance().writeValueAsString(role);
			dataObject.put("object", jsonObject);
			dataObject.put("service", "AnoAccessConfiguration");
			dataObject.put("document", "AnoAccessConfiguration_Role");

			data.put(dataObject);

		}catch(AnoAccessConfigurationServiceException e){
			throw new AnoAccessConfigurationServiceException("Problem with getting document from AnoAccessConfiguration" + e.getMessage());
		}catch(IOException e){
			throw new AnoAccessConfigurationServiceException ("Problem with fetching data for this Role instance object:" + e.getMessage());
		}catch(JSONException e){
			throw new AnoAccessConfigurationServiceException ("Problem with fetching data for this Role instance in json :" + e.getMessage());
		}
	}

	private void saveTransferredRole(final JSONObject data) throws AnoAccessConfigurationServiceException {
		try {
			String objectData = data.getString("object");
			Role role = ObjectMapperUtil.getMapperInstance().readValue(objectData.getBytes(Charset.forName("UTF-8")), RoleDocument.class);

			try {
				updateRole(role);
			}catch(Exception e){
				importRole(role);
			}
		}catch(JSONException e){
			throw new AnoAccessConfigurationServiceException("Problem with getting data from json Role instance :" + e.getMessage());
		}catch(IOException e){
			throw new AnoAccessConfigurationServiceException("Problem with parsing data for this Role instance :" + e.getMessage());
		}
	}

	@Override
	public List getPermissions(){
		List permissions = new ArrayList<>();
		permissions.addAll(_getModuleAnoAccessConfiguration().getPermissions());
		return permissions;
	}

	@Override
	public List getPermissions(SortType sortType){
		return StaticQuickSorter.sort(getPermissions(), sortType);
	}

	/**
	 * Returns the Permission objects with the specified ids.
	 */
	public List getPermissions(List ids){
		if (ids==null || ids.size()==0)
			return new ArrayList<>(0);
		List all = getPermissions();
		List ret = new ArrayList<>();
		for (Permission permission : all){
			if(ids.contains(permission.getId())){
				ret.add(permission);
			}
		}
		return ret;
	}

	/**
	 * Returns the Permission objects with the specified ids, sorted by given sorttype.
	 */
	public List getPermissions(List ids, SortType sortType){
		return StaticQuickSorter.sort(getPermissions(ids), sortType);
	}

	@Override
	public void deletePermission(Permission permission){
		deletePermission(permission.getId());
		if (hasServiceListeners()){
			fireObjectDeletedEvent(permission);
		}
	}

	@Override
	public void deletePermission(String id){
		ModuleAnoAccessConfiguration module = _getModuleAnoAccessConfiguration();
		Permission varValue = hasServiceListeners()?module.getPermission(id):null;
		module.deletePermission(id);
		updateModule(module);
		if(varValue!=null){
			fireObjectDeletedEvent(varValue);
		}
	}

	@Override
	public void deletePermissions(List list){
		ModuleAnoAccessConfiguration module = _getModuleAnoAccessConfiguration();
		for (Permission permission : list){
			module.deletePermission(permission.getId());
		}
		updateModule(module);
		if (hasServiceListeners()){
			for (int t=0; t importPermissions(List list){
		ModuleAnoAccessConfiguration module = _getModuleAnoAccessConfiguration();
		List ret = new ArrayList<>();
		for (Permission permission : list){
			Permission imported = module.importPermission((PermissionDocument)permission);
			ret.add(imported);
		}
		updateModule(module);
		if (hasServiceListeners()){
			for (Permission permission : ret)
				fireObjectImportedEvent(permission);
		}
		return ret;
	}

	@Override
	public Permission createPermission(Permission permission){
		ModuleAnoAccessConfiguration module = _getModuleAnoAccessConfiguration();
		module.createPermission((PermissionDocument)permission);
		updateModule(module);
		fireObjectCreatedEvent(permission);
		return permission;
	}

	@Override
	/**
	 * Creates multiple new Permission objects.
	 * Returns the created versions.
	 */
	public List createPermissions(List list){
		ModuleAnoAccessConfiguration module = _getModuleAnoAccessConfiguration();
		List ret = new ArrayList<>();
		for (Permission permission : list){
			Permission created = module.createPermission((PermissionDocument)permission);
			ret.add(created);
		}
		updateModule(module);
		if (hasServiceListeners()){
			for (Permission permission : ret)
				fireObjectCreatedEvent(permission);
		}
		return ret;
	}

	@Override
	public Permission updatePermission(Permission permission){
		Permission oldVersion = null;
		ModuleAnoAccessConfiguration module = _getModuleAnoAccessConfiguration();
		if (hasServiceListeners())
			oldVersion = module.getPermission(permission.getId());
		module.updatePermission((PermissionDocument)permission);
		updateModule(module);
		if (oldVersion != null){
			fireObjectUpdatedEvent(oldVersion, permission);
		}
		return permission;
	}

	@Override
	public List updatePermissions(List list){
		List oldList = null;
		if (hasServiceListeners())
			oldList = new ArrayList<>(list.size());
		ModuleAnoAccessConfiguration module = _getModuleAnoAccessConfiguration();
		for (Permission permission : list){
			if (oldList!=null)
				oldList.add(module.getPermission(permission.getId()));
			module.updatePermission((PermissionDocument)permission);
		}
		updateModule(module);
		if (oldList!=null){
			for (int t=0; t getPermissionsByProperty(String propertyName, Object value){
		List allPermissions = getPermissions();
		List ret = new ArrayList<>();
		for (int i=0; i getPermissionsByProperty(String propertyName, Object value, SortType sortType){
		return StaticQuickSorter.sort(getPermissionsByProperty(propertyName, value), sortType);
	}
	/**
	 * Executes a query on Permissions
	 */
	public QueryResult executeQueryOnPermissions(DocumentQuery query){
		List allPermissions = getPermissions();
		QueryResult result = new QueryResult();
		for (int i=0; i partialResult = query.match(allPermissions.get(i));
			result.add(partialResult);
		}
		return result;
	}

	/**
	 * Returns all Permission objects, where property matches.
	 */
	public List getPermissionsByProperty(QueryProperty... property){
		//first the slow version, the fast version is a todo.
		List ret = new ArrayList<>();
		List src = getPermissions();
		for ( Permission permission : src){
			boolean mayPass = true;
			for (QueryProperty qp : property){
				mayPass = mayPass && qp.doesMatch(permission.getPropertyValue(qp.getName()));
			}
			if (mayPass)
				ret.add(permission);
		}
		return ret;
	}

	/**
	 * Returns all Permission objects, where property matches, sorted
	 */
	public List getPermissionsByProperty(SortType sortType, QueryProperty... property){
		return StaticQuickSorter.sort(getPermissionsByProperty(property), sortType);
	}

	/**
	 * Returns Permission objects count.
	 */
	public int getPermissionsCount() {
		return _getModuleAnoAccessConfiguration().getPermissions().size();
	}

	/**
	 * Returns Permission objects segment.
	 */
	public List getPermissions(Segment aSegment) {
		return Slicer.slice(aSegment, getPermissions()).getSliceData();
	}

	/**
	 * Returns Permission objects segment, where property matched.
	 */
	public List getPermissionsByProperty(Segment aSegment, QueryProperty... property) {
		int pLimit = aSegment.getElementsPerSlice();
		int pOffset = aSegment.getSliceNumber() * aSegment.getElementsPerSlice() - aSegment.getElementsPerSlice();
		List ret = new ArrayList<>();
		List src = getPermissions();
		for (Permission permission : src) {
			boolean mayPass = true;
			for (QueryProperty qp : property) {
				mayPass = mayPass && qp.doesMatch(permission.getPropertyValue(qp.getName()));
			}
			if (mayPass)
				ret.add(permission);
			if (ret.size() > pOffset + pLimit)
				break;
		}
		return Slicer.slice(aSegment, ret).getSliceData();
	}

	/**
	 * Returns Permission objects segment, where property matched, sorted.
	 */
	public List getPermissionsByProperty(Segment aSegment, SortType aSortType, QueryProperty... aProperty){
		return StaticQuickSorter.sort(getPermissionsByProperty(aSegment, aProperty), aSortType);
	}

	@Override
	public void fetchPermission(final String id, Set addedDocuments, JSONArray data) throws AnoAccessConfigurationServiceException {
		if (id.isEmpty() || addedDocuments.contains("Permission" + id))
			return;

		try {
			final PermissionDocument permission = _getModuleAnoAccessConfiguration().getPermission(id);
			addedDocuments.add("Permission" + id);

			if (!StringUtils.isEmpty(permission.getAccessOperation()))
				getAnoAccessConfigurationService().fetchAccessOperation(permission.getAccessOperation(), addedDocuments, data);

			if (!permission.getConstraints().isEmpty()) {
				for (String aConstraintsId: permission.getConstraints()) {
					getAnoAccessConfigurationService().fetchConstraint(aConstraintsId, addedDocuments, data);
				}
			}

			JSONObject dataObject = new JSONObject();
			String jsonObject = ObjectMapperUtil.getMapperInstance().writeValueAsString(permission);
			dataObject.put("object", jsonObject);
			dataObject.put("service", "AnoAccessConfiguration");
			dataObject.put("document", "AnoAccessConfiguration_Permission");

			data.put(dataObject);

		}catch(AnoAccessConfigurationServiceException e){
			throw new AnoAccessConfigurationServiceException("Problem with getting document from AnoAccessConfiguration" + e.getMessage());
		}catch(IOException e){
			throw new AnoAccessConfigurationServiceException ("Problem with fetching data for this Permission instance object:" + e.getMessage());
		}catch(JSONException e){
			throw new AnoAccessConfigurationServiceException ("Problem with fetching data for this Permission instance in json :" + e.getMessage());
		}
	}

	private void saveTransferredPermission(final JSONObject data) throws AnoAccessConfigurationServiceException {
		try {
			String objectData = data.getString("object");
			Permission permission = ObjectMapperUtil.getMapperInstance().readValue(objectData.getBytes(Charset.forName("UTF-8")), PermissionDocument.class);

			try {
				updatePermission(permission);
			}catch(Exception e){
				importPermission(permission);
			}
		}catch(JSONException e){
			throw new AnoAccessConfigurationServiceException("Problem with getting data from json Permission instance :" + e.getMessage());
		}catch(IOException e){
			throw new AnoAccessConfigurationServiceException("Problem with parsing data for this Permission instance :" + e.getMessage());
		}
	}

	@Override
	public List getConstraints(){
		List constraints = new ArrayList<>();
		constraints.addAll(_getModuleAnoAccessConfiguration().getConstraints());
		return constraints;
	}

	@Override
	public List getConstraints(SortType sortType){
		return StaticQuickSorter.sort(getConstraints(), sortType);
	}

	/**
	 * Returns the Constraint objects with the specified ids.
	 */
	public List getConstraints(List ids){
		if (ids==null || ids.size()==0)
			return new ArrayList<>(0);
		List all = getConstraints();
		List ret = new ArrayList<>();
		for (Constraint constraint : all){
			if(ids.contains(constraint.getId())){
				ret.add(constraint);
			}
		}
		return ret;
	}

	/**
	 * Returns the Constraint objects with the specified ids, sorted by given sorttype.
	 */
	public List getConstraints(List ids, SortType sortType){
		return StaticQuickSorter.sort(getConstraints(ids), sortType);
	}

	@Override
	public void deleteConstraint(Constraint constraint){
		deleteConstraint(constraint.getId());
		if (hasServiceListeners()){
			fireObjectDeletedEvent(constraint);
		}
	}

	@Override
	public void deleteConstraint(String id){
		ModuleAnoAccessConfiguration module = _getModuleAnoAccessConfiguration();
		Constraint varValue = hasServiceListeners()?module.getConstraint(id):null;
		module.deleteConstraint(id);
		updateModule(module);
		if(varValue!=null){
			fireObjectDeletedEvent(varValue);
		}
	}

	@Override
	public void deleteConstraints(List list){
		ModuleAnoAccessConfiguration module = _getModuleAnoAccessConfiguration();
		for (Constraint constraint : list){
			module.deleteConstraint(constraint.getId());
		}
		updateModule(module);
		if (hasServiceListeners()){
			for (int t=0; t importConstraints(List list){
		ModuleAnoAccessConfiguration module = _getModuleAnoAccessConfiguration();
		List ret = new ArrayList<>();
		for (Constraint constraint : list){
			Constraint imported = module.importConstraint((ConstraintDocument)constraint);
			ret.add(imported);
		}
		updateModule(module);
		if (hasServiceListeners()){
			for (Constraint constraint : ret)
				fireObjectImportedEvent(constraint);
		}
		return ret;
	}

	@Override
	public Constraint createConstraint(Constraint constraint){
		ModuleAnoAccessConfiguration module = _getModuleAnoAccessConfiguration();
		module.createConstraint((ConstraintDocument)constraint);
		updateModule(module);
		fireObjectCreatedEvent(constraint);
		return constraint;
	}

	@Override
	/**
	 * Creates multiple new Constraint objects.
	 * Returns the created versions.
	 */
	public List createConstraints(List list){
		ModuleAnoAccessConfiguration module = _getModuleAnoAccessConfiguration();
		List ret = new ArrayList<>();
		for (Constraint constraint : list){
			Constraint created = module.createConstraint((ConstraintDocument)constraint);
			ret.add(created);
		}
		updateModule(module);
		if (hasServiceListeners()){
			for (Constraint constraint : ret)
				fireObjectCreatedEvent(constraint);
		}
		return ret;
	}

	@Override
	public Constraint updateConstraint(Constraint constraint){
		Constraint oldVersion = null;
		ModuleAnoAccessConfiguration module = _getModuleAnoAccessConfiguration();
		if (hasServiceListeners())
			oldVersion = module.getConstraint(constraint.getId());
		module.updateConstraint((ConstraintDocument)constraint);
		updateModule(module);
		if (oldVersion != null){
			fireObjectUpdatedEvent(oldVersion, constraint);
		}
		return constraint;
	}

	@Override
	public List updateConstraints(List list){
		List oldList = null;
		if (hasServiceListeners())
			oldList = new ArrayList<>(list.size());
		ModuleAnoAccessConfiguration module = _getModuleAnoAccessConfiguration();
		for (Constraint constraint : list){
			if (oldList!=null)
				oldList.add(module.getConstraint(constraint.getId()));
			module.updateConstraint((ConstraintDocument)constraint);
		}
		updateModule(module);
		if (oldList!=null){
			for (int t=0; t getConstraintsByProperty(String propertyName, Object value){
		List allConstraints = getConstraints();
		List ret = new ArrayList<>();
		for (int i=0; i getConstraintsByProperty(String propertyName, Object value, SortType sortType){
		return StaticQuickSorter.sort(getConstraintsByProperty(propertyName, value), sortType);
	}
	/**
	 * Executes a query on Constraints
	 */
	public QueryResult executeQueryOnConstraints(DocumentQuery query){
		List allConstraints = getConstraints();
		QueryResult result = new QueryResult();
		for (int i=0; i partialResult = query.match(allConstraints.get(i));
			result.add(partialResult);
		}
		return result;
	}

	/**
	 * Returns all Constraint objects, where property matches.
	 */
	public List getConstraintsByProperty(QueryProperty... property){
		//first the slow version, the fast version is a todo.
		List ret = new ArrayList<>();
		List src = getConstraints();
		for ( Constraint constraint : src){
			boolean mayPass = true;
			for (QueryProperty qp : property){
				mayPass = mayPass && qp.doesMatch(constraint.getPropertyValue(qp.getName()));
			}
			if (mayPass)
				ret.add(constraint);
		}
		return ret;
	}

	/**
	 * Returns all Constraint objects, where property matches, sorted
	 */
	public List getConstraintsByProperty(SortType sortType, QueryProperty... property){
		return StaticQuickSorter.sort(getConstraintsByProperty(property), sortType);
	}

	/**
	 * Returns Constraint objects count.
	 */
	public int getConstraintsCount() {
		return _getModuleAnoAccessConfiguration().getConstraints().size();
	}

	/**
	 * Returns Constraint objects segment.
	 */
	public List getConstraints(Segment aSegment) {
		return Slicer.slice(aSegment, getConstraints()).getSliceData();
	}

	/**
	 * Returns Constraint objects segment, where property matched.
	 */
	public List getConstraintsByProperty(Segment aSegment, QueryProperty... property) {
		int pLimit = aSegment.getElementsPerSlice();
		int pOffset = aSegment.getSliceNumber() * aSegment.getElementsPerSlice() - aSegment.getElementsPerSlice();
		List ret = new ArrayList<>();
		List src = getConstraints();
		for (Constraint constraint : src) {
			boolean mayPass = true;
			for (QueryProperty qp : property) {
				mayPass = mayPass && qp.doesMatch(constraint.getPropertyValue(qp.getName()));
			}
			if (mayPass)
				ret.add(constraint);
			if (ret.size() > pOffset + pLimit)
				break;
		}
		return Slicer.slice(aSegment, ret).getSliceData();
	}

	/**
	 * Returns Constraint objects segment, where property matched, sorted.
	 */
	public List getConstraintsByProperty(Segment aSegment, SortType aSortType, QueryProperty... aProperty){
		return StaticQuickSorter.sort(getConstraintsByProperty(aSegment, aProperty), aSortType);
	}

	@Override
	public void fetchConstraint(final String id, Set addedDocuments, JSONArray data) throws AnoAccessConfigurationServiceException {
		if (id.isEmpty() || addedDocuments.contains("Constraint" + id))
			return;

		try {
			final ConstraintDocument constraint = _getModuleAnoAccessConfiguration().getConstraint(id);
			addedDocuments.add("Constraint" + id);


			if (!constraint.getContextInitializers().isEmpty()) {
				for (String aContextInitializersId: constraint.getContextInitializers()) {
					getAnoAccessConfigurationService().fetchContextInitializer(aContextInitializersId, addedDocuments, data);
				}
			}

			JSONObject dataObject = new JSONObject();
			String jsonObject = ObjectMapperUtil.getMapperInstance().writeValueAsString(constraint);
			dataObject.put("object", jsonObject);
			dataObject.put("service", "AnoAccessConfiguration");
			dataObject.put("document", "AnoAccessConfiguration_Constraint");

			data.put(dataObject);

		}catch(AnoAccessConfigurationServiceException e){
			throw new AnoAccessConfigurationServiceException("Problem with getting document from AnoAccessConfiguration" + e.getMessage());
		}catch(IOException e){
			throw new AnoAccessConfigurationServiceException ("Problem with fetching data for this Constraint instance object:" + e.getMessage());
		}catch(JSONException e){
			throw new AnoAccessConfigurationServiceException ("Problem with fetching data for this Constraint instance in json :" + e.getMessage());
		}
	}

	private void saveTransferredConstraint(final JSONObject data) throws AnoAccessConfigurationServiceException {
		try {
			String objectData = data.getString("object");
			Constraint constraint = ObjectMapperUtil.getMapperInstance().readValue(objectData.getBytes(Charset.forName("UTF-8")), ConstraintDocument.class);

			try {
				updateConstraint(constraint);
			}catch(Exception e){
				importConstraint(constraint);
			}
		}catch(JSONException e){
			throw new AnoAccessConfigurationServiceException("Problem with getting data from json Constraint instance :" + e.getMessage());
		}catch(IOException e){
			throw new AnoAccessConfigurationServiceException("Problem with parsing data for this Constraint instance :" + e.getMessage());
		}
	}

	@Override
	public List getContextInitializers(){
		List contextinitializers = new ArrayList<>();
		contextinitializers.addAll(_getModuleAnoAccessConfiguration().getContextInitializers());
		return contextinitializers;
	}

	@Override
	public List getContextInitializers(SortType sortType){
		return StaticQuickSorter.sort(getContextInitializers(), sortType);
	}

	/**
	 * Returns the ContextInitializer objects with the specified ids.
	 */
	public List getContextInitializers(List ids){
		if (ids==null || ids.size()==0)
			return new ArrayList<>(0);
		List all = getContextInitializers();
		List ret = new ArrayList<>();
		for (ContextInitializer contextinitializer : all){
			if(ids.contains(contextinitializer.getId())){
				ret.add(contextinitializer);
			}
		}
		return ret;
	}

	/**
	 * Returns the ContextInitializer objects with the specified ids, sorted by given sorttype.
	 */
	public List getContextInitializers(List ids, SortType sortType){
		return StaticQuickSorter.sort(getContextInitializers(ids), sortType);
	}

	@Override
	public void deleteContextInitializer(ContextInitializer contextinitializer){
		deleteContextInitializer(contextinitializer.getId());
		if (hasServiceListeners()){
			fireObjectDeletedEvent(contextinitializer);
		}
	}

	@Override
	public void deleteContextInitializer(String id){
		ModuleAnoAccessConfiguration module = _getModuleAnoAccessConfiguration();
		ContextInitializer varValue = hasServiceListeners()?module.getContextInitializer(id):null;
		module.deleteContextInitializer(id);
		updateModule(module);
		if(varValue!=null){
			fireObjectDeletedEvent(varValue);
		}
	}

	@Override
	public void deleteContextInitializers(List list){
		ModuleAnoAccessConfiguration module = _getModuleAnoAccessConfiguration();
		for (ContextInitializer contextinitializer : list){
			module.deleteContextInitializer(contextinitializer.getId());
		}
		updateModule(module);
		if (hasServiceListeners()){
			for (int t=0; t importContextInitializers(List list){
		ModuleAnoAccessConfiguration module = _getModuleAnoAccessConfiguration();
		List ret = new ArrayList<>();
		for (ContextInitializer contextinitializer : list){
			ContextInitializer imported = module.importContextInitializer((ContextInitializerDocument)contextinitializer);
			ret.add(imported);
		}
		updateModule(module);
		if (hasServiceListeners()){
			for (ContextInitializer contextinitializer : ret)
				fireObjectImportedEvent(contextinitializer);
		}
		return ret;
	}

	@Override
	public ContextInitializer createContextInitializer(ContextInitializer contextinitializer){
		ModuleAnoAccessConfiguration module = _getModuleAnoAccessConfiguration();
		module.createContextInitializer((ContextInitializerDocument)contextinitializer);
		updateModule(module);
		fireObjectCreatedEvent(contextinitializer);
		return contextinitializer;
	}

	@Override
	/**
	 * Creates multiple new ContextInitializer objects.
	 * Returns the created versions.
	 */
	public List createContextInitializers(List list){
		ModuleAnoAccessConfiguration module = _getModuleAnoAccessConfiguration();
		List ret = new ArrayList<>();
		for (ContextInitializer contextinitializer : list){
			ContextInitializer created = module.createContextInitializer((ContextInitializerDocument)contextinitializer);
			ret.add(created);
		}
		updateModule(module);
		if (hasServiceListeners()){
			for (ContextInitializer contextinitializer : ret)
				fireObjectCreatedEvent(contextinitializer);
		}
		return ret;
	}

	@Override
	public ContextInitializer updateContextInitializer(ContextInitializer contextinitializer){
		ContextInitializer oldVersion = null;
		ModuleAnoAccessConfiguration module = _getModuleAnoAccessConfiguration();
		if (hasServiceListeners())
			oldVersion = module.getContextInitializer(contextinitializer.getId());
		module.updateContextInitializer((ContextInitializerDocument)contextinitializer);
		updateModule(module);
		if (oldVersion != null){
			fireObjectUpdatedEvent(oldVersion, contextinitializer);
		}
		return contextinitializer;
	}

	@Override
	public List updateContextInitializers(List list){
		List oldList = null;
		if (hasServiceListeners())
			oldList = new ArrayList<>(list.size());
		ModuleAnoAccessConfiguration module = _getModuleAnoAccessConfiguration();
		for (ContextInitializer contextinitializer : list){
			if (oldList!=null)
				oldList.add(module.getContextInitializer(contextinitializer.getId()));
			module.updateContextInitializer((ContextInitializerDocument)contextinitializer);
		}
		updateModule(module);
		if (oldList!=null){
			for (int t=0; t getContextInitializersByProperty(String propertyName, Object value){
		List allContextInitializers = getContextInitializers();
		List ret = new ArrayList<>();
		for (int i=0; i getContextInitializersByProperty(String propertyName, Object value, SortType sortType){
		return StaticQuickSorter.sort(getContextInitializersByProperty(propertyName, value), sortType);
	}
	/**
	 * Executes a query on ContextInitializers
	 */
	public QueryResult executeQueryOnContextInitializers(DocumentQuery query){
		List allContextInitializers = getContextInitializers();
		QueryResult result = new QueryResult();
		for (int i=0; i partialResult = query.match(allContextInitializers.get(i));
			result.add(partialResult);
		}
		return result;
	}

	/**
	 * Returns all ContextInitializer objects, where property matches.
	 */
	public List getContextInitializersByProperty(QueryProperty... property){
		//first the slow version, the fast version is a todo.
		List ret = new ArrayList<>();
		List src = getContextInitializers();
		for ( ContextInitializer contextinitializer : src){
			boolean mayPass = true;
			for (QueryProperty qp : property){
				mayPass = mayPass && qp.doesMatch(contextinitializer.getPropertyValue(qp.getName()));
			}
			if (mayPass)
				ret.add(contextinitializer);
		}
		return ret;
	}

	/**
	 * Returns all ContextInitializer objects, where property matches, sorted
	 */
	public List getContextInitializersByProperty(SortType sortType, QueryProperty... property){
		return StaticQuickSorter.sort(getContextInitializersByProperty(property), sortType);
	}

	/**
	 * Returns ContextInitializer objects count.
	 */
	public int getContextInitializersCount() {
		return _getModuleAnoAccessConfiguration().getContextInitializers().size();
	}

	/**
	 * Returns ContextInitializer objects segment.
	 */
	public List getContextInitializers(Segment aSegment) {
		return Slicer.slice(aSegment, getContextInitializers()).getSliceData();
	}

	/**
	 * Returns ContextInitializer objects segment, where property matched.
	 */
	public List getContextInitializersByProperty(Segment aSegment, QueryProperty... property) {
		int pLimit = aSegment.getElementsPerSlice();
		int pOffset = aSegment.getSliceNumber() * aSegment.getElementsPerSlice() - aSegment.getElementsPerSlice();
		List ret = new ArrayList<>();
		List src = getContextInitializers();
		for (ContextInitializer contextinitializer : src) {
			boolean mayPass = true;
			for (QueryProperty qp : property) {
				mayPass = mayPass && qp.doesMatch(contextinitializer.getPropertyValue(qp.getName()));
			}
			if (mayPass)
				ret.add(contextinitializer);
			if (ret.size() > pOffset + pLimit)
				break;
		}
		return Slicer.slice(aSegment, ret).getSliceData();
	}

	/**
	 * Returns ContextInitializer objects segment, where property matched, sorted.
	 */
	public List getContextInitializersByProperty(Segment aSegment, SortType aSortType, QueryProperty... aProperty){
		return StaticQuickSorter.sort(getContextInitializersByProperty(aSegment, aProperty), aSortType);
	}

	@Override
	public void fetchContextInitializer(final String id, Set addedDocuments, JSONArray data) throws AnoAccessConfigurationServiceException {
		if (id.isEmpty() || addedDocuments.contains("ContextInitializer" + id))
			return;

		try {
			final ContextInitializerDocument contextinitializer = _getModuleAnoAccessConfiguration().getContextInitializer(id);
			addedDocuments.add("ContextInitializer" + id);



			JSONObject dataObject = new JSONObject();
			String jsonObject = ObjectMapperUtil.getMapperInstance().writeValueAsString(contextinitializer);
			dataObject.put("object", jsonObject);
			dataObject.put("service", "AnoAccessConfiguration");
			dataObject.put("document", "AnoAccessConfiguration_ContextInitializer");

			data.put(dataObject);

		}catch(IOException e){
			throw new AnoAccessConfigurationServiceException ("Problem with fetching data for this ContextInitializer instance object:" + e.getMessage());
		}catch(JSONException e){
			throw new AnoAccessConfigurationServiceException ("Problem with fetching data for this ContextInitializer instance in json :" + e.getMessage());
		}
	}

	private void saveTransferredContextInitializer(final JSONObject data) throws AnoAccessConfigurationServiceException {
		try {
			String objectData = data.getString("object");
			ContextInitializer contextinitializer = ObjectMapperUtil.getMapperInstance().readValue(objectData.getBytes(Charset.forName("UTF-8")), ContextInitializerDocument.class);

			try {
				updateContextInitializer(contextinitializer);
			}catch(Exception e){
				importContextInitializer(contextinitializer);
			}
		}catch(JSONException e){
			throw new AnoAccessConfigurationServiceException("Problem with getting data from json ContextInitializer instance :" + e.getMessage());
		}catch(IOException e){
			throw new AnoAccessConfigurationServiceException("Problem with parsing data for this ContextInitializer instance :" + e.getMessage());
		}
	}

	public void executeParsingForDocument (final DocumentName documentName, final JSONObject data) throws AnoAccessConfigurationServiceException {
		switch(documentName) {
			case DOCUMENT_ANOACCESSCONFIGURATION_ACCESSOPERATION:
				saveTransferredAccessOperation(data);
				break;
			case DOCUMENT_ANOACCESSCONFIGURATION_ROLE:
				saveTransferredRole(data);
				break;
			case DOCUMENT_ANOACCESSCONFIGURATION_PERMISSION:
				saveTransferredPermission(data);
				break;
			case DOCUMENT_ANOACCESSCONFIGURATION_CONSTRAINT:
				saveTransferredConstraint(data);
				break;
			case DOCUMENT_ANOACCESSCONFIGURATION_CONTEXTINITIALIZER:
				saveTransferredContextInitializer(data);
				break;
			default:
				log.info("There is no correct document: " + documentName + "in this service");
				throw new AnoAccessConfigurationServiceException("No such document");
		}
	}

	/**
	 * Executes a query on all data objects (documents, vo) which are part of this module and managed by this service
	 */
	public QueryResult executeQueryOnAllObjects(DocumentQuery query){
		QueryResult ret = new QueryResult();
		ret.add(executeQueryOnAccessOperations(query).getEntries());
		ret.add(executeQueryOnRoles(query).getEntries());
		ret.add(executeQueryOnPermissions(query).getEntries());
		ret.add(executeQueryOnConstraints(query).getEntries());
		ret.add(executeQueryOnContextInitializers(query).getEntries());
		return ret;
	} //executeQueryOnAllObjects


	public XMLNode exportAccessOperationsToXML(){
		XMLNode ret = new XMLNode("AccessOperations");
		List list = getAccessOperations();
		ret.addAttribute(new XMLAttribute("count", list.size()));
		for (AccessOperation object : list)
			ret.addChildNode(AccessOperationXMLHelper.toXML(object));
		return ret;
	}

	public XMLNode exportAccessOperationsToXML(List list){
		XMLNode ret = new XMLNode("AccessOperations");
		ret.addAttribute(new XMLAttribute("count", list.size()));
		for (AccessOperation object : list)
			ret.addChildNode(AccessOperationXMLHelper.toXML(object));
		return ret;
	}

	public XMLNode exportRolesToXML(){
		XMLNode ret = new XMLNode("Roles");
		List list = getRoles();
		ret.addAttribute(new XMLAttribute("count", list.size()));
		for (Role object : list)
			ret.addChildNode(RoleXMLHelper.toXML(object));
		return ret;
	}

	public XMLNode exportRolesToXML(List list){
		XMLNode ret = new XMLNode("Roles");
		ret.addAttribute(new XMLAttribute("count", list.size()));
		for (Role object : list)
			ret.addChildNode(RoleXMLHelper.toXML(object));
		return ret;
	}

	public XMLNode exportPermissionsToXML(){
		XMLNode ret = new XMLNode("Permissions");
		List list = getPermissions();
		ret.addAttribute(new XMLAttribute("count", list.size()));
		for (Permission object : list)
			ret.addChildNode(PermissionXMLHelper.toXML(object));
		return ret;
	}

	public XMLNode exportPermissionsToXML(List list){
		XMLNode ret = new XMLNode("Permissions");
		ret.addAttribute(new XMLAttribute("count", list.size()));
		for (Permission object : list)
			ret.addChildNode(PermissionXMLHelper.toXML(object));
		return ret;
	}

	public XMLNode exportConstraintsToXML(){
		XMLNode ret = new XMLNode("Constraints");
		List list = getConstraints();
		ret.addAttribute(new XMLAttribute("count", list.size()));
		for (Constraint object : list)
			ret.addChildNode(ConstraintXMLHelper.toXML(object));
		return ret;
	}

	public XMLNode exportConstraintsToXML(List list){
		XMLNode ret = new XMLNode("Constraints");
		ret.addAttribute(new XMLAttribute("count", list.size()));
		for (Constraint object : list)
			ret.addChildNode(ConstraintXMLHelper.toXML(object));
		return ret;
	}

	public XMLNode exportContextInitializersToXML(){
		XMLNode ret = new XMLNode("ContextInitializers");
		List list = getContextInitializers();
		ret.addAttribute(new XMLAttribute("count", list.size()));
		for (ContextInitializer object : list)
			ret.addChildNode(ContextInitializerXMLHelper.toXML(object));
		return ret;
	}

	public XMLNode exportContextInitializersToXML(List list){
		XMLNode ret = new XMLNode("ContextInitializers");
		ret.addAttribute(new XMLAttribute("count", list.size()));
		for (ContextInitializer object : list)
			ret.addChildNode(ContextInitializerXMLHelper.toXML(object));
		return ret;
	}

	public XMLNode exportToXML(){
		XMLNode ret = new XMLNode("AnoAccessConfiguration");

		ret.addChildNode(exportAccessOperationsToXML());
		ret.addChildNode(exportRolesToXML());
		ret.addChildNode(exportPermissionsToXML());
		ret.addChildNode(exportConstraintsToXML());
		ret.addChildNode(exportContextInitializersToXML());

		return ret;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy