package com.yem.ensign.weboffice.dynamic;

import java.util.ArrayList;
import java.util.EventObject;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import kd.bos.form.CloseCallBack;
import kd.bos.form.FormShowParameter;
import kd.bos.form.MessageBoxResult;
import kd.bos.form.ShowType;
import kd.bos.form.control.EntryGrid;
import kd.bos.form.control.Search;
import kd.bos.form.control.TreeView;
import kd.bos.form.control.events.RowClickEvent;
import kd.bos.form.control.events.RowClickEventListener;
import kd.bos.form.control.events.SearchEnterEvent;
import kd.bos.form.control.events.SearchEnterListener;
import kd.bos.form.control.events.TreeNodeClickListener;
import kd.bos.form.control.events.TreeNodeEvent;
import kd.bos.form.control.events.TreeNodeQueryListener;
import kd.bos.form.events.AfterDoOperationEventArgs;
import kd.bos.form.events.BeforeClosedEvent;
import kd.bos.form.events.ClosedCallBackEvent;
import kd.bos.form.events.MessageBoxClosedEvent;
import kd.bos.form.plugin.AbstractFormPlugin;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.QueryServiceHelper;
import kd.bos.servicehelper.operation.OperationServiceHelper;
import kd.bos.servicehelper.runmode.RunModeServiceHelper;
import kd.bos.algo.DataSet;
import kd.bos.algo.Row;
import kd.bos.base.BaseShowParameter;
import kd.bos.bill.BillOperationStatus;
import kd.bos.context.RequestContext;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.dataentity.entity.LocaleString;
import kd.bos.dataentity.resource.ResManager;
import kd.bos.dataentity.utils.StringUtils;
import kd.bos.db.DB;
import kd.bos.db.DBRoute;
import kd.bos.entity.tree.TreeNode;
import kd.bos.entity.AppMetadataCache;
import kd.bos.entity.EntryType;
import kd.bos.entity.datamodel.IDataModel;

/**
 * weboffice列表表单插件
 * @author hdd
 * @date 2020-08-13 下午5:10:12
 */
public class WebOfficeList extends AbstractFormPlugin
		implements TreeNodeQueryListener, TreeNodeClickListener, RowClickEventListener, SearchEnterListener {

	@Override
	public void registerListener(EventObject e) {
		super.registerListener(e);
		TreeView systeTtree = (TreeView) this.getControl("yem_treeviewap");
		systeTtree.addTreeNodeQueryListener(this);
		systeTtree.addTreeNodeClickListener(this);
	}

	@Override
	public void initialize() {
		super.initialize();
		this.addItemClickListeners(new String[] { "yem_main" });
		EntryGrid grid = (EntryGrid) this.getView().getControl("yem_entryentity");
		grid.addRowClickListener(this);
		Search search = (Search) this.getControl("yem_searchap");
		search.addEnterListener(this);
	}

	@Override
	public void beforeClosed(BeforeClosedEvent e) {
		super.beforeClosed(e);
		this.getPageCache().remove("paths");
	}

	@Override
	public void afterCreateNewData(EventObject e) {
		super.afterCreateNewData(e);
	}

	public void afterBindData(EventObject e) {
		super.afterBindData(e);
		
		String localeid = RequestContext.get().getLang().name();
		StringBuilder sql = new StringBuilder();
		sql.append("select a.fid, al.fname ").append("\n");
		sql.append(" from t_meta_bizcloud a ").append("\n");
		sql.append(" inner join t_meta_bizcloud_l al ").append("\n");
		sql.append(" on a.fid = al.fid ").append("\n");
		sql.append(" where al.flocaleid = \'").append(localeid).append("\' ").append("\n");
		sql.append(" and a.fvisible = '1' ").append("\n");

		String cloudBlacklist = RunModeServiceHelper.getCloudIdsFromBlackList();
		if (StringUtils.isNotBlank(cloudBlacklist)) {
			sql.append(" and a.fid not in (").append(cloudBlacklist).append(") ").append("\n");
		}
		sql.append(" and ( exists ( ").append("\n");
		sql.append(" \tselect 1 from t_meta_entitydesign e ").append("\n");
		sql.append(" \tleft join t_meta_bizunitrelform b ").append("\n");
		sql.append(" \ton e.fid = b.fformid ").append("\n");
		sql.append(" \tleft join t_meta_bizapp c ").append("\n");
		sql.append(" \ton b.fbizappid = c.fid  ").append("\n");
		sql.append(" \tLEFT JOIN t_meta_mainentityinfo f  ").append("\n");
		sql.append(" \ton f.fdentityid = b.fformid  ").append("\n");
		sql.append(" \twhere e.fmodeltype IN (\'BillFormModel\', \'BaseFormModel\') ").append("\n");
		sql.append(" \tand  c.fbizcloudid = a.fid ").append("\n");
		sql.append(" \tand  c.fvisible = '1' ").append("\n");
		sql.append(" \tand  e.fistemplate = '0' ").append("\n");
		sql.append(" \tAND  f.fcodenumber = '1' ) ").append("\n");
		sql.append(" ) order by a.fseq asc").append("\n");
		DataSet data = DB.queryDataSet("", DBRoute.meta, sql.toString());
		TreeView tree = (TreeView) this.getView().getControl("yem_treeviewap");
		TreeNode root = new TreeNode();
		root.setParentid("");
		root.setText(
				ResManager.loadKDString("全部", "CodeRuleTreeListPlugin_5", "bos-coderule-formplugin", new Object[0]));
		root.setId("0");
		root.setIsOpened(true);
		while (data.hasNext()) {
			Row row = data.next();
			TreeNode subsystemTreeNode = new TreeNode();
			String id = row.getString("fid");
			String name = row.getString("fname");
			subsystemTreeNode.setParentid("0");
			subsystemTreeNode.setId("1_split_"+id);
			subsystemTreeNode.setText(name);
			subsystemTreeNode.addChildren(new ArrayList());
			subsystemTreeNode.setData(Integer.valueOf(1));
			root.addChild(subsystemTreeNode);
		}
		tree.addNode(root);
		tree.focusNode(root);
		
		afterTreeNodeClick(null, null);
	}

	public void afterDoOperation(AfterDoOperationEventArgs e) {
		super.afterDoOperation(e);
		if (e.getOperationResult() != null && e.getOperationResult().isSuccess()) {
			String opKey = e.getOperateKey();
			if (opKey.equalsIgnoreCase("new")) {
				this.doNew();
			} else if (opKey.equalsIgnoreCase("modify")) {
				this.doModify();
			} else if (opKey.equalsIgnoreCase("delete")) {
				this.doDelete();
			}

		}
	}

	public void closedCallBack(ClosedCallBackEvent closedCallBackEvent) {
		super.closedCallBack(closedCallBackEvent);
		String actionId = closedCallBackEvent.getActionId();
		if (actionId.equalsIgnoreCase("yem_webofficemodel")) {
			Search yem_searchap = this.getControl("yem_searchap");
	        String text = yem_searchap.getSearchKey();
			TreeView tree = (TreeView) this.getView().getControl("yem_treeviewap");
			String nodeId = tree.getTreeState().getFocusNodeId();
			treeNodeClick(nodeId, text);
		}

	}

	public void confirmCallBack(MessageBoxClosedEvent messageBoxClosedEvent) {
		super.confirmCallBack(messageBoxClosedEvent);
		if (StringUtils.equalsIgnoreCase("delete", messageBoxClosedEvent.getCallBackId())
				&& messageBoxClosedEvent.getResult() == MessageBoxResult.Yes) {
			this.doDelete();
		}

	}

	public void treeNodeClick(TreeNodeEvent e) {
		String id = String.valueOf(e.getNodeId());
		treeNodeClick(id, null);
	}
	
	private void treeNodeClick(String id,String filterString) {
		List numbers = new ArrayList();
		if ("0".equals(id)) {
			this.afterTreeNodeClick(numbers, filterString);
		} else {
			int level = Integer.parseInt(id.split("_split_")[0]);
			String trueId = id.split("_split_")[1];
			String[] filters;
			if (level == 1) {
				String map = "select a.fnumber from t_meta_entitydesign a left join t_meta_bizunitrelform b on a.fid = b.fformid  left join t_meta_bizapp c on b.fbizappid = c.fid where c.fbizcloudid = ?\tand  c.fvisible = '1' and a.fistemplate = '0' ";
				String allExtAppId = RunModeServiceHelper.getAppIdFromBlacklist();
				if (StringUtils.isNotBlank(allExtAppId)) {
					map = "select a.fnumber from t_meta_entitydesign a left join t_meta_bizunitrelform b on a.fid = b.fformid  left join t_meta_bizapp c on b.fbizappid = c.fid where c.fbizcloudid = ?\tand  c.fvisible = '1' and a.fistemplate = '0' and c.fid not in ("
							+ allExtAppId + ")";
				}

				filters = new String[] { trueId };
				DataSet data = DB.queryDataSet("", DBRoute.meta, map.toString(), filters);
				while (data.hasNext()) {
					Row row = data.next();
					numbers.add(row.getString("fnumber"));
				}
			} else if (level == 2) {
				StringBuilder arg13 = new StringBuilder(
						"select a.fnumber from t_meta_entitydesign a left join t_meta_bizunitrelform b on a.fid = b.fformid where a.fistemplate = '0' and b.fbizappid in (?");
				List arg14 = getAllExtAppId(trueId);
				filters = new String[arg14.size() + 1];

				for (int arg16 = 0; arg16 < arg14.size() + 1; ++arg16) {
					if (arg16 == 0) {
						filters[0] = trueId;
					} else {
						arg13.append(" ,? ");
						filters[arg16] = (String) arg14.get(arg16 - 1);
					}
				}

				arg13.append(" ) ");
				String arg17 = AppMetadataCache.getAppNumberById(trueId);
				String entityNumBlacklist = RunModeServiceHelper.getEntityNumFromBlacklist(arg17);
				if (StringUtils.isNotBlank(entityNumBlacklist)) {
					arg13.append(" and a.fnumber not in (").append(entityNumBlacklist).append(')');
				}

				DataSet data = DB.queryDataSet("", DBRoute.meta, arg13.toString(), filters);
				while (data.hasNext()) {
					Row row = data.next();
					numbers.add(row.getString("fnumber"));
				}
			} else if (level == 3) {
				Map arg15 = this.getBizObjectById(trueId);
				numbers.add(arg15.get("id"));
			}
			if(numbers.size()==0) {
				numbers.add("无查询数据！");
			}
			this.afterTreeNodeClick(numbers, filterString);
		}
	}

	private void afterTreeNodeClick(List numbers, String filterString) {
		this.getModel().getDataEntity(true);
		IDataModel model = this.getModel();
		DynamicObjectCollection rows = model.getEntryEntity("yem_entryentity");
		rows.clear();
		QFilter qFilter1 = null;
		if(numbers!=null && numbers.size()>0) {
			qFilter1 = new QFilter("yem_bill", "in", numbers);
		}else {
			qFilter1 = new QFilter("yem_bill", "<>", "");
		}
		QFilter qFilter2 = null;
		if(filterString!=null && !"".equals(filterString)) {
			qFilter2 = new QFilter("number", "like", "%"+filterString+"%");
		}else {
			qFilter2 = new QFilter("yem_bill", "<>", "");
		}
		DynamicObject[] webofficemodels = BusinessDataServiceHelper.load("yem_webofficemodel","id,number,name,yem_bill",new QFilter[]{qFilter1,qFilter2});
		if(webofficemodels!=null && webofficemodels.length>0) {
			EntryType entryType = (EntryType) this.getModel().getDataEntityType().getAllEntities().get("yem_entryentity");
			int seq = 1;
			for(int i =0;i<webofficemodels.length;i++) {
				DynamicObject path = webofficemodels[i];
				DynamicObject row = new DynamicObject(entryType);
				row.set("seq", Integer.valueOf(seq));
				row.set("yem_number", path.get("number"));
				row.set("yem_name", path.get("name"));
				row.set("yem_billid", path.get("id"));
				row.set("yem_bill", path.get("yem_bill"));
				rows.add(row);
			}
		}
		this.getView().updateView("yem_entryentity");
	}

	public static List<String> getAllExtAppId(String originalAppId) {
		StringBuilder sb = (new StringBuilder("select fid from t_meta_bizapp where fmasterid = \'"))
				.append(originalAppId).append('\'').append(" and fid <> \'").append(originalAppId).append('\'');
		ArrayList result = new ArrayList();
		DataSet data = DB.queryDataSet("", DBRoute.meta, sb.toString());
		while (data.hasNext()) {
			Row row = data.next();
			result.add(row.getString("fid"));
		}
		return result;
	}

	private Map<String, String> getBizObjectById(String id) {
		Map map = new HashMap();
		StringBuilder sql = new StringBuilder();
		sql.append(" SELECT a.fid, b.fname,a.fcodenumber from t_meta_mainentityinfo a ");
		sql.append(" INNER JOIN t_meta_mainentityinfo_l b on (a.fid = b.fid and b.flocaleid = ?) ");
		sql.append(" where a.fdentityid = ? ");
		sql.append(" and a.fistemplate = '0'  ");
		sql.append(" and a.fmodeltype in (\'BaseFormModel\', \'BillFormModel\') ");
		String[] filters = new String[] { RequestContext.get().getLang().name(), id };
		DataSet data = DB.queryDataSet("", DBRoute.meta, sql.toString(), filters);
		while (data.hasNext()) {
			Row row = data.next();
			map.put("id", row.getString("fid"));
			map.put("name", row.getString("fname"));
			map.put("number", row.getString("fcodenumber"));
		}
		return map;
	}

	public void treeNodeDoubleClick(TreeNodeEvent e) {
	}

	public void entryRowClick(RowClickEvent evt) {
	}

	public void entryRowDoubleClick(RowClickEvent evt) {
		doModify();
	}

	public List<String> getSearchList(SearchEnterEvent e) {
		Search search = (Search) e.getSource();
		if (StringUtils.equals("searchpath", search.getKey())) {
			String searchText = e.getText();
			return StringUtils.isNotBlank(searchText) ? this.doSearchList(searchText) : null;
		} else {
			return null;
		}
	}
	
	private List<String> doSearchList(String searchText) {
		HashSet searchList = new HashSet();
		if (StringUtils.isBlank(searchText)) {
			return new ArrayList();
		} else {

			return new ArrayList(searchList);
		}
	}

	@Override
	public void search(SearchEnterEvent e) {
		Search search = (Search) e.getSource();
		if (StringUtils.equals("yem_searchap", search.getKey())) {
			TreeView treeView = (TreeView) this.getControl("yem_treeviewap");
			Map treeMap = treeView.getTreeState().getFocusNode();
			String id = treeMap.get("id").toString();
			treeNodeClick(id, e.getText());
		}
	}

	private void doNew() {
		TreeView treeView = (TreeView) this.getControl("yem_treeviewap");
		Map treeMap = treeView.getTreeState().getFocusNode();
		boolean isParent = (boolean) treeMap.get("isParent");
		if(!isParent) {
			String id = treeMap.get("id").toString().split("_split_")[1];
			Map map = this.getBizObjectById(id);
			String yem_bill = map.get("id").toString();
			BaseShowParameter baseShowParameter = new BaseShowParameter();
			baseShowParameter.setFormId("yem_webofficemodel");
			baseShowParameter.getOpenStyle().setShowType(ShowType.Modal);
			baseShowParameter.setBillStatus(BillOperationStatus.ADDNEW);
			baseShowParameter.setBillStatusValue(1);
			baseShowParameter.setCustomParam("yem_bill", yem_bill);
			CloseCallBack callBack = new CloseCallBack(this, "yem_webofficemodel");
			baseShowParameter.setCloseCallBack(callBack);
			this.getView().showForm(baseShowParameter);
		}else {
            this.getView().showErrorNotification("请先选择业务单据节点！");
            return;
		}
	}

	private void doModify() {
		int rowCount = this.getModel().getEntryRowCount("yem_entryentity");
		if (rowCount != 0) {
			int rowIndex = this.getModel().getEntryCurrentRowIndex("yem_entryentity");
			long id = (long) this.getModel().getValue("yem_billid", rowIndex);
			BaseShowParameter baseShowParameter = new BaseShowParameter();
			baseShowParameter.setFormId("yem_webofficemodel");
			baseShowParameter.getOpenStyle().setShowType(ShowType.Modal);
			baseShowParameter.setBillStatus(BillOperationStatus.EDIT);
			baseShowParameter.setBillStatusValue(1);
			baseShowParameter.setPkId(id);
			CloseCallBack callBack = new CloseCallBack(this, "yem_webofficemodel");
			baseShowParameter.setCloseCallBack(callBack);
			this.getView().showForm(baseShowParameter);
		}
	}

	private void showRuleForm(String id) {
		if (!StringUtils.isBlank(id)) {
			FormShowParameter showParameter = new FormShowParameter();
			showParameter.setFormId("yem_webofficemodel");
			showParameter.getOpenStyle().setShowType(ShowType.MainNewTabPage);
			showParameter.setCustomParam("id", id);
			showParameter.getCustomParams().put("checkRightAppId", "bpm");
			this.getView().showForm(showParameter);
		}
	}

	private void doBeforeDelete() {
		
	}

	private void doDelete() {
		int rowCount = this.getModel().getEntryRowCount("yem_entryentity");
		if (rowCount != 0) {
			int rowIndex = this.getModel().getEntryCurrentRowIndex("yem_entryentity");
			long yem_billid = (long) this.getModel().getValue("yem_billid", rowIndex);
			DynamicObject webofficemodel = BusinessDataServiceHelper.loadSingle(yem_billid,"yem_webofficemodel");
			String status = webofficemodel.getString("status");
			if("B".equals(status)) {
	            this.getView().showErrorNotification("单据已提交，不允许删除！");
	            return;
			}else if("C".equals(status)) {
	            this.getView().showErrorNotification("单据已审核，不允许删除！");
	            return;
			}
			Object [] idsObj = new Object[] {webofficemodel.getPkValue()};
			OperationServiceHelper.executeOperate("delete", "yem_webofficemodel", idsObj , null);
			
			Search yem_searchap = this.getControl("yem_searchap");
	        String text = yem_searchap.getSearchKey();
			TreeView tree = (TreeView) this.getView().getControl("yem_treeviewap");
			String nodeId = tree.getTreeState().getFocusNodeId();
			treeNodeClick(nodeId, text);
		}
	}	

	@Override
	public void queryTreeNodeChildren(TreeNodeEvent treeNodeEvent) {
		TreeView treeView = (TreeView) treeNodeEvent.getSource();
		String parentId = String.valueOf(treeNodeEvent.getNodeId());
		String localeid = RequestContext.get().getLang().name();
		int level = Integer.parseInt(parentId.split("_split_")[0]);
		String parentTrueId = parentId.split("_split_")[1];
		QFilter[] qfArr = new QFilter[1];
		DynamicObject[] load = null;
		List allExtAppId;
		DynamicObject name;
		if (level == 1) {
			allExtAppId = this.findBizappExistsEntity(parentTrueId);
			qfArr[0] = new QFilter("id", "in", allExtAppId);
			qfArr = RunModeServiceHelper.getAppIdBlacklistFilters(qfArr, "id");
			load = BusinessDataServiceHelper.load("bos_devportal_bizapp", "", qfArr, "sequence");
		} else if (level == 2) {
			allExtAppId = getAllExtAppId(parentTrueId);
			allExtAppId.add(parentTrueId);
			qfArr[0] = new QFilter("bizapp", "in", allExtAppId);
			qfArr = RunModeServiceHelper.getEntityIdBlacklistFilters(qfArr, "form");
			load = BusinessDataServiceHelper.load("bos_devportal_unitrelform", "form", qfArr);
			HashSet idSet = new HashSet(load.length);
			DynamicObject[] qFilters = load;
			int obj = load.length;

			for (int childrenDataTree = 0; childrenDataTree < obj; ++childrenDataTree) {
				name = qFilters[childrenDataTree];
				idSet.add(name.get("form"));
			}

			QFilter[] arg19 = new QFilter[] { new QFilter("dentityid", "in", idSet) };
			DynamicObject[] arg21 = BusinessDataServiceHelper.load("bos_entityinfo",
					"id,codenumber,modeltype,dentityid", arg19);
			idSet = new HashSet();
			DynamicObject[] arg23 = arg21;
			int arg25 = arg21.length;

			int formId;
			for (formId = 0; formId < arg25; ++formId) {
				DynamicObject map = arg23[formId];
				if (map.getBoolean("codenumber")) {
					idSet.add(map.get("dentityid"));
				}
			}

			ArrayList arg24 = new ArrayList();
			DynamicObject[] arg27 = load;
			formId = load.length;

			for (int arg30 = 0; arg30 < formId; ++arg30) {
				DynamicObject dynamicObject = arg27[arg30];
				if (idSet.contains(dynamicObject.get("form"))) {
					arg24.add(dynamicObject);
				}
			}

			load = new DynamicObject[arg24.size()];

			for (arg25 = 0; arg25 < arg24.size(); ++arg25) {
				load[arg25] = (DynamicObject) arg24.get(arg25);
			}

			load = this.buildDynamicsWithFilter(load);
		}

		if (load != null) {
			DynamicObject[] arg17 = load;
			int arg18 = load.length;

			for (int arg20 = 0; arg20 < arg18; ++arg20) {
				DynamicObject arg22 = arg17[arg20];
				if (arg22 != null) {
					TreeNode arg26 = new TreeNode();
					arg26.setParentid(String.valueOf(parentId));
					name = null;
					if (level == 1) {
						arg26.addChildren(new ArrayList());
						arg26.setId("2_split_" + (String) arg22.get("id"));
						LocaleString arg28 = AppMetadataCache.getAppInfo(arg22.get("id") + "").getName();
						arg26.setText((String) arg28.get(localeid));
					} else if (level == 2) {
						String arg29 = (String) arg22.get("form");
						Map arg31 = this.getBizObjectById(arg29);
						if (!arg31.isEmpty()) {
							arg26.setId("3_split_" + arg29);
							arg26.setText((String) arg31.get("name"));
						} else {
							arg26 = null;
						}
					}

					if (arg26 != null) {
						treeView.addNode(arg26);
					}
				}
			}
		}
	}

	private List<String> findBizappExistsEntity(String bizCloudId) {
		StringBuilder sql = new StringBuilder();
		sql.append("SELECT A.FID, A.FMASTERID ");
		sql.append(" FROM T_META_BIZAPP A");
		sql.append(" WHERE A.FBIZCLOUDID = ?");
		sql.append(" AND a.fdeploystatus = '2' ");
		sql.append(" AND ( EXISTS (  ");
		sql.append(" \tSELECT 1 FROM T_META_ENTITYDESIGN E");
		sql.append(" \tLEFT JOIN T_META_BIZUNITRELFORM B  ");
		sql.append(" \tON E.FID = B.FFORMID  ");
		sql.append(" \tLEFT JOIN t_meta_mainentityinfo f  ");
		sql.append(" \ton f.fdentityid = b.fformid  ");
		sql.append(" \tWHERE  B.FBIZAPPID = A.FID ");
		sql.append(" \tAND E.FMODELTYPE IN ('BillFormModel', 'BaseFormModel') ");
		sql.append(" \tAND e.FISTEMPLATE = '0'");
		sql.append(" \tAND f.fcodenumber = '1' ) ");
		sql.append(" )");
		String[] filters = new String[] { bizCloudId };
		DataSet data = DB.queryDataSet("", DBRoute.meta, sql.toString(), filters);
		Set idSet = new HashSet();
		while (data.hasNext()) {
			Row row = data.next();
			idSet.add(row.getString("FID"));
		}
		return new ArrayList(idSet);
	}
	
	private DynamicObject[] buildDynamicsWithFilter(DynamicObject[] load) {
		LinkedHashMap dynamicMaps = new LinkedHashMap();
		if (load != null && load.length > 0) {
			DynamicObject[] entitymetaQFilter = load;
			int dynamicObjects = load.length;

			for (int idsFromEntitymeta = 0; idsFromEntitymeta < dynamicObjects; ++idsFromEntitymeta) {
				DynamicObject newLoad = entitymetaQFilter[idsFromEntitymeta];
				dynamicMaps.put(newLoad.getString("form"), newLoad);
			}
		}

		QFilter[] arg9 = new QFilter[]{new QFilter("id", "in", dynamicMaps.keySet())};
		DynamicObjectCollection arg10 = QueryServiceHelper.query("bos_entitymeta", "id", arg9);
		
		Set arg11 = new HashSet();
		if(arg10!=null && arg10.size()>0) {
			for(int i =0;i<arg10.size();i++) {
				arg11.add(arg10.get(i).get("id"));
			}
		}
		DynamicObject[] arg12 = new DynamicObject[arg10.size()];
		int j = 0;
		Iterator arg7 = dynamicMaps.entrySet().iterator();

		while (arg7.hasNext()) {
			Entry entry = (Entry) arg7.next();
			if (arg11.contains(entry.getKey())) {
				arg12[j++] = (DynamicObject) entry.getValue();
			}
		}

		return arg12;
	}
}
