package gr.uoa.di.web.utils.ep;

import eu.dnetlib.domain.data.Document;
import eu.dnetlib.domain.functionality.UserProfile;
import gr.uoa.di.web.utils.ep.domain.Entity;
import gr.uoa.di.web.utils.ep.domain.Graph;
import gr.uoa.di.web.utils.ep.domain.Node;
import gr.uoa.di.web.utils.ep.domain.RelatedNode;
import gr.uoa.di.web.utils.ep.domain.Relation;
import gr.uoa.di.web.utils.search.DocumentPage;

import java.util.List;
import java.util.Map;
import java.util.Set;

public class DLMSEPManager implements EPManager {

	@Override
	public Set<RelatedNode> getChildren(Node node) throws EPManagerException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Set<Map<String, List<String>>> getDropboxContents(
			UserProfile userProfile) throws EPManagerException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Document getEnhancedPublication(String id) throws EPManagerException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public DocumentPage getEnhancedPublications(int pageSize, int pageNumber)
			throws EPManagerException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Set<Entity> getEntities() throws EPManagerException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Graph getGraph(String rootId) throws EPManagerException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Node getNode(String id) throws EPManagerException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Set<RelatedNode> getParents(Node node) throws EPManagerException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Set<Relation> getRelations() throws EPManagerException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String saveAggregationObject(UserProfile userProfile,
			String description, String language, String subject, String title,
			Set<String> contentIds) throws EPManagerException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String saveEnhancedPublication(UserProfile userProfile,
			String description, String language, String subject, String title,
			String ePrintId, Set<String> nonEPrintIds)
			throws EPManagerException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void saveGraph(UserProfile userProfile, String[] commands) throws EPManagerException {
		// TODO Auto-generated method stub
	}
	
}


//public class DLMSEPManager implements EPManager {
//	private static final String FORMAT = "DMF";
//	private static final String PARAMETER_DELIMITER = "&";
//	private static final String VALUE_DELIMITER = "=";
//	private static final String UTF8 = "UTF-8";
//	private static final String COMMAND = "command";
//	private static final String CREATE = "create";
//	private static final String IMPORT = "import";
//	private static final String EDIT = "edit";
//	private static final String DELETE = "delete";
//	private static final String ADD = "add";
//	private static final String REMOVE = "remove";
//	private static final String TYPE = "type";
//	private static final String ID = "id";
//	private static final String SOURCE = "source";
//	private static final String TARGET = "target";
//	private static final String DOCUMENT_PREFIX = "document.";
//	private static final String COLLECTION_PREFIX = "coll(";
//	private static final String DEFAULT_PROPERTIES_FILE = "gr.uoa.di.driver.web.ep.ep-manager.properties";
//	
//	private static Logger logger = Logger.getLogger(DLMSEPManager.class);
//
//	private DataSource dataSource = null;
//	private Connection connection = null;
//	private ServiceLocator<PublisherService> publisherServiceLocator = null;
//	private DocumentReader documentReader = null;
//	private IndexLayoutManager indexLayoutManager = null;
//	private String repositoryName = null;
//	private String repositoryInstitution = null;
//	private String propertiesFile = null;
//	private Properties properties = new Properties();
//	private Set<Entity> entities = new HashSet<Entity>();
//	private Map<String, Entity> entitiesByName = new HashMap<String, Entity>();
//	private Map<String, Set<String>> unions = new HashMap<String, Set<String>>();
//	private Set<Relation> relations = new HashSet<Relation>();
//	private Map<String, Set<String>> relationsBySource = new HashMap<String, Set<String>>();
//	private Map<String, Set<String>> relationsByTarget = new HashMap<String, Set<String>>();
//	private Map<String, String> fieldsByXPath = new HashMap<String, String>();
//	private Map<String, String> fieldsByName = new HashMap<String, String>();
//	private Map<Long, Long> temporaryIds = new HashMap<Long, Long>();
//
//	@SuppressWarnings("unchecked")
//	public void init() throws EPManagerException {
//		try {
//			long time = System.currentTimeMillis();
//
//			// <<-- field mappings --
//			for (LayoutField layoutField: indexLayoutManager.getIndexableFields()) {
//				String xPath = layoutField.getXpath().replace("//", "");
//				String name = layoutField.getName();
//				fieldsByXPath.put(xPath, name);
//				fieldsByName.put(name, xPath);
//			}
//			// -- field mappings -->>
//
//			//<<-- properties --
//			loadProperties(propertiesFile);
//			//-- properties -->>
//
//			// <<-- entities --
//			PreparedStatement preparedStatement = getConnection().prepareStatement("select SystemStructSets/@(name|fields)");
//			ResultSet resultSet = preparedStatement.executeQuery();
//			while (resultSet.next()) {
//				Set<Field> fields = new HashSet<Field>();
//				String name = resultSet.getString(1);
//				for (Map<String, String> field : (List<Map<String, String>>) resultSet.getObject(2)) {
//					String fieldName = fieldsByXPath.get(field.get("label"));
//					if (fieldName != null)
//						fields.add(new Field(fieldName, field.get("type")));
//				}
//				Entity entity = new Entity(name, fields, properties.getProperty("entity." + name + ".label"),
//						properties.getProperty("entity." + name + ".color"),
//						Shape.parseShape(properties.getProperty("entity." + name + ".shape")),
//						properties.getProperty("entity." + name + ".idField"),
//						properties.getProperty("entity." + name + ".labelField"),
//						Boolean.parseBoolean(properties.getProperty("entity." + name + ".internal")));
//				entities.add(entity);
//				entitiesByName.put(name, entity);
//			}
//			// -- entities -->>
//
//			// <<-- unions --
//			preparedStatement = getConnection().prepareStatement("select SystemUnionSets/@name");
//			resultSet = preparedStatement.executeQuery();
//			while (resultSet.next()) {
//				String name = resultSet.getString(1);
//				preparedStatement = getConnection().prepareStatement("select SystemUnionSets[@name = ?]/SystemIncludesSets/deref::*/@name");
//				preparedStatement.setString(1, name);
//				ResultSet innerResultSet = preparedStatement.executeQuery();
//				Set<String> unionEntities = new HashSet<String>();
//				while (innerResultSet.next())
//					unionEntities.add(innerResultSet.getString(1));
//				unions.put(name, unionEntities);
//			}
//			// -- unions -->>
//
//			// <<-- relations --
//			preparedStatement = getConnection().prepareStatement("select SystemRelSets/@(name|mult|part)");
//			resultSet = preparedStatement.executeQuery();
//			while (resultSet.next()) {
//				String name = resultSet.getString(1);
//				preparedStatement = getConnection().prepareStatement("select SystemRelSets[@name = ?]/SystemHasFirstSet/deref::*/@name");
//				preparedStatement.setString(1, name);
//				ResultSet innerResultSet = preparedStatement.executeQuery();
//				Set<String> sourceEntities = new HashSet<String>();
//				while (innerResultSet.next()) {
//					String sourceName = innerResultSet.getString(1);
//					if (entitiesByName.get(sourceName) != null) // it is a plain entity; just add it
//						sourceEntities.add(sourceName);
//					else if (unions.containsKey(sourceName)) // it is a union; add all entities it contains
//						sourceEntities.addAll(unions.get(sourceName));
//				}
//				preparedStatement = getConnection().prepareStatement("select SystemRelSets[@name = ?]/SystemHasSecondSet/deref::*/@name");
//				preparedStatement.setString(1, name);
//				innerResultSet = preparedStatement.executeQuery();
//				Set<String> targetEntities = new HashSet<String>();
//				while (innerResultSet.next()) {
//					String targetName = innerResultSet.getString(1);
//					if (entitiesByName.get(targetName) != null) // it is a plain entity; just add it
//						targetEntities.add(targetName);
//					else if (unions.containsKey(targetName)) // it is a union; add all entities it contains
//						targetEntities.addAll(unions.get(targetName));
//				}
//				relations.add(new Relation(name, sourceEntities, targetEntities, Cardinality.parseCardinality(resultSet.getString(2)),
//						Partiality.parsePartiality(resultSet.getString(3)), properties.getProperty("relation." + name + ".label"),
//						Integer.parseInt(properties.getProperty("relation." + name + ".width")),
//						properties.getProperty("relation." + name + ".color")));
//				for (String sourceEntity: sourceEntities) {
//					Set<String> relations = relationsBySource.get(sourceEntity);
//					if (relations == null) {
//						relations = new HashSet<String>();
//						relationsBySource.put(sourceEntity, relations);
//					}
//					relations.add(name);
//				}
//				for (String targetEntity: targetEntities) {
//					Set<String> relations = relationsByTarget.get(targetEntity);
//					if (relations == null) {
//						relations = new HashSet<String>();
//						relationsByTarget.put(targetEntity, relations);
//					}
//					relations.add(name);
//				}
//			}
//			// -- relations -->>
//
//			logger.debug("DLMS EP manager initialized successfully in " + (System.currentTimeMillis() - time) + " ms");
//		} catch (FileNotFoundException e) {
//			logger.error("error loading properties", e);
//			throw new EPManagerException("error loading properties", e);
//		} catch (IOException e) {
//			logger.error("error loading properties", e);
//			throw new EPManagerException("error loading properties", e);
//		} catch (SQLException e) {
//			logger.error("error retrieving entities, types, unions or relations", e);
//			throw new EPManagerException("error retrieving entities, types, unions or relations", e);
//		}
//	}
//
//	@Override
//	public Set<Entity> getEntities() throws EPManagerException {
//		logger.debug("retrieved entities");
//		return entities;
//	}
//
//	@Override
//	public Set<Relation> getRelations() throws EPManagerException {
//		logger.debug("retrieved relations");
//		return relations;
//	}
//
//	@Override
//	public Set<Document> getDropboxContents(UserProfile userProfile) throws EPManagerException {
//		long time = System.currentTimeMillis();
//		try {
//			Set<Document> documents = new HashSet<Document>();
//			for (String documentId : userProfile.getDocumentIds()) {
//				String xml = publisherServiceLocator.getService().getResourceById(documentId, FORMAT);
//				if (xml == null)
//					continue;
//				Document document = documentReader.read(xml);
//				if (document == null)
//					continue;
//				documents.add(document);
//			}
//			logger.debug("retrieved dropbox contents of user " + userProfile + " in " + (System.currentTimeMillis() - time) + " ms");
//			return documents;
//		} catch (PublisherServiceException e) {
//			logger.error("error retrieving dropbox contents of user " + userProfile, e);
//			throw new EPManagerException("error retrieving dropbox contents of user " + userProfile, e);
//		}
//	}
//
//	@Override
//	public Graph getGraph(String id) throws EPManagerException {
//		logger.debug("retrieving graph with root node " + id);
//		long time = System.currentTimeMillis();
//		Set<Node> nodes = new HashSet<Node>();
//		Set<Edge> edges = new HashSet<Edge>();
//		Node root = getNode(id);
//		if (root == null) {
//			logger.debug("no graph with root node " + id + " found");
//			return null;
//		}
//		nodes.add(root);
//		for (RelatedNode parent : getParents(root)) {
//			nodes.add(parent.getNode());
//			edges.add(new Edge(parent.getRelation(), parent.getNode().getId(), root.getId()));
//		}
//		getChildren(root, nodes, edges);
//		logger.debug("retrieved graph with root node " + id + " in " + (System.currentTimeMillis() - time) + " ms");
//		return new Graph(nodes, edges);
//	}
//	
//	@Override
//	public void saveGraph(UserProfile userProfile, String [] commands) throws EPManagerException {
//		logger.debug("saving graph");
//		long time = System.currentTimeMillis();
//		for (String command : commands)
//			executeCommand(command);
//		logger.debug("saved graph in " + (System.currentTimeMillis() - time) + " ms");
//	}
//	
//	@Override
//	public DocumentPage getEnhancedPublications(int pageSize, int pageNumber) throws EPManagerException {
//		logger.debug("retrieving enhanced publications (page size = " + pageSize + ", page number = " + pageNumber + ")");
//		long time = System.currentTimeMillis();
//		List<Document> documents = new ArrayList<Document>();
//		try {
//			String entityName = properties.getProperty("enhancedPublicationEntity");
//			if (entityName == null) {
//				logger.debug("no enhanced publication entity defined");
//				throw new EPManagerException("no enhanced publication entity defined");
//			}
//			PreparedStatement preparedStatement = getConnection().prepareStatement("select " + entityName);
//			ResultSet resultSet = preparedStatement.executeQuery();
//			while (resultSet.next()) {
//				InformationObject informationObject = (InformationObject) resultSet.getObject(1);
//				Document document = getDocument(informationObject);
//				if (document != null)
//					documents.add(document);
//			}
//			int numberOfDocuments = documents.size();
//			int numberOfPages = numberOfDocuments / pageSize + (((numberOfDocuments % pageSize) > 0) ? 1 : 0);
//			DocumentPage page = null;
//			if (numberOfDocuments > 0) {
//				int from = (pageNumber - 1) * pageSize;
//				int to = pageNumber * pageSize - 1;
//				if (from < 0)
//					from = 0;
//				if (to > numberOfDocuments)
//					to = numberOfDocuments;
//				page = new DocumentPage(documents.subList(from, to), pageSize, pageNumber, numberOfDocuments, numberOfPages);
//			} else {
//				page = DocumentPage.EMPTY_PAGE;
//			}
//			logger.debug("retrieved enhanced publications in " + (System.currentTimeMillis() - time) + " ms");
//			return page;
//		} catch (SQLException e) {
//			logger.error("error retrieving enhanced publications", e);
//			throw new EPManagerException("error retrieving enhanced publications", e);
//		}
//	}
//	
//	@Override
//	public Document getEnhancedPublication(String id) throws EPManagerException {
//		logger.debug("retrieving enhanced publication " + id);
//		long time = System.currentTimeMillis();
//		String entityName = properties.getProperty("enhancedPublicationEntity");
//		if (entityName == null) {
//			logger.debug("no enhanced publication entity defined");
//			throw new EPManagerException("no enhanced publication entity defined");
//		}
//		Entity entity = entitiesByName.get(entityName);
//		if (entity == null) {
//			logger.debug("no enhanced publication entity defined");
//			throw new EPManagerException("no enhanced publication entity defined");
//		}
//
//		String idField = fieldsByName.get(entity.getIdField());
//		if (idField == null) {
//			logger.debug("no id field defined for entity " + entityName);
//			throw new EPManagerException("no id field defined for entity " + entityName);
//		}
//		try {
//			PreparedStatement preparedStatement = getConnection().prepareStatement("select " + entityName + "[@" + idField + " = ?]");
//			preparedStatement.setString(1, id);
//			ResultSet resultSet = preparedStatement.executeQuery();
//			if (!resultSet.next()) {
//				logger.debug("enhanced publication " + id + " does not exist");
//				return null;
//			}
//			InformationObject informationObject = (InformationObject) resultSet.getObject(1);
//			Document document = getDocument(informationObject);
//			if (document == null) {
//				logger.debug("enhanced publication " + id + " has no document");
//				return null;				
//			}
//			logger.debug("retrieved enhanced publication " + id + " in " + (System.currentTimeMillis() - time) + " ms");
//			return document;
//		} catch (SQLException e) {
//			logger.error("error retrieving enhanced publication " + id);
//			throw new EPManagerException("error retrieving enhanced publication " + id);
//		}
//	}
//	
//	@Override
//	public Node getNode(String id) throws EPManagerException {
//		logger.debug("retrieving node " + id);
//		long time = System.currentTimeMillis();
//		if (entities.size() <= 0) {
//			logger.debug("no entities found");
//			return null;
//		}
//		try {
//			for (Entity entity : entities) {
//				String field = fieldsByName.get(entity.getIdField());
//				if (field == null)
//					continue;
//				PreparedStatement preparedStatement = getConnection().prepareStatement("select " + entity.getName() + "[@" + field + " = ?]");
//				preparedStatement.setString(1, id);
//				ResultSet resultSet = preparedStatement.executeQuery();
//				if (!resultSet.next())
//					continue;
//				InformationObject informationObject = (InformationObject) resultSet.getObject(1);
//				Document document = getDocument(informationObject);
//				if ((document == null) || (document.getMap() == null))
//					continue;
//				logger.debug("retrieved node " + id + " in " + (System.currentTimeMillis() - time) + " ms");
//				return new Node(informationObject.getSet(), informationObject.getId(), document);
//			}
//			logger.debug("node " + id + " not found");
//			return null;
//		} catch (SQLException e) {
//			logger.error("error retriving node " + id, e);
//			throw new EPManagerException("error retriving node " + id, e);
//		}
//	}
//	
//	@Override
//	public Set<RelatedNode> getParents(Node node) throws EPManagerException {
//		logger.debug("retrieving parents of node " + node.getId());
//		long time = System.currentTimeMillis();
//		Set<RelatedNode> parents = new HashSet<RelatedNode>();
//		try {
//			for (String relation : relationsByTarget.get(node.getType())) { // for all relations that can have this node as target
//				PreparedStatement preparedStatement = getConnection().prepareStatement("select " + node.getType() + "[@id = ?]/reverse::" +
//						relation);
//				preparedStatement.setLong(1, node.getId());
//				ResultSet resultSet = preparedStatement.executeQuery();
//				while (resultSet.next()) {
//					Node parent = getNode(((InformationObject) resultSet.getObject(1)).getId());
//					if (parent != null)
//						parents.add(new RelatedNode(relation, parent));
//				}
//			}
//			logger.debug("retrieved parents of node " + node.getId() + " in " + (System.currentTimeMillis() - time) + " ms");
//			return parents;
//		} catch (SQLException e) {
//			logger.error("error retrieving parents of node " + node.getId(), e);
//			throw new EPManagerException("error retrieving parents of node " + node.getId(), e);
//		}
//	}
//
//	@Override
//	public Set<RelatedNode> getChildren(Node node) throws EPManagerException {
//		logger.debug("retrieving immediate children of node " + node.getId());
//		long time = System.currentTimeMillis();
//		Set<RelatedNode> children = new HashSet<RelatedNode>();
//		try {
//			for (String relation : relationsBySource.get(node.getType())) { // for all relations that can have this node as source
//				PreparedStatement preparedStatement = getConnection().prepareStatement("select " + node.getType() + "[@id = ?]/" + relation);
//				preparedStatement.setLong(1, node.getId());
//				ResultSet resultSet = preparedStatement.executeQuery();
//				while (resultSet.next()) {
//					Node child = getNode(((InformationObject) resultSet.getObject(1)).getId());
//					if (child != null)
//						children.add(new RelatedNode(relation, child));
//				}
//			}
//			logger.debug("retrieved immediate children of node " + node.getId() + " in " + (System.currentTimeMillis() - time) + " ms");
//			return children;
//		} catch (SQLException e) {
//			logger.error("error retrieving immediate children of node " + node.getId(), e);
//			throw new EPManagerException("error retrieving immediate children of node " + node.getId(), e);
//		}
//	}
//
//	private Map<String, List<String>> parseCommand(String command) throws EPManagerException {
//		Map<String, List<String>> arguments = new HashMap<String, List<String>>();
//		try {
//			for (String parameter: command.split(PARAMETER_DELIMITER)) {
//				String [] pair = parameter.split(VALUE_DELIMITER);
//				String key = URLDecoder.decode(pair[0], UTF8);
//				String value = (pair.length > 1) ? URLDecoder.decode(pair[1], UTF8) : "";
//				if (arguments.get(key) == null)
//					arguments.put(key, new ArrayList<String>());
//				arguments.get(key).add(value);
//			}
//			return arguments;
//		} catch (UnsupportedEncodingException e) {
//			logger.error("error parsing command " + command);
//			throw new EPManagerException("error parsing command " + command);
//		}
//	}
//	
//	private void executeCommand(String command) throws EPManagerException {
//		Map<String, List<String>> arguments = parseCommand(command);
//		command = arguments.get(COMMAND).get(0);
//		if (command == null) {
//			logger.error("error parsing command");
//			throw new EPManagerException("error parsing command");
//		} else if (command.equals(CREATE)) {
//			createNode(arguments.get(TYPE).get(0), Long.parseLong(arguments.get(ID).get(0)));
//		} else if (command.equals(IMPORT)) {
//			importNode(Long.parseLong(arguments.get(ID).get(0)));
//		} else if (command.equals(EDIT)) {
//			editNode(Long.parseLong(arguments.get(ID).get(0)), arguments);
//		} else if (command.equals(DELETE)) {
//			deleteNode(Long.parseLong(arguments.get(ID).get(0)));
//		} else if (command.equals(ADD)) {
//			addEdge(arguments.get(TYPE).get(0), Long.parseLong(arguments.get(SOURCE).get(0)), Long.parseLong(arguments.get(TARGET).get(0)));
//		} else if (command.equals(REMOVE)) {
//			removeEdge(arguments.get(TYPE).get(0), Long.parseLong(arguments.get(SOURCE).get(0)), Long.parseLong(arguments.get(TARGET).get(0)));
//		} else {
//			logger.error("error parsing command " + command);
//			throw new EPManagerException("error parsing command " + command);
//		}
//	}
//
//	private void createNode(String type, long id) throws EPManagerException {
//		logger.debug("creating node " + type + " with temporary id " + id);
//		long time = System.currentTimeMillis();
//		try {
//			PreparedStatement preparedStatement = getConnection().prepareStatement("Object object = new " + type + "({});");
//			ResultSet resultSet = preparedStatement.executeQuery();
//			if (!resultSet.next()) {
//				logger.error("error creating node " + type + " with temporary id " + id);
//				throw new EPManagerException("error creating node " + type + " with temporary id " + id);
//			}
//			InformationObject informationObject = (InformationObject) resultSet.getObject(1);
//			temporaryIds.put(id, informationObject.getId());
//			logger.debug("created node " + type + " with actual id " + informationObject.getId() + " (temporary id " + id + ") in " +
//					(System.currentTimeMillis() - time) + " ms");
//		} catch (SQLException e) {
//			logger.error("error creating node " + type + " with temporary id " + id, e);
//			throw new EPManagerException("error creating node " + type + " with temporary id " + id, e);
//		}
//	}
//	
//	private void importNode(long id) {}
//	
//	private Node getNode(long id) throws EPManagerException {
//		logger.debug("retrieving node " + id);
//		long time = System.currentTimeMillis();
//		if (entities.size() <= 0) {
//			logger.debug("no entities found");
//			return null;
//		}
//		if (id < 0) {
//			id = temporaryIds.get(id);
//			logger.debug("retrieving node with actual id " + id);
//		}
//		try {
//			StringBuilder query = new StringBuilder("select (");
//			for (Entity entity : entities)
//				query.append(entity.getName()).append(" | ");
//			query.replace(query.lastIndexOf(" | "), query.length(), ")[@id = ?]");
//			PreparedStatement preparedStatement = getConnection().prepareStatement(query.toString());
//			preparedStatement.setLong(1, id);
//			ResultSet resultSet = preparedStatement.executeQuery();
//			if (!resultSet.next()) {
//				logger.debug("node " + id + " not found");
//				return null;
//			}
//			InformationObject informationObject = (InformationObject) resultSet.getObject(1);
//			Document document = getDocument(informationObject);
//			if ((document == null) || (document.getMap() == null)) {
//				logger.debug("node " + id + " not found");
//				return null;
//			}
//			logger.debug("retrieved node " + id + " in " + (System.currentTimeMillis() - time) + " ms");
//			return new Node(informationObject.getSet(), informationObject.getId(), document);
//		} catch (SQLException e) {
//			logger.error("error retriving node " + id, e);
//			throw new EPManagerException("error retriving node " + id, e);
//		}
//	}
//
//	private void getChildren(Node node, Set<Node> nodes, Set<Edge> edges) throws EPManagerException {
//		logger.debug("retrieving all children of node " + node.getId());
//		long time = System.currentTimeMillis();
//		for (RelatedNode child : getChildren(node)) {
//			nodes.add(child.getNode());
//			edges.add(new Edge(child.getRelation(), node.getId(), child.getNode().getId()));
//			getChildren(child.getNode(), nodes, edges);  // find children recursively
//		}
//		logger.debug("retrieved all children of node " + node.getId() + " in " + (System.currentTimeMillis() - time) + " ms");
//	}
//	
//	private void editNode(long id, Map<String, List<String>> document) throws EPManagerException {
//		logger.debug("editing node " + id);
//		long time = System.currentTimeMillis();
//		Node node = getNode(id);
//		Set<RelatedNode> parents = getParents(node);
//		Set<RelatedNode> children = getChildren(node);
//		for (RelatedNode parent : parents) // remove connections with parents
//			removeEdge(parent.getRelation(), parent.getNode().getId(), id);
//		for (RelatedNode child : children) // remove connections with children
//			removeEdge(child.getRelation(), id, child.getNode().getId());
//		deleteNode(id); // delete node		
//		try { // create new node
//			StringBuilder fieldString = new StringBuilder();
//			for (Field field : entitiesByName.get(node.getType()).getFields()) {
//				if (document.get(DOCUMENT_PREFIX + field.getLabel()) != null) {
//					fieldString.append(fieldsByName.get(field.getLabel())).append(" = ");
//					boolean isCollectionField = field.getType().startsWith(COLLECTION_PREFIX);
//					if (isCollectionField) {
//						StringBuilder valueString = new StringBuilder();
//						for (String value : document.get(DOCUMENT_PREFIX + field.getLabel()))
//							valueString.append("'").append(value).append("', ");
//						if (valueString.length() > 2)
//							valueString.setLength(valueString.length() - 2);
//						fieldString.append("[").append(valueString).append("], "); 
//					} else
//						fieldString.append("'").append(document.get(DOCUMENT_PREFIX + field.getLabel()).get(0)).append("', ");
//				}
//			}			
//			if (fieldString.length() > 2)
//				fieldString.setLength(fieldString.length() - 2);
//			PreparedStatement preparedStatement = getConnection().prepareStatement("Object object = new " + node.getType() + "({" + fieldString +
//					"})");
//			ResultSet resultSet = preparedStatement.executeQuery();
//			if (!resultSet.next()) {
//				logger.error("error editing node " + id);
//				throw new EPManagerException("error editing node " + id);
//			}
//			InformationObject informationObject = (InformationObject) resultSet.getObject(1);
//			temporaryIds.put(id, informationObject.getId());
//		} catch (SQLException e) {
//			logger.error("error editing node " + id, e);
//			throw new EPManagerException("error editing node " + id, e);
//		}
//		for (RelatedNode parent : parents) // restore connections with parents
//			addEdge(parent.getRelation(), parent.getNode().getId(), id);
//		for (RelatedNode child : children) // restore connections with children
//			addEdge(child.getRelation(), id, child.getNode().getId());
//		logger.debug("edited node " + id + " in " + (System.currentTimeMillis() - time) + " ms");
//	}
//	
//	private void deleteNode(long id) throws EPManagerException {
//		logger.debug("deleting node " + id);
//		long time = System.currentTimeMillis();
//		if (entities.size() <= 0) {
//			logger.debug("no entities found");
//			throw new EPManagerException("no entities found");
//		}
//		if (id < 0) {
//			id = temporaryIds.get(id);
//			logger.debug("deleting node with actual id " + id);
//		}
//		try {
//			StringBuilder query = new StringBuilder("select (");
//			for (Entity entity : entities)
//				query.append(entity.getName()).append(" | ");
//			query.replace(query.lastIndexOf(" | "), query.length(), ")[@id = ?]");
//			PreparedStatement preparedStatement = getConnection().prepareStatement(query.toString());
//			preparedStatement.setLong(1, id);
//			ResultSet resultSet = preparedStatement.executeQuery();
//			if (!resultSet.next()) {
//				logger.error("error deleting node " + id + ": no such node exists");
//				throw new EPManagerException("error deleting node " + id + ": no such node exists");
//			}
//			InformationObject informationObject = (InformationObject) resultSet.getObject(1);
//			preparedStatement = getConnection().prepareStatement(informationObject.getSet() + ".drop(?)");
//			preparedStatement.setObject(1, informationObject);
//			preparedStatement.executeUpdate();
//			logger.debug("deleted node " + id + " in " + (System.currentTimeMillis() - time) + " ms");
//		} catch (SQLException e) {
//			logger.error("error deleting node " + id, e);
//			throw new EPManagerException("error deleting node " + id, e);
//		}		
//	}	
//	
//	private void addEdge(String type, long source, long target) throws EPManagerException {
//		logger.debug("adding edge " + type + " from node " + source + " to node " + target);
//		long time = System.currentTimeMillis();
//		if (entities.size() <= 0) {
//			logger.debug("no entities found");
//			throw new EPManagerException("no entities found");
//		}
//		if (source < 0) {
//			source = temporaryIds.get(source);
//			logger.debug("source actual id is " + source);
//		}
//		if (target < 0) {
//			target = temporaryIds.get(target);
//			logger.debug("target actual id is " + target);
//		}
//		try {
//			StringBuilder query = new StringBuilder("select (");
//			for (Entity entity : entities)
//				query.append(entity.getName()).append(" | ");
//			query.replace(query.lastIndexOf(" | "), query.length(), ")[@id = ?]");
//			PreparedStatement preparedStatement = getConnection().prepareStatement(query.toString());
//			preparedStatement.setLong(1, source);
//			ResultSet resultSet = preparedStatement.executeQuery();
//			if (!resultSet.next()) {
//				logger.error("error adding edge " + type + " from node " + source + " to node " + target + ": source does not exist");
//				throw new EPManagerException("error adding edge " + type + " from node " + source + " to node " + target + ": source does not exist");
//			}
//			InformationObject sourceInformationObject = (InformationObject) resultSet.getObject(1);
//
//logger.debug("source retrieved");
//
//			query = new StringBuilder("select (");
//			for (Entity entity : entities)
//				query.append(entity.getName()).append(" | ");
//			query.replace(query.lastIndexOf(" | "), query.length(), ")[@id = ?]");
//			preparedStatement = getConnection().prepareStatement(query.toString());
//			preparedStatement.setLong(1, target);
//			resultSet = preparedStatement.executeQuery();
//			if (!resultSet.next()) {
//				logger.error("error adding edge " + type + " from node " + source + " to node " + target + ": target does not exist");
//				throw new EPManagerException("error adding edge " + type + " from node " + source + " to node " + target +
//						": target does not exist");
//			}
//			InformationObject targetInformationObject = (InformationObject) resultSet.getObject(1);
//
//logger.debug("target retrieved");
//
//			preparedStatement = getConnection().prepareStatement("new " + type + " (?, ?);");
//			preparedStatement.setObject(1, sourceInformationObject);
//			preparedStatement.setObject(2, targetInformationObject);
//			
//			if (preparedStatement.executeUpdate() != 1) {
//				logger.error("error adding edge " + type + " from node " + source + " to node " + target);
//				throw new EPManagerException("error adding edge " + type + " from node " + source + " to node " + target);				
//			}
//			logger.debug("added edge " + type + " from node " + source + " to node " + target + " in " + (System.currentTimeMillis() - time) +
//					" ms");
//		} catch (SQLException e) {
//			logger.error("error adding edge " + type + " between nodes " + source + " and " + target, e);
//			throw new EPManagerException("error adding edge " + type + " between nodes " + source + " and " + target, e);
//		}
//	}
//	
//	private void removeEdge(String type, long source, long target) {}
//	
//	private Document getDocument(InformationObject informationObject) throws EPManagerException {
//		try {
//			PreparedStatement preparedStatement = getConnection().prepareStatement("?.exportDMF();");
//			preparedStatement.setObject(1, informationObject);
//			ResultSet resultSet = preparedStatement.executeQuery();
//			if (!resultSet.next()) {
//				logger.debug("object " + informationObject.getId() + " not found");
//				return null;
//			}
//			String xml = resultSet.getString(1);
//			if (xml == null) {
//				logger.debug("object " + informationObject.getId() + " has no XML");
//				return null;
//			}
//			Document document = documentReader.read(xml);
//			if (document == null) {
//				logger.debug("object " + informationObject.getId() + " has no document");
//				return null;
//			}
//			String entityName = informationObject.getSet();
//			if (!entitiesByName.get(entityName).getInternal()) { // entity is not internal in DLMS; use publisher
//				Map<String, List<String>> map = document.getMap();
//				if ((map == null) || (map.get("id") == null) || (map.get("id").get(0) == null)) {
//					logger.debug("object " + informationObject.getId() + " not found");
//					return null;
//				}
//				String documentId = map.get("id").get(0);
//				if (documentId == null) {
//					logger.debug("object " + informationObject.getId() + " not found");
//					return null;
//				}
//				xml = publisherServiceLocator.getService().getResourceById(documentId, FORMAT);
//				if (xml == null) {
//					logger.debug("object " + informationObject.getId() + " has no XML");
//					return null;
//				}
//				document = documentReader.read(xml);
//				if (document == null) {
//					logger.debug("object " + informationObject.getId() + " has no document");
//					return null;
//				}
//			}
//			return document;
//		} catch (SQLException e) {
//			logger.debug("error retrieving object " + informationObject.getId(), e);
//			throw new EPManagerException("error retrieving object " + informationObject.getId(), e);
//		} catch (PublisherServiceException e) {
//			logger.debug("error retrieving object " + informationObject.getId(), e);
//			throw new EPManagerException("error retrieving object " + informationObject.getId(), e);
//		}
//	}
//	
//	private void loadProperties(String propertiesFile) throws IOException {
//		if ((propertiesFile == null) || propertiesFile.isEmpty())
//			propertiesFile = DEFAULT_PROPERTIES_FILE;
//		InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(propertiesFile);
//		if (inputStream == null)
//			inputStream = DLMSEPManager.class.getResourceAsStream(propertiesFile);
//		properties.load(inputStream);
////		properties.load(this.getClass().getClassLoader().getResourceAsStream(propertiesFile));
//	}
//
////	@Override
////	public DocumentPage getEnhancedPublications(int pageSize, int pageNumber) throws EPManagerException {
////		try {
////			PreparedStatement stmt = this.getConnection().prepareStatement("select ePubs");
////			stmt.execute();
////			ResultSet rs = stmt.getResultSet();
////			List<Document> list = new ArrayList<Document>();
////
////			while (rs.next()) {
////				InformationObject iObj = (InformationObject) rs.getObject(1);
////				logger.debug("object type: " + iObj.getType());
////
////				list.add(this.documentReader.read(this.getDMF(iObj)));
////			}
////
////			int numberOfDocuments = list.size();
////			int numberOfPages = numberOfDocuments / pageSize + ((numberOfDocuments%pageSize > 0)?1:0);
////			DocumentPage page = null;
////
////			if (numberOfDocuments > 0) {
////				int from = (pageNumber - 1)*pageSize;
////				int to = (pageNumber)*pageSize - 1;
////
////				if (from < 0)
////					from = 0;
////
////				if (to > numberOfDocuments)
////					to = numberOfDocuments;
////
////				page = new DocumentPage(list.subList(from, to), pageSize, pageNumber, numberOfDocuments, numberOfPages);
////
////			} else {
////				page = DocumentPage.EMPTY_PAGE;
////			}
////
////			return page;
////		} catch (Exception e) {
////			logger.error("Error executing query", e);
////			throw new EPManagerException("Error executing query", e);
////		}
////	}
////
////	@Override
////	public Document getEnhachedPublication(String epId) throws EPManagerException {
////		logger.debug("Returning ePub with id " + epId);
////		Document doc = null;
////
////		try {
////			InformationObject iObj = getCompoundObject(epId);
////
////			if (iObj != null) {
////				String xmlDoc = this.getDMF(iObj);
////
////				logger.debug("Parsing dmf");
////				doc = documentReader.read(xmlDoc);
////				logger.debug("Done!!");
////			} else {
////				logger.warn("Information object for epub " + epId + " not found!");
////				return new Document();
////			}
////		} catch (Exception e) {
////			logger.error("Error getting compound object", e);
////			throw new EPManagerException("Error getting compound object", e);
////		}
////
////		return doc;
////	}
////
////	@Override
////	public List<RelatedObject> getAncestors(String epId) throws EPManagerException {
////		logger.debug("Getting parents for compound object " + epId);
////
////		try {
////			InformationObject ePub = this.getCompoundObject(epId);
////			PreparedStatement stmt = null;
////			List<InformationObject> objectList = null;
////			List<RelatedObject> res = new ArrayList<RelatedObject>();
////
////			if (ePub == null)
////				return new ArrayList<RelatedObject>();
////
////			logger.debug("Object is of type " + ePub.getType());
////
////			if (ePub.getType().equals("EPubsType")) {
////				logger.debug("trying relatedWith");
////				// relatedWith
////				stmt = this.getConnection().prepareStatement("select ePubs[relatedWith[@id=?]]");
////				stmt.setLong(1, ePub.getId());
////				objectList = this.performQuery(stmt);
////
////				for (InformationObject iObj:objectList) {
////					logger.debug("adding inforamtion object " + iObj.getId());
////					String xmlDoc = this.getDMF(iObj);
////
////					Document doc = documentReader.read(xmlDoc);
////
////					res.add(new RelatedObject("relatedWith", doc));
////				}
////			} else if (ePub.getType().equals("AggregationsType")) {
////				// composedBy
////				logger.debug("trying composedBy");
////				stmt = this.getConnection().prepareStatement("select ePubs[composedBy/deref::AggregationObjects[@id=?]]");
////				stmt.setLong(1, ePub.getId());
////				objectList = this.performQuery(stmt);
////
////				for (InformationObject iObj:objectList) {
////					logger.debug("adding inforamtion object " + iObj.getId());
////					String xmlDoc = this.getDMF(iObj);
////
////					Document doc = documentReader.read(xmlDoc);
////
////					res.add(new RelatedObject("composedBy", doc));
////				}
////
////				// aggregates
////				logger.debug("trying aggregates");
////				stmt = this.getConnection().prepareStatement("select AggregationObjects[aggregates/deref::AggregationObjects[@id=?]]");
////				stmt.setLong(1, ePub.getId());
////				objectList = this.performQuery(stmt);
////
////				for (InformationObject iObj:objectList) {
////					logger.debug("adding inforamtion object " + iObj.getId());
////					String xmlDoc = this.getDMF(iObj);
////
////					Document doc = documentReader.read(xmlDoc);
////
////					res.add(new RelatedObject("aggregates", doc));
////				}
////			} else if (ePub.getType().equals("ResearchDataType")) {
////				// generatedBy
////				logger.debug("trying generatedBy");
////				stmt = this.getConnection().prepareStatement("select ResearchData[generatedBy[@id=?]]");
////				stmt.setLong(1, ePub.getId());
////				objectList = this.performQuery(stmt);
////
////				for (InformationObject iObj:objectList) {
////					logger.debug("adding inforamtion object " + iObj.getId());
////					String xmlDoc = this.getDMF(iObj);
////
////					Document doc = documentReader.read(xmlDoc);
////
////					res.add(new RelatedObject("generatedBy", doc));
////				}
////
////				// composedBy
////				logger.debug("trying composedBy");
////				stmt = this.getConnection().prepareStatement("select ePubs[composedBy/deref::ResearchData[@id=?]]");
////				stmt.setLong(1, ePub.getId());
////				objectList = this.performQuery(stmt);
////
////				for (InformationObject iObj:objectList) {
////					logger.debug("adding inforamtion object " + iObj.getId());
////					String xmlDoc = this.getDMF(iObj);
////
////					Document doc = documentReader.read(xmlDoc);
////
////					res.add(new RelatedObject("composedBy", doc));
////				}
////
////				// aggregates
////				logger.debug("trying aggregates");
////				stmt = this.getConnection().prepareStatement("select AggregationObjects[aggregates/deref::ResearchData[@id=?]]");
////				stmt.setLong(1, ePub.getId());
////				objectList = this.performQuery(stmt);
////
////				for (InformationObject iObj:objectList) {
////					logger.debug("adding inforamtion object " + iObj.getId());
////					String xmlDoc = this.getDMF(iObj);
////
////					Document doc = documentReader.read(xmlDoc);
////
////					res.add(new RelatedObject("aggregates", doc));
////				}
////			} else {
////				logger.warn("NOT CONFIGURED TO SEARCH FOR ANCESTORS OF TYPE " + ePub.getType());
////			}
////
////			return res;
////		} catch (Exception e) {
////			logger.error("Error getting related objects", e);
////			throw new EPManagerException("Error getting related objects", e);
////		}
////	}
////
////	@Override
////	public List<RelatedObject> getRelatedObjects(String epId) throws EPManagerException {
////		logger.debug("Getting related objects for epub " + epId);
////
////		try {
////			InformationObject ePub = this.getCompoundObject(epId);
////			PreparedStatement stmt = null;
////			List<InformationObject> objectList = null;
////			List<RelatedObject> res = new ArrayList<RelatedObject>();
////
////			if (ePub == null)
////				return new ArrayList<RelatedObject>();
////
////			if (ePub.getType().equals("EPubsType")) {
////				logger.debug("object is ePub");
////				logger.debug("Trying relatedWith");
////				// relatedWith
////				stmt = this.getConnection().prepareStatement("select ePubs[@id=?]/relatedWith");
////				stmt.setLong(1, ePub.getId());
////				objectList = this.performQuery(stmt);
////
////				for (InformationObject iObj:objectList) {
////					logger.debug("adding information object " + iObj.getId() + " to results");
////					String xmlDoc = this.getDMF(iObj);
////
////					Document doc = documentReader.read(xmlDoc);
////
////					res.add(new RelatedObject("relatedWith", doc));
////				}
////
////				// hasEPrint
////				logger.debug("Trying hasEPrint");
////				stmt = this.getConnection().prepareStatement("select ePubs[@id=?]/hasEPrint");
////				stmt.setLong(1, ePub.getId());
////				objectList = this.performQuery(stmt);
////
////				for (InformationObject iObj:objectList) {
////					logger.debug("adding information object " + iObj.getId() + " to results");
////					String xmlDoc = this.getDMF(iObj);
////
////					Document doc = documentReader.read(xmlDoc);
////
////					res.add(new RelatedObject("hasEprint", doc));
////				}
////
////				// composedBy
////				logger.debug("Trying composedBy");
////				stmt = this.getConnection().prepareStatement("select ePubs[@id=?]/composedBy/deref::(ePrints|nonEPrints|ResearchData|AggregationObjects)");
////				stmt.setLong(1, ePub.getId());
////				objectList = this.performQuery(stmt);
//////				stmt = this.getConnection().prepareStatement("select ePubs[@id=?]/composedBy/deref::nonEPrints");
//////				stmt.setLong(1, ePub.getId());
//////				objectList.addAll(this.performQuery(stmt));
//////				stmt = this.getConnection().prepareStatement("select ePubs[@id=?]/composedBy/deref::ResearchData");
//////				stmt.setLong(1, ePub.getId());
//////				objectList.addAll(this.performQuery(stmt));
//////				stmt = this.getConnection().prepareStatement("select ePubs[@id=?]/composedBy/deref::AggregationObjects");
//////				stmt.setLong(1, ePub.getId());
//////				objectList.addAll(this.performQuery(stmt));
////
////				for (InformationObject iObj:objectList) {
////					logger.debug("adding information object " + iObj.getId() + " to results");
////					String xmlDoc = this.getDMF(iObj);
////
////					Document doc = documentReader.read(xmlDoc);
////
////					res.add(new RelatedObject("composedBy", doc));
////				}
////			} else if (ePub.getType().equals("AggregationsType")) {
////				// aggregates
////				stmt = this.getConnection().prepareStatement("select AggregationObjects[@id=?]/aggregates/deref::(ePrints|nonEPrints|ResearchData|AggregationObjects)");
////				stmt.setLong(1, ePub.getId());
////				objectList = this.performQuery(stmt);
//////				stmt = this.getConnection().prepareStatement("select AggregationObjects[@id=?]/aggregates/deref::nonEPrints");
//////				stmt.setLong(1, ePub.getId());
//////				objectList.addAll(this.performQuery(stmt));
//////				stmt = this.getConnection().prepareStatement("select AggregationObjects[@id=?]/aggregates/deref::ResearchData");
//////				stmt.setLong(1, ePub.getId());
//////				objectList.addAll(this.performQuery(stmt));
//////				stmt = this.getConnection().prepareStatement("select AggregationObjects[@id=?]/aggregates/deref::AggregationObjects");
//////				stmt.setLong(1, ePub.getId());
//////				objectList.addAll(this.performQuery(stmt));
////
////				for (InformationObject iObj:objectList) {
////					String xmlDoc = this.getDMF(iObj);
////
////					Document doc = documentReader.read(xmlDoc);
////
////					res.add(new RelatedObject("aggregates", doc));
////				}
////
////			} else if (ePub.getType().equals("ResearchDataType")) {
////				// generatedBy
////				stmt = this.getConnection().prepareStatement("select ResearchData[@id=?]/generatedBy");
////				stmt.setLong(1, ePub.getId());
////				objectList = this.performQuery(stmt);
////
////				for (InformationObject iObj:objectList) {
////					String xmlDoc = this.getDMF(iObj);
////
////					Document doc = documentReader.read(xmlDoc);
////
////					res.add(new RelatedObject("generatedBy", doc));
////				}
////			} else {
////				logger.warn("NOT CONFIGURED TO SEARCH FOR CHILDREN OF TYPE " + ePub.getType());
////			}
////
////			return res;
////		} catch (Exception e) {
////			logger.error("Error getting related objects", e);
////			throw new EPManagerException("Error getting related objects", e);
////		}
////	}
////
////	@Override
////	public String saveCompoundObject(Map<String, List<String>> values, Map<String, List<String>> relations, CompoundObjectType type)
////			throws EPManagerException {
////		logger.debug("Saving new enhanced publication");
////
////		try {
////			String epId = this.createCompoundObject(values, type);
////			InformationObject ePub = this.getCompoundObject(epId);
////
////			logger.debug("Information object: " + ((ePub == null)?null:ePub.getId()));
////
////			for (String relation : relations.keySet()) {
////				logger.debug("Adding relation " + relation);
////
////				for (String docId : relations.get(relation)) {
////					logger.debug("document id: " + docId);
////					// check if doc is in dlms
////					InformationObject iObj = this.getInformationObject(docId);
////
////					if (iObj == null) {
////						logger.debug("Document not in dlms. Creating new placeholder");
////						// the doc is not in dlms. It can not be a compound object,
////						// because if it was, it would already be there. It's an
////						// ePrint or nonEprint. Getting the dmf from the
////						// publisher, parsing it and storing the placeholder
////						// in dlms.
////						String docXml = this.publisherServiceLocator.getService().getResourceById(docId, FORMAT);
////						Document doc = documentReader.read(docXml);
////						String docType = doc.getMap().get("CobjTypology").get(0);
////
////						PreparedStatement stmt = this.getConnection().prepareStatement("Object setName = ?; Object o = new setName({dri:objIdentifier=?}); Components.add(o);");
////
////						if (docType.toLowerCase().equals("textual")) {
////							logger.debug("document is textual. Creating ePrint");
////							stmt.setString(1, "ePrints");
////						} else {
////							logger.debug("document is not textual. Creating nonEPrint");
////							stmt.setString(1, "nonEPrints");
////						}
////
////						stmt.setString(2, docId);
////
////						logger.debug("Saving document");
////						stmt.executeUpdate();
////						try {
////							Thread.sleep(200);
////						} catch (InterruptedException e) {}
////
////						iObj = this.getInformationObject(docId);
////					}
////
////					PreparedStatement stmt = this.getConnection().prepareStatement("Object relationName = ?; new relationName(?, ?);");
////
////					stmt.setString(1, relation);
////					stmt.setObject(2, ePub);
////					stmt.setObject(3, iObj);
////
////					logger.debug("Saving relation");
////					stmt.executeUpdate();
////					try {
////						Thread.sleep(200);
////					} catch (InterruptedException e) {}
////				}
////			}
////
////			return epId;
////		} catch (Exception e) {
////			logger.error("Error saving ePub", e);
////			throw new EPManagerException("Error saving ePub", e);
////		}
////	}
////
////	private String createCompoundObject(Map<String, List<String>> valueMap, CompoundObjectType type) throws EPManagerException {
////		logger.debug("Saving compund object of type " + type);
////
////		try {
////			String epId = this.createRandomId();
////			logger.debug("new object Id: " + epId);
////			String set = null;
////			String category = null;
////
////			// dc:dateAccepted, dr:dateOfCollection = ?, dri:dateOfCollection = ?
////			PreparedStatement stmt = this.getConnection().prepareStatement(
////					"Object coSet = ?; new coSet({dr:CobjTypology = 'compound object', dr:CobjCategory = ?, dri:objIdentifier = ?, dc:title=?, dc:description = ?, dc:creator = [?], dr:repositoryName = ?, dr:repositoryInstitution = ?});");
////
////			if (type == CompoundObjectType.ENHANCED_PUBLICATION) {
////				set = "ePubs";
////				category = "0015";
////			} else if (type == CompoundObjectType.AGGREGATION) {
////				set = "AggregationObjects";
////				category = "0016";
////			} else {
////				logger.error("I don't know how to save " + type);
////
////				throw new EPManagerException("Unknown type of epub");
////			}
////
////			stmt.setString(1, set);
////			stmt.setString(2, category);
////			stmt.setString(3, epId);
////			stmt.setString(4, valueMap.get("title").get(0));
////			stmt.setString(5, valueMap.get("description").get(0));
////			stmt.setString(6, valueMap.get("creator").get(0));
////			stmt.setString(7, this.repositoryName);
////			stmt.setString(8, this.repositoryInstitution);
////
////			logger.debug("title " + valueMap.get("title").get(0));
////			logger.debug("description " + valueMap.get("description").get(0));
////			logger.debug("creator " + valueMap.get("creator").get(0));
////
////			logger.debug("Saving epub");
////			stmt.executeUpdate();
////
////			try {
////				Thread.sleep(200);
////			} catch (InterruptedException e) {}
////
////			if (type == CompoundObjectType.AGGREGATION) {
////				logger.debug("Adding new aggregation to Components set");
////				InformationObject iObj = this.getCompoundObject(epId);
////
////				stmt = this.getConnection().prepareStatement("Components.add(?);");
////				stmt.setObject(1, iObj);
////				stmt.executeUpdate();
////
////				try {
////					Thread.sleep(200);
////				} catch (InterruptedException e) {}
////			}
////
////			return epId;
////		} catch (SQLException e) {
////			throw new EPManagerException("Error saving compound object", e);
////		}
////	}
////
////	private String createRandomId() {
////		return UUID.randomUUID().toString();
////	}
////
////	private List<InformationObject> performQuery(PreparedStatement stmt) throws SQLException {
////		List<InformationObject> list = new ArrayList<InformationObject>();
////
////		ResultSet rs = stmt.executeQuery();
////		while (rs.next()) {
////			list.add((InformationObject) rs.getObject(1));
////		}
////
////		return list;
////	}
////
////	private InformationObject getInformationObject(String docId) throws SQLException {
////		logger.debug("Loading information object for object with id " + docId);
////
////		InformationObject iObj = null;
////
////		PreparedStatement stmt = this.getConnection().prepareStatement("select (ePubs|ePrints|nonEPrints|ResearchData|AggregationObjects)[@dri:objIdentifier=?]");
////		stmt.setString(1, docId);
////		ResultSet rs = stmt.executeQuery();
////
////		if (rs.next()) {
////			iObj = (InformationObject) rs.getObject(1);
////			logger.debug("found information object, id: " + iObj.getId());
////		}
////
////		return iObj;
////	}
////
////	private InformationObject getCompoundObject(String epId) throws SQLException {
////		logger.debug("Loading information object for compound object with id " + epId);
////
////		InformationObject iObj = null;
////
////		PreparedStatement stmt = this.getConnection().prepareStatement("select (ePubs|AggregationObjects)[@dri:objIdentifier=?]");
////		stmt.setString(1, epId);
////		ResultSet rs = stmt.executeQuery();
////
////		if (rs.next()) {
////			iObj = (InformationObject) rs.getObject(1);
////			logger.debug("found information object, id: " + iObj.getId());
////		}
////
////		return iObj;
////	}
////
////	private String getDMF(InformationObject obj) throws SQLException, PublisherServiceException {
////		logger.debug("Getting dmf for information object " + obj.getId());
////
////		String type = obj.getType();
////		String xml = null;
////		PreparedStatement stmt = this.getConnection().prepareStatement("?.exportDMF();");
////		ResultSet innerRs = null;
////
////		stmt.setObject(1, obj);
////		stmt.execute();
////		innerRs = stmt.getResultSet();
////
////		if (innerRs.next()) {
////			logger.debug("result: " + innerRs.getString(1));
////			xml = innerRs.getString(1);
////		} else {
////			logger.warn("Object with id " + obj.getId() + " not found in dlms");
////			return null;
////		}
////
////		logger.debug("Object type: " + type);
////		if (type.equals("EPrintsType") || type.equals("NonEPrintsType")) {
////			logger.debug("Object is textual. Fetching full dmf from publisher");
////			Document doc = documentReader.read(xml);
////
////			xml = publisherServiceLocator.getService().getResourceById(doc.getMap().get("id").get(0), FORMAT);
////		}
////
////		return xml;
////	}
//
//	private Connection getConnection() throws SQLException {
//		if (this.connection == null)
//			connection = dataSource.getConnection();
//		return connection;
//	}
//
//	public void setDataSource(DataSource dataSource) {
//		this.dataSource = dataSource;
//	}
//
//	public void setPublisherServiceLocator(ServiceLocator<PublisherService> publisherServiceLocator) {
//		this.publisherServiceLocator = publisherServiceLocator;
//	}
//
//	public void setDocumentReader(DocumentReader documentReader) {
//		this.documentReader = documentReader;
//	}
//
//	public void setIndexLayoutManager(IndexLayoutManager indexLayoutManager) {
//		this.indexLayoutManager = indexLayoutManager;
//	}
//
//	public void setPropertiesFile(String propertiesFile) {
//		this.propertiesFile = propertiesFile;
//	}
//
//	public void setRepositoryName(String repositoryName) {
//		this.repositoryName = repositoryName;
//	}
//
//	public void setRepositoryInstitution(String repositoryInstitution) {
//		this.repositoryInstitution = repositoryInstitution;
//	}
//}
