package eu.dnetlib.data.collective.transformation.utils; import java.io.StringReader; import java.util.List; import org.apache.commons.lang3.StringEscapeUtils; import eu.dnetlib.common.profile.ProfileNotFoundException; import eu.dnetlib.data.collective.transformation.rulelanguage.RuleLanguageParser; import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException; import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService; import eu.dnetlib.enabling.tools.ServiceLocator; /** * * @author jochen * @since 1.2 */ public class TransformationRulesImportTool { private ServiceLocator lookupServiceLocator; /** * retrieves the transformation rule script of a transformation rule profile identified by a profile id * @param aProfileId * @return list of the transformation rule script and optionally profile id's of subscripts * @throws ProfileNotFoundException */ protected List getScript(String aProfileId) throws ProfileNotFoundException{ String xquery = "collection('/db/DRIVER/TransformationRuleDSResources')//RESOURCE_PROFILE[.//RESOURCE_IDENTIFIER/@value ='" + aProfileId + "']//CODE/child::node(), " + "for $id in (collection('/db/DRIVER/TransformationRuleDSResources')//RESOURCE_PROFILE[.//RESOURCE_IDENTIFIER/@value ='" + aProfileId + "']//IMPORTED/SCRIPT_REFERENCE/@id) return string($id)"; List queryResult; try { queryResult = lookupServiceLocator.getService().quickSearchProfile(xquery); if (!queryResult.isEmpty()){ return queryResult; }else{ throw new ProfileNotFoundException("no script found in profile for profileId: " + aProfileId); } } catch (ISLookUpException e) { throw new ProfileNotFoundException(e); } } protected void importRules(RuleLanguageParser aParser, String aProfileId) throws ProfileNotFoundException{ List profileQueryResult = getScript(aProfileId); String script = StringEscapeUtils.unescapeXml(profileQueryResult.get(0)); // the first entry contains the script if (script.trim().startsWith("