| /* |
| * |
| * Copyright (c) 2013, 2016 - Loetz GmbH&Co.KG, 69115 Heidelberg, Germany |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation |
| * |
| */ |
| |
| package org.eclipse.osbp.xtext.datamartdsl.util |
| |
| import java.util.HashMap |
| import org.eclipse.osbp.xtext.datamartdsl.EventBrokerDataMart |
| import javax.inject.Inject |
| import org.eclipse.osbp.xtext.datamartdsl.jvmmodel.DatamartDSLJvmModelInferrer |
| import org.eclipse.emf.common.util.EList |
| import java.util.ArrayList |
| import org.eclipse.emf.ecore.EObject |
| |
| class EventBrokerDatamartUtils { |
| |
| @Inject extension DatamartDSLJvmModelInferrer datamartInferrer |
| |
| def HashMap<String, String> getUsedFilterInDatamart(EventBrokerDataMart datamart, HashMap<String, String> filterIdMap){ |
| var usedFilterIdMap = <String, String>newHashMap() |
| for (filter : filterIdMap.entrySet){ |
| if (datamart.filter.equals(filter.value)){ |
| usedFilterIdMap.put(filter.key, filter.value); |
| } |
| } |
| return usedFilterIdMap |
| } |
| |
| def HashMap<String,String> getFilterMap(EventBrokerDataMart datamart){ |
| var filterIdMap = new HashMap<String, String> |
| datamartInferrer.createFilterMap(datamart.getDatamartDef, filterIdMap) |
| return filterIdMap |
| } |
| |
| def void removeAlreadyUsedFilter(EList<EventBrokerDataMart> datamarts, HashMap<String, HashMap<String, String>> datamartsFilterMap){ |
| for (EventBrokerDataMart dat : datamarts) { |
| if (dat.filter!=null){ |
| // remove the already default used filter of the root organization |
| var filterIdMap = (datamartsFilterMap.get(dat.datamartDef.name) as HashMap<String,String>) |
| // if key is already removed |
| if (filterIdMap!=null){ |
| var filterIdMapTemp = (filterIdMap.clone as HashMap<String,String>) |
| for (filter : filterIdMapTemp.entrySet){ |
| if (dat.filter.equals(filter.value)){ |
| filterIdMap.remove(filter.key); |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| def HashMap<String, String> getFilterMap(EList<EventBrokerDataMart> datamarts){ |
| var filterMap = <String, String>newHashMap |
| return datamarts.getFilterMap(filterMap) |
| } |
| |
| def HashMap<String, String> getFilterMap(EList<EventBrokerDataMart> datamarts, HashMap<String, String> filterMap){ |
| if (filterMap!=null){ |
| for (datamart : datamarts){ |
| filterMap.putAll(datamart.getUsedFilterInDatamart(datamart.filterMap)) |
| } |
| } |
| return filterMap |
| } |
| |
| def HashMap<String, HashMap<String,String>> getUsedFilterMap(EList<EventBrokerDataMart> datamarts){ |
| var usedFilterMap = <String, HashMap<String,String>>newHashMap() |
| for (EventBrokerDataMart dat : datamarts) { |
| if (dat!=null && dat.datamartDef!=null){ |
| usedFilterMap.put(dat.datamartDef.name, dat.filterMap) |
| } |
| } |
| return usedFilterMap; |
| } |
| |
| def void fillResultWithFilter(EList<EventBrokerDataMart> datamarts, HashMap<String, HashMap<String,String>> usedDatamartsFilterMap, ArrayList<EObject> result){ |
| for (EventBrokerDataMart dat : datamarts) { |
| // If datamart filter list has more than 1 filter. Because otherwise that filter is the |
| // default filter for all positions and no other filter is possible to use for a multiple position |
| if (dat!=null && dat.datamartDef!=null && usedDatamartsFilterMap.containsKey(dat.datamartDef.name) && !usedDatamartsFilterMap.get(dat.datamartDef.name).empty){ |
| result.add(dat.datamartDef) |
| } |
| } |
| |
| } |
| |
| def getEventBrokerMsgs(EList<EventBrokerDataMart> datamarts)''' |
| «FOR datamart : datamarts» |
| eventBroker.send("«datamart.filter»/clear", selectedItem); |
| eventBroker.send("«datamart.filter»", selectedItem); |
| «ENDFOR» |
| ''' |
| |
| |
| } |