/** * Creating a KieBase from the workflow GAV specified in the config. * * @return KieBase for package SRAMPPackage * @throws SrampClientException * @throws SrampAtomException */ public KieContainer getKieContainer(ReleaseId releaseId) throws SrampClientException, SrampAtomException { KieServices ks = KieServices.Factory.get(); KieRepository repo = ks.getRepository(); SrampAtomApiClient client = SrampAtomApiClientFactory.createAtomApiClient(); Governance governance = new Governance(); QueryResultSet results = client .buildQuery(SRAMP_KIE_JAR_QUERY) .parameter(governance.getGovernanceWorkflowGroup()) .parameter(governance.getGovernanceWorkflowName()) .parameter(governance.getGovernanceWorkflowVersion()) .count(1) .query(); if (results.size() > 0) { ArtifactSummary artifactSummery = results.get(0); InputStream is = client.getArtifactContent(artifactSummery); KieModule kModule = repo.addKieModule(ks.getResources().newInputStreamResource(is)); logger.info( Messages.i18n.format( "KieSrampUtil.CreatingKieContainer", artifactSummery)); // $NON-NLS-1$ KieContainer kContainer = ks.newKieContainer(kModule.getReleaseId()); // Creating the KieBase for the SRAMPPackage logger.info( Messages.i18n.format( "KieSrampUtil.FindKieBase", governance.getGovernanceWorkflowPackage())); // $NON-NLS-1$ return kContainer; } else { return null; } }
/** * * Gets the artifact content from the s-ramp repository and stores it in the {@link InputData} * object for use by Maven. * * @param gavInfo * @param inputData * @throws TransferFailedException * @throws ResourceDoesNotExistException * @throws AuthorizationException */ private void doGetArtifact(MavenGavInfo gavInfo, InputData inputData) throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException { // RESTEasy uses the current thread's context classloader to load its logger class. This // fails in Maven because the context classloader is the wagon plugin's classloader, which // doesn't know about any of the RESTEasy JARs. So here we're temporarily setting the // context classloader to the s-ramp wagon extension's classloader, which should have access // to all the right stuff. ClassLoader oldCtxCL = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(SrampWagon.class.getClassLoader()); try { // Query the artifact meta data using GAV info BaseArtifactType artifact = findExistingArtifact(client, gavInfo); if (artifact == null) throw new ResourceDoesNotExistException( Messages.i18n.format("ARTIFACT_NOT_FOUND", gavInfo.getName())); // $NON-NLS-1$ this.archive.addEntry(gavInfo.getFullName(), artifact, null); ArtifactType type = ArtifactType.valueOf(artifact); // Get the artifact content as an input stream InputStream artifactContent = client.getArtifactContent(type, artifact.getUuid()); inputData.setInputStream(artifactContent); } catch (ResourceDoesNotExistException e) { throw e; } catch (SrampClientException e) { if (e.getCause() instanceof HttpHostConnectException) { this.debug(Messages.i18n.format("SRAMP_CONNECTION_FAILED", e.getMessage())); // $NON-NLS-1$ } else { this.error(e.getMessage(), e); } throw new ResourceDoesNotExistException( Messages.i18n.format( "FAILED_TO_GET_RESOURCE_FROM_SRAMP", gavInfo.getName())); // $NON-NLS-1$ } catch (Throwable t) { this.error(t.getMessage(), t); } finally { Thread.currentThread().setContextClassLoader(oldCtxCL); } }