blob: 97a3967f5083cdc285ee8edd7bfd2a2b5994fc34 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.mdm.api.atfxadapter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import org.asam.ods.AoException;
import org.asam.ods.AoSession;
import org.asam.ods.ApplicationElement;
import org.asam.ods.InstanceElement;
import org.asam.ods.InstanceElementIterator;
import org.asam.ods.Relationship;
/**
* @author akn
*
*/
public class NameHelper {
private static final Pattern PATTERN_TESTSTEP_ASAM_PATH = Pattern.compile(
"\\/\\[Environment\\].+\\/\\[Project\\](.+)\\/\\[StructureLevel\\](.+)\\/\\[Test\\](.+)\\/\\[TestStep\\](.+)");
private final AoSession aoSession;
private final String compName;
private final String attrName;
private Map<String, String> asamAttrCache = new HashMap<>();
/**
* @param aoSession
* @param property
* @throws AoException
*/
public NameHelper(AoSession aoSession, String compName, String attrName) throws AoException {
super();
this.aoSession = aoSession;
this.compName = compName;
this.attrName = attrName;
initCache();
}
private void initCache() throws AoException {
ApplicationElement testStep = this.aoSession.getApplicationStructure().getElementByName("TestStep");
InstanceElementIterator testStepInstances = testStep.getInstances("*");
List<InstanceElement> relatedIE = new ArrayList<>();
for (InstanceElement ie : testStepInstances.nextN(testStepInstances.getCount())) {
relatedIE.add(ie);
relatedIE.addAll(getParentIntances(ie));
}
int i = 0;
}
private List<InstanceElement> getParentIntances(InstanceElement ie) throws AoException {
List<InstanceElement> returnVal = new ArrayList<>();
InstanceElementIterator ieIterator = ie.getRelatedInstancesByRelationship(Relationship.FATHER, "*");
if (ieIterator != null && ieIterator.getCount() > 0) {
for (InstanceElement ieParent : ieIterator.nextN(ieIterator.getCount())) {
returnVal.add(ie);
returnVal.addAll(getParentIntances(ie));
}
}
return returnVal;
}
}