class AuditParser {

	public static List<PerunBean> parseLog(String log) {
		List<PerunBean> listPerunBeans = new ArrayList<PerunBean>();
		PerunBean perunBean = null;
		//Parse log to List of text Beanss
		List<Pair<String, Map<String, String>>> listOfTextBeans = new ArrayList<Pair<String, Map<String, String>>>();
		try {
			listOfTextBeans = beansToMap(log);
		} catch (RuntimeException ex) {
			loger.error("Message " + log + " was not correctly parsed to Map<NameOfBean,BodyOfBean>", ex);
		}
		//For every bean try to find it and create object from text
		for(Pair<String, Map<String, String>> p: listOfTextBeans) {
			try {
				perunBean = null;
				if(p.getLeft().equals("Attribute")) perunBean = createAttribute(p.getRight());
				else if(p.getLeft().equals("AttributeDefinition")) perunBean = createAttributeDefinition(p.getRight());
				else if(p.getLeft().equals("Candidate")) perunBean = createCandidate(p.getRight());
				else if(p.getLeft().equals("Destination")) perunBean = createDestination(p.getRight());
				else if(p.getLeft().equals("ExtSource")) perunBean = createExtSource(p.getRight());
				else if(p.getLeft().equals("RichFacility")) perunBean = createRichFacility(p.getRight());
				else if(p.getLeft().equals("Facility")) perunBean = createFacility(p.getRight());
				else if(p.getLeft().equals("Group")) perunBean = createGroup(p.getRight());
				else if(p.getLeft().equals("Host")) perunBean = createHost(p.getRight());
				else if(p.getLeft().equals("Member")) perunBean = createMember(p.getRight());
				else if(p.getLeft().equals("Owner")) perunBean = createOwner(p.getRight());
				else if(p.getLeft().equals("Resource")) perunBean = createResource(p.getRight());
				else if(p.getLeft().equals("RichDestination")) perunBean = createRichDestination(p.getRight());
				else if(p.getLeft().equals("RichMember")) perunBean = createRichMember(p.getRight());
				else if(p.getLeft().equals("RichUser")) perunBean = createRichUser(p.getRight());
				else if(p.getLeft().equals("RichGroup")) perunBean = createRichGroup(p.getRight());
				else if(p.getLeft().equals("RichResource")) perunBean = createRichResource(p.getRight());
				else if(p.getLeft().equals("Service")) perunBean = createService(p.getRight());
				else if(p.getLeft().equals("User")) perunBean = createUser(p.getRight());
				else if(p.getLeft().equals("UserExtSource")) perunBean = createUserExtSource(p.getRight());
				else if(p.getLeft().equals("Vo")) perunBean = createVo(p.getRight());
				else if(p.getLeft().equals("Authorship")) perunBean = createAuthorship(p.getRight());
				else if(p.getLeft().equals("ResourceTag")) perunBean = createResourceTag(p.getRight());
				else if(p.getLeft().equals("SecurityTeam")) perunBean = createSecurityTeam(p.getRight());
				else if(p.getLeft().equals("TaskResult")) perunBean = createTaskResult(p.getRight());
				else if(p.getLeft().equals("BanOnResource")) perunBean = createBanOnResource(p.getRight());
				else if(p.getLeft().equals("BanOnFacility")) perunBean = createBanOnFacility(p.getRight());
				else loger.debug("Object of this type can't be parsed cause there is no such object in parser's branches. ObjectName:" + p.getLeft());
				if(perunBean != null) listPerunBeans.add(perunBean);
			} catch (RuntimeException e) {
				loger.error("Object name " + p.getLeft() + " with attributes " + p.getRight() + " was not parsed due to fail {} ", e);
			}
		}
		return listPerunBeans;
	}

}