Example usage for org.springframework.core.io ClassPathResource getFilename

List of usage examples for org.springframework.core.io ClassPathResource getFilename

Introduction

In this page you can find the example usage for org.springframework.core.io ClassPathResource getFilename.

Prototype

@Override
@Nullable
public String getFilename() 

Source Link

Document

This implementation returns the name of the file that this class path resource refers to.

Usage

From source file:org.openlmis.fulfillment.web.TemplateControllerIntegrationTest.java

@Test
public void shouldAddReportTemplate() throws IOException {
    ClassPathResource podReport = new ClassPathResource("jasperTemplates/proofOfDelivery.jrxml");

    try (InputStream podStream = podReport.getInputStream()) {
        restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader())
                .contentType(MediaType.MULTIPART_FORM_DATA_VALUE)
                .multiPart("file", podReport.getFilename(), podStream)
                .formParam("name", TEMPLATE_CONTROLLER_TEST).formParam("description", TEMPLATE_CONTROLLER_TEST)
                .when().post(RESOURCE_URL).then().statusCode(200);
    }//from   w  ww.  j  a va2 s.  c  o m

    assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations());
}

From source file:py.una.pol.karaku.test.cucumber.DatabasePopulatorCucumberExecutionListener.java

/**
 * @param cpr/*from w  w w .  java  2  s  .  c om*/
 * @param br
 * @return
 */
private BufferedReader _getBr(ClassPathResource cpr) {

    try {
        return new BufferedReader(new InputStreamReader(cpr.getInputStream(), "UTF-8"));
    } catch (UnsupportedEncodingException e) {
        throw new KarakuRuntimeException(e);
    } catch (IOException e) {
        throw new KarakuRuntimeException("Can not load the file " + cpr.getFilename(), e);
    }
}

From source file:org.openlmis.fulfillment.web.TemplateControllerIntegrationTest.java

@Test
public void shouldReturnBadRequestWhenTemplateExist() throws IOException {
    ClassPathResource podReport = new ClassPathResource("jasperTemplates/proofOfDelivery.jrxml");

    given(templateRepository.findByName(TEMPLATE_CONTROLLER_TEST)).willReturn(new Template());
    try (InputStream podStream = podReport.getInputStream()) {
        restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader())
                .contentType(MediaType.MULTIPART_FORM_DATA_VALUE)
                .multiPart("file", podReport.getFilename(), podStream)
                .formParam("name", TEMPLATE_CONTROLLER_TEST).formParam("description", TEMPLATE_CONTROLLER_TEST)
                .when().post(RESOURCE_URL).then().statusCode(400);
    }/*from w  w w .  j av a  2  s .  c  om*/

    assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations());
}

From source file:com.sirma.itt.cmf.integration.workflow.alfresco4.CMFWorkflowDeployer.java

/**
 * Deploy from properties.// w w  w.ja v  a 2s. co  m
 * 
 * @param workflowDefinition
 *            the workflow definition
 * @return the workflow definition
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
private WorkflowDefinition deployFromProperties(Properties workflowDefinition) throws IOException {
    // retrieve workflow specification
    String engineId = workflowDefinition.getProperty(ENGINE_ID);
    if (engineId == null || engineId.length() == 0) {
        throw new WorkflowException("Workflow Engine Id must be provided");
    }

    String location = workflowDefinition.getProperty(LOCATION);
    if (location == null || location.length() == 0) {
        throw new WorkflowException("Workflow definition location must be provided");
    }
    if (workflowAdminService.isEngineEnabled(engineId)) {
        Boolean redeploy = Boolean.valueOf(workflowDefinition.getProperty(REDEPLOY));
        String mimetype = workflowDefinition.getProperty(MIMETYPE);

        // retrieve input stream on workflow definition
        ClassPathResource workflowResource = new ClassPathResource(location);

        // deploy workflow definition
        if (!redeploy && workflowService.isDefinitionDeployed(engineId, workflowResource.getInputStream(),
                mimetype)) {
            if (logger.isDebugEnabled())
                logger.debug("Workflow deployer: Definition '" + location + "' already deployed");
        } else {
            if (!redeploy && workflowService.isDefinitionDeployed(engineId, workflowResource.getInputStream(),
                    mimetype)) {
                logger.debug("Workflow deployer: Definition '" + location + "' already deployed");
            } else {
                WorkflowDeployment deployment = workflowService.deployDefinition(engineId,
                        workflowResource.getInputStream(), mimetype, workflowResource.getFilename());
                getDefinitionToWorkflowMapping().put(deployment.getDefinition(), workflowDefinition);

                logDeployment(location, deployment);
                return deployment.getDefinition();
            }
        }
    } else {
        logger.debug("Workflow deployer: Definition '" + location + "' not deployed as the '" + engineId
                + "' engine is disabled");
    }
    return null;
}

From source file:com.sirma.itt.cmf.integration.alfresco3.CMFWorkflowDeployer.java

/**
 * Deploy the Workflow Definitions./*from  ww w .j  av a2s .c o  m*/
 */
public void init() {
    PropertyCheck.mandatory(this, "transactionService", transactionService);
    PropertyCheck.mandatory(this, "authenticationContext", authenticationContext);
    PropertyCheck.mandatory(this, "workflowService", workflowService);

    String currentUser = authenticationContext.getCurrentUserName();
    if (currentUser == null) {
        authenticationContext.setSystemUserAsCurrentUser();
    }
    if (!transactionService.getAllowWrite()) {
        if (logger.isWarnEnabled())
            logger.warn("Repository is in read-only mode; not deploying workflows.");

        return;
    }

    UserTransaction userTransaction = transactionService.getUserTransaction();
    try {
        userTransaction.begin();

        // bootstrap the workflow models and static labels (from classpath)
        if (models != null && resourceBundles != null
                && ((models.size() > 0) || (resourceBundles.size() > 0))) {
            DictionaryBootstrap dictionaryBootstrap = new DictionaryBootstrap();
            dictionaryBootstrap.setDictionaryDAO(dictionaryDAO);
            dictionaryBootstrap.setTenantService(tenantService);
            dictionaryBootstrap.setModels(models);
            dictionaryBootstrap.setLabels(resourceBundles);
            dictionaryBootstrap.bootstrap(); // also registers with
            // dictionary
        }

        // bootstrap the workflow definitions (from classpath)
        if (workflowDefinitions != null) {
            for (Properties workflowDefinition : workflowDefinitions) {
                // retrieve workflow specification
                String engineId = workflowDefinition.getProperty(ENGINE_ID);
                if (engineId == null || engineId.length() == 0) {
                    throw new WorkflowException("Workflow Engine Id must be provided");
                }

                String location = workflowDefinition.getProperty(LOCATION);
                if (location == null || location.length() == 0) {
                    throw new WorkflowException("Workflow definition location must be provided");
                }

                Boolean redeploy = Boolean.valueOf(workflowDefinition.getProperty(REDEPLOY));
                String mimetype = workflowDefinition.getProperty(MIMETYPE);

                // retrieve input stream on workflow definition
                ClassPathResource workflowResource = new ClassPathResource(location);

                // deploy workflow definition
                if (!redeploy && workflowService.isDefinitionDeployed(engineId,
                        workflowResource.getInputStream(), mimetype)) {
                    if (logger.isDebugEnabled())
                        logger.debug("Workflow deployer: Definition '" + location + "' already deployed");
                } else {
                    if (!redeploy && workflowService.isDefinitionDeployed(engineId,
                            workflowResource.getInputStream(), mimetype)) {
                        if (logger.isDebugEnabled())
                            logger.debug("Workflow deployer: Definition '" + location + "' already deployed");
                    } else {
                        WorkflowDeployment deployment = workflowService.deployDefinition(engineId,
                                workflowResource.getInputStream(), workflowResource.getFilename());
                        logDeployment(location, deployment);
                    }
                }

            }
        }

        userTransaction.commit();
    } catch (Throwable e) {
        // rollback the transaction
        try {
            if (userTransaction != null) {
                userTransaction.rollback();
            }
        } catch (Exception ex) {
            // NOOP
        }
    } finally {
        if (currentUser == null) {
            authenticationContext.clearCurrentSecurityContext();
        }
    }
}

From source file:org.alfresco.repo.workflow.WorkflowDeployer.java

/**
 * Deploy the Workflow Definitions//from  ww w . j  a  va2  s  .com
 */
public void init() {
    PropertyCheck.mandatory(this, "transactionService", transactionService);
    PropertyCheck.mandatory(this, "authenticationContext", authenticationContext);
    PropertyCheck.mandatory(this, "workflowService", workflowService);

    String currentUser = authenticationContext.getCurrentUserName();
    if (currentUser == null) {
        authenticationContext.setSystemUserAsCurrentUser();
    }
    if ((!transactionService.getAllowWrite())
            && (AlfrescoTransactionSupport.getTransactionReadState() != TxnReadState.TXN_READ_WRITE)) {
        if (logger.isWarnEnabled())
            logger.warn("Repository is in read-only mode; not deploying workflows.");

        return;
    }

    UserTransaction userTransaction = transactionService.getUserTransaction();
    try {
        userTransaction.begin();

        // bootstrap the workflow models and static labels (from classpath)
        if (models != null && resourceBundles != null
                && ((models.size() > 0) || (resourceBundles.size() > 0))) {
            DictionaryBootstrap dictionaryBootstrap = new DictionaryBootstrap();
            dictionaryBootstrap.setDictionaryDAO(dictionaryDAO);
            dictionaryBootstrap.setTenantService(tenantService);
            dictionaryBootstrap.setModels(models);
            dictionaryBootstrap.setLabels(resourceBundles);
            dictionaryBootstrap.bootstrap(); // also registers with dictionary

            // MNT-10537 fix, since new model was deployed we need to destroy dictionary to force lazy re-init 
            AlfrescoTransactionSupport.bindListener(this.workflowDeployerTransactionListener);
        }

        // bootstrap the workflow definitions (from classpath)
        if (workflowDefinitions != null) {
            for (Properties workflowDefinition : workflowDefinitions) {
                // retrieve workflow specification
                String engineId = workflowDefinition.getProperty(ENGINE_ID);
                if (engineId == null || engineId.length() == 0) {
                    throw new WorkflowException("Workflow Engine Id must be provided");
                }

                String location = workflowDefinition.getProperty(LOCATION);
                if (location == null || location.length() == 0) {
                    throw new WorkflowException("Workflow definition location must be provided");
                }

                if (workflowAdminService.isEngineEnabled(engineId)) {
                    Boolean redeploy = Boolean.valueOf(workflowDefinition.getProperty(REDEPLOY));
                    String mimetype = workflowDefinition.getProperty(MIMETYPE);

                    // retrieve input stream on workflow definition
                    ClassPathResource workflowResource = new ClassPathResource(location);

                    // deploy workflow definition
                    if (!redeploy && workflowService.isDefinitionDeployed(engineId,
                            workflowResource.getInputStream(), mimetype)) {
                        if (logger.isDebugEnabled())
                            logger.debug("Workflow deployer: Definition '" + location + "' already deployed");
                    } else {
                        WorkflowDeployment deployment = workflowService.deployDefinition(engineId,
                                workflowResource.getInputStream(), mimetype, workflowResource.getFilename());
                        logDeployment(location, deployment);
                    }
                } else {
                    if (logger.isDebugEnabled())
                        logger.debug("Workflow deployer: Definition '" + location + "' not deployed as the '"
                                + engineId + "' engine is disabled");
                }
            }
        }

        // deploy workflow definitions from repository (if any)
        if (repoWorkflowDefsLocation != null) {
            StoreRef storeRef = repoWorkflowDefsLocation.getStoreRef();
            NodeRef rootNode = nodeService.getRootNode(storeRef);
            List<NodeRef> nodeRefs = searchService
                    .selectNodes(rootNode,
                            repoWorkflowDefsLocation.getPath() + CRITERIA_ALL + "["
                                    + defaultSubtypeOfWorkflowDefinitionType + "]",
                            null, namespaceService, false);

            if (nodeRefs.size() > 0) {
                for (NodeRef nodeRef : nodeRefs) {
                    deploy(nodeRef, false);
                }
            }
        }

        userTransaction.commit();
    } catch (Throwable e) {
        // rollback the transaction
        try {
            if (userTransaction != null) {
                userTransaction.rollback();
            }
        } catch (Exception ex) {
            // NOOP 
        }
        throw new AlfrescoRuntimeException("Workflow deployment failed", e);
    } finally {
        if (currentUser == null) {
            authenticationContext.clearCurrentSecurityContext();
        }
    }
}

From source file:org.metamorfosis.framework.SpringContextTest.java

public void testClassPathResource() throws IOException {
    ClassPathResource resource = new ClassPathResource("templates/internalTemplate.ftl");
    File file = resource.getFile();
    log.debug("classpath file: " + file);
    String filename = resource.getFilename();
    log.debug("filename: " + filename);
    String path = resource.getPath();
    log.debug("path: " + path);
    String absolutePath = file.getAbsolutePath();
    log.debug("absolutePath: " + absolutePath);

    resource = new ClassPathResource("overview.html");
    InputStream inputStream = resource.getInputStream();
    log.debug(inputStream);/* ww w  .j ava 2s .com*/
}