Example usage for javax.persistence NoResultException NoResultException

List of usage examples for javax.persistence NoResultException NoResultException

Introduction

In this page you can find the example usage for javax.persistence NoResultException NoResultException.

Prototype

public NoResultException(String message) 

Source Link

Document

Constructs a new NoResultException exception with the specified detail message.

Usage

From source file:org.opencastproject.ingest.endpoint.IngestRestService.java

/**
 * Add an elements to a MediaPackage and keeps track of the progress of the upload. Returns an HTML that triggers the
 * host sites UploadListener.uploadComplete javascript event Returns an HTML that triggers the host sites
 * UploadListener.uplaodFailed javascript event in case of error
 * /*from   w ww .j  ava 2s  . c  o  m*/
 * @param jobId
 *          of the upload job
 * @param request
 *          containing the file, the flavor and the MediaPackage to which it should be added
 * @return HTML that calls the UploadListener.uploadComplete javascript handler
 */
@POST
@Path("addElementMonitored/{jobId}")
@Produces(MediaType.TEXT_HTML)
public Response addElementMonitored(@PathParam("jobId") String jobId, @Context HttpServletRequest request) {
    UploadJob job = null;
    MediaPackage mp = null;
    String fileName = null;
    MediaPackageElementFlavor flavor = null;
    String elementType = "track";
    EntityManager em = null;
    try {
        em = emf.createEntityManager();
        try { // try to get UploadJob, responde 404 if not successful
            // job = em.find(UploadJob.class, jobId);
            if (jobs.containsKey(jobId)) {
                job = jobs.get(jobId);
            } else {
                throw new NoResultException("Job not found");
            }
        } catch (NoResultException e) {
            logger.warn("Upload job not found for Id: " + jobId);
            return buildUploadFailedRepsonse(job);
        }
        if (ServletFileUpload.isMultipartContent(request)) {
            ServletFileUpload upload = new ServletFileUpload();
            UploadProgressListener listener = new UploadProgressListener(job, this.emf);
            upload.setProgressListener(listener);
            for (FileItemIterator iter = upload.getItemIterator(request); iter.hasNext();) {
                FileItemStream item = iter.next();
                String fieldName = item.getFieldName();
                if ("mediaPackage".equalsIgnoreCase(fieldName)) {
                    mp = factory.newMediaPackageBuilder().loadFromXml(item.openStream());
                } else if ("flavor".equals(fieldName)) {
                    String flavorString = Streams.asString(item.openStream());
                    if (flavorString != null) {
                        flavor = MediaPackageElementFlavor.parseFlavor(flavorString);
                    }
                } else if ("elementType".equalsIgnoreCase(fieldName)) {
                    String typeString = Streams.asString(item.openStream());
                    if (typeString != null) {
                        elementType = typeString;
                    }
                } else if ("file".equalsIgnoreCase(fieldName)) {
                    fileName = item.getName();
                    job.setFilename(fileName);
                    if ((mp != null) && (flavor != null) && (fileName != null)) {
                        // decide which element type to add
                        if ("TRACK".equalsIgnoreCase(elementType)) {
                            mp = ingestService.addTrack(item.openStream(), fileName, flavor, mp);
                        } else if ("CATALOG".equalsIgnoreCase(elementType)) {
                            logger.info("Adding Catalog: " + fileName + " - " + flavor);
                            mp = ingestService.addCatalog(item.openStream(), fileName, flavor, mp);
                        }
                        InputStream is = null;
                        try {
                            is = getClass().getResourceAsStream("/templates/complete.html");
                            String html = IOUtils.toString(is, "UTF-8");
                            html = html.replaceAll("\\{mediaPackage\\}", MediaPackageParser.getAsXml(mp));
                            html = html.replaceAll("\\{jobId\\}", job.getId());
                            return Response.ok(html).build();
                        } finally {
                            IOUtils.closeQuietly(is);
                        }
                    }
                }
            }
        } else {
            logger.warn("Job " + job.getId() + ": message is not multipart/form-data encoded");
        }
        return buildUploadFailedRepsonse(job);
    } catch (Exception ex) {
        logger.error(ex.getMessage());
        return buildUploadFailedRepsonse(job);
    } finally {
        if (em != null)
            em.close();
    }
}

From source file:org.rhq.enterprise.server.configuration.ConfigurationManagerBean.java

private Configuration validateResourceConfiguration(Subject subject, int resourceId,
        Configuration configuration, boolean isStructured) throws PluginContainerException {
    Resource resource = entityManager.find(Resource.class, resourceId);
    if (resource == null) {
        throw new NoResultException("Cannot get live configuration for unknown resource [" + resourceId + "]");
    }//from   w  w w.  j  a va 2 s  .  c  o m
    if (!authorizationManager.canViewResource(subject, resource.getId())) {
        throw new PermissionException("User [" + subject.getName()
                + "] does not have permission to view resource configuration for [" + resource + "]");
    }
    Agent agent = resource.getAgent();
    AgentClient agentClient = this.agentManager.getAgentClient(agent);
    ConfigurationAgentService configService = agentClient.getConfigurationAgentService();
    return configService.validate(configuration, resourceId, isStructured);
}

From source file:io.hops.hopsworks.common.util.Settings.java

/**
 * Update a variable in the database./*from  w w  w. j av a 2  s.  c om*/
 *
 * @param variableName name
 * @param variableValue value
 */
private void updateVariableInternal(String variableName, String variableValue) {
    Variables var = findById(variableName);
    if (var == null) {
        throw new NoResultException("Variable <" + variableName + "> does not exist in the database");
    }
    if (!var.getValue().equals(variableValue)) {
        var.setValue(variableValue);
        em.persist(var);
    }
}

From source file:org.rhq.enterprise.server.configuration.ConfigurationManagerBean.java

public Configuration translateResourceConfiguration(Subject subject, int resourceId,
        Configuration configuration, boolean fromStructured) {

    if (!isStructuredAndRawSupported(resourceId)) {
        throw new TranslationNotSupportedException("The translation operation is only supported for "
                + "configurations that support both structured and raw.");
    }/*from w w  w  .  j  av a 2  s .  c  o m*/

    Resource resource = entityManager.find(Resource.class, resourceId);

    if (resource == null) {
        throw new NoResultException("Cannot get live configuration for unknown resource [" + resourceId + "]");
    }

    if (!authorizationManager.hasResourcePermission(subject, Permission.CONFIGURE_READ, resource.getId())) {
        throw new PermissionException("User [" + subject.getName()
                + "] does not have permission to view resource configuration for [" + resource + "]");
    }

    try {
        Agent agent = resource.getAgent();
        AgentClient agentClient = this.agentManager.getAgentClient(agent);
        ConfigurationAgentService configService = agentClient.getConfigurationAgentService();

        return configService.merge(configuration, resourceId, fromStructured);
    } catch (PluginContainerException e) {
        log.error("An error occurred while trying to translate the configuration.", e);
        return null;
    }
}