Example usage for java.util NoSuchElementException getMessage

List of usage examples for java.util NoSuchElementException getMessage

Introduction

In this page you can find the example usage for java.util NoSuchElementException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:de.zib.gndms.dspace.service.SliceServiceImpl.java

@Override
@RequestMapping(value = "/_{subspaceId}/_{sliceKindId}/_{sliceId}/directory", method = RequestMethod.GET)
@Secured("ROLE_USER")
public ResponseEntity<String> getRelativeDirectoryPath(@PathVariable final String subspaceId,
        @PathVariable final String sliceKindId, @PathVariable final String sliceId,
        @RequestHeader("DN") final String dn) {
    GNDMSResponseHeader headers = setHeaders(subspaceId, sliceKindId, sliceId, dn);

    try {//w w w . j av  a 2 s  .c  o  m
        Slice slice = findSliceOfKind(subspaceId, sliceKindId, sliceId);

        return new ResponseEntity<String>(
                slice.getKind().getSliceDirectory() + File.separatorChar + slice.getDirectoryId(), headers,
                HttpStatus.OK);
    } catch (NoSuchElementException ne) {
        logger.warn(ne.getMessage());
        return new ResponseEntity<String>(null, headers, HttpStatus.NOT_FOUND);
    }
}

From source file:de.zib.gndms.dspace.service.SliceServiceImpl.java

@Override
@RequestMapping(value = "/_{subspaceId}/_{sliceKindId}/_{sliceId}/_{fileName:.*}", method = RequestMethod.DELETE)
@Secured("ROLE_USER")
public ResponseEntity<Integer> deleteFile(@PathVariable final String subspaceId,
        @PathVariable final String sliceKindId, @PathVariable final String sliceId,
        @PathVariable final String fileName, @RequestHeader("DN") final String dn) {
    GNDMSResponseHeader headers = setHeaders(subspaceId, sliceKindId, sliceId, dn);

    try {/*w  w w. j a  v  a2s .co m*/
        Subspace space = subspaceProvider.get(subspaceId);
        Slice slice = findSliceOfKind(subspaceId, sliceKindId, sliceId);
        String path = space.getPathForSlice(slice);

        if (directoryAux.deleteDirectory(dn, path + File.separator + fileName)) {
            return new ResponseEntity<Integer>(0, headers, HttpStatus.OK);
        } else {
            logger.warn("File " + path + " could not be deleted.");
            return new ResponseEntity<Integer>(0, headers, HttpStatus.FORBIDDEN);
        }
    } catch (NoSuchElementException ne) {
        logger.warn(ne.getMessage(), ne);
        return new ResponseEntity<Integer>(0, headers, HttpStatus.NOT_FOUND);
    }
}

From source file:de.zib.gndms.dspace.service.SliceServiceImpl.java

@Override
@RequestMapping(value = "/_{subspaceId}/_{sliceKindId}/_{sliceId}", method = RequestMethod.DELETE)
@Secured("ROLE_USER")
public ResponseEntity<Specifier<Facets>> deleteSlice(@PathVariable final String subspaceId,
        @PathVariable final String sliceKindId, @PathVariable final String sliceId,
        @RequestHeader("DN") final String dn) {
    GNDMSResponseHeader headers = setHeaders(subspaceId, sliceKindId, sliceId, dn);

    try {//from   ww  w .  j a  v a  2 s . c  o m
        // submit action
        final Taskling ling = sliceProvider.deleteSlice(subspaceId, sliceId);

        // get service facets of task
        final TaskClient client = new TaskClient(localBaseUrl);
        client.setRestTemplate(restTemplate);
        final Specifier<Facets> spec = TaskClient.TaskServiceAux.getTaskSpecifier(client, ling.getId(),
                uriFactory, null, dn);

        // return specifier for service facets
        return new ResponseEntity<Specifier<Facets>>(spec, headers, HttpStatus.OK);
    } catch (NoSuchElementException ne) {
        logger.warn(ne.getMessage());
        return new ResponseEntity<Specifier<Facets>>(null, headers, HttpStatus.NOT_FOUND);
    }
}

From source file:de.zib.gndms.dspace.service.SliceServiceImpl.java

@Override
@RequestMapping(value = "/_{subspace}/_{sliceKind}/_{slice}/files", method = RequestMethod.DELETE)
@Secured("ROLE_USER")
public ResponseEntity<Integer> deleteFiles(@PathVariable final String subspaceId,
        @PathVariable final String sliceKind, @PathVariable final String sliceId,
        @RequestHeader("DN") final String dn) {
    GNDMSResponseHeader headers = setHeaders(subspaceId, sliceKind, sliceId, dn);

    try {//from w ww. j a v  a  2s  .  c om
        Subspace space = subspaceProvider.get(subspaceId);
        Slice slice = findSliceOfKind(subspaceId, sliceKind, sliceId);
        String path = space.getPathForSlice(slice);

        File f = new File(path);
        String[] fl = f.list();
        for (String s : fl) {
            String p = path + File.separatorChar + s;
            if (!directoryAux.deleteDirectory(dn, p)) {
                logger.warn("Some file in directory " + p + " could not be deleted.");
                return new ResponseEntity<Integer>(0, headers, HttpStatus.CONFLICT);
            }
        }
    } catch (NoSuchElementException ne) {
        logger.warn(ne.getMessage());
        return new ResponseEntity<Integer>(0, headers, HttpStatus.NOT_FOUND);
    }
    return new ResponseEntity<Integer>(0, headers, HttpStatus.OK);
}

From source file:de.zib.gndms.dspace.service.SliceServiceImpl.java

@Override
@RequestMapping(value = "/_{subspaceId}/_{sliceKindId}/_{sliceId}/files", method = RequestMethod.GET)
@Secured("ROLE_USER")
public ResponseEntity<List<FileStats>> listFiles(@PathVariable final String subspaceId,
        @PathVariable final String sliceKindId, @PathVariable final String sliceId,
        @RequestHeader("DN") final String dn) {
    final GNDMSResponseHeader headers = setHeaders(subspaceId, sliceKindId, sliceId, dn);

    try {/*from   www.  ja v  a 2s  .  c o m*/
        final Subspace space = subspaceProvider.get(subspaceId);
        final Slice slice = findSliceOfKind(subspaceId, sliceKindId, sliceId);
        final String path = space.getPathForSlice(slice);

        File dir = new File(path);
        if (dir.exists() && dir.canRead() && dir.isDirectory()) {
            List<FileStats> files = new LinkedList<FileStats>();
            recursiveListFiles(path, "", files);

            headers.add("DiskUsage", String.valueOf(sliceProvider.getDiskUsage(subspaceId, sliceId)));

            return new ResponseEntity<List<FileStats>>(files, headers, HttpStatus.OK);
        } else {
            return new ResponseEntity<List<FileStats>>(null, headers, HttpStatus.FORBIDDEN);
        }
    } catch (NoSuchElementException ne) {
        logger.warn(ne.getMessage());
        return new ResponseEntity<List<FileStats>>(null, headers, HttpStatus.NOT_FOUND);
    }
}

From source file:de.zib.gndms.dspace.service.SliceServiceImpl.java

@RequestMapping(value = "/_{subspace}/_{sliceKind}/_{sliceId}/files", method = RequestMethod.POST)
@Secured("ROLE_USER")
public ResponseEntity<Integer> setFileContents(@PathVariable final String subspaceId,
        @PathVariable final String sliceKind, @PathVariable final String sliceId,
        @RequestParam("files") final List<MultipartFile> files, @RequestHeader("DN") final String dn) {
    GNDMSResponseHeader headers = setHeaders(subspaceId, sliceKind, sliceId, dn);

    try {//from w w  w  .  jav  a  2 s .c o m
        Subspace space = subspaceProvider.get(subspaceId);
        Slice slice = findSliceOfKind(subspaceId, sliceKind, sliceId);
        String path = space.getPathForSlice(slice);

        final long sliceMaxSize = slice.getTotalStorageSize();

        for (MultipartFile file : files) {
            long sliceSize = sliceProvider.getDiskUsage(subspaceId, sliceId);
            if (sliceSize >= sliceMaxSize)
                throw new IOException(
                        "Slice " + sliceId + " has reached maximum size of " + sliceMaxSize + " Bytes");

            File newFile = new File(path + File.separatorChar + file.getOriginalFilename());

            if (newFile.exists()) {
                logger.warn("File " + newFile + "will be overwritten.");
            }

            file.transferTo(newFile);
        }
        return new ResponseEntity<Integer>(0, headers, HttpStatus.OK);
    } catch (NoSuchElementException ne) {
        logger.warn(ne.getMessage(), ne);
        return new ResponseEntity<Integer>(0, headers, HttpStatus.NOT_FOUND);
    } catch (FileNotFoundException e) {
        logger.warn(e.getMessage(), e);
        return new ResponseEntity<Integer>(0, headers, HttpStatus.FORBIDDEN);
    } catch (IOException e) {
        logger.warn(e.getMessage(), e);
        return new ResponseEntity<Integer>(0, headers, HttpStatus.FORBIDDEN);
    }
}

From source file:de.zib.gndms.dspace.service.SliceServiceImpl.java

@Override
@RequestMapping(value = "/_{subspaceId}/_{sliceKindId}/_{sliceId}/_{fileName:.*}", method = RequestMethod.POST)
@Secured("ROLE_USER")
public ResponseEntity<Integer> setFileContent(@PathVariable final String subspaceId,
        @PathVariable final String sliceKindId, @PathVariable final String sliceId,
        @PathVariable final String fileName, @RequestParam("file") final MultipartFile file,
        @RequestHeader("DN") final String dn) {
    GNDMSResponseHeader headers = setHeaders(subspaceId, sliceKindId, sliceId, dn);

    try {// www .  j a v  a 2s. co  m
        Subspace space = subspaceProvider.get(subspaceId);
        Slice slice = findSliceOfKind(subspaceId, sliceKindId, sliceId);
        String path = space.getPathForSlice(slice);
        File newFile = new File(path + File.separatorChar + fileName);

        if (newFile.exists()) {
            logger.warn("File " + newFile + "will be overwritten. ");
        }

        final long sliceMaxSize = slice.getTotalStorageSize();
        long sliceSize = sliceProvider.getDiskUsage(subspaceId, sliceId);
        if (sliceSize >= sliceMaxSize)
            throw new IOException(
                    "Slice " + sliceId + " has reached maximum size of " + sliceMaxSize + " Bytes");

        file.transferTo(newFile);

        //DataOutputStream dos = new DataOutputStream(new FileOutputStream(newFile));

        //dos.write(file.getBytes());
        //dos.close();
        return new ResponseEntity<Integer>(0, headers, HttpStatus.OK);
    } catch (NoSuchElementException ne) {
        logger.warn(ne.getMessage(), ne);
        return new ResponseEntity<Integer>(0, headers, HttpStatus.NOT_FOUND);
    } catch (FileNotFoundException e) {
        logger.warn(e.getMessage(), e);
        return new ResponseEntity<Integer>(0, headers, HttpStatus.FORBIDDEN);
    } catch (IOException e) {
        logger.warn(e.getMessage(), e);
        return new ResponseEntity<Integer>(0, headers, HttpStatus.FORBIDDEN);
    }
}

From source file:de.zib.gndms.dspace.service.SliceServiceImpl.java

@Override
@RequestMapping(value = "/_{subspaceId}/_{sliceKindId}/_{sliceId}", method = RequestMethod.POST)
@Secured("ROLE_USER")
public ResponseEntity<Specifier<Void>> transformSlice(@PathVariable final String subspaceId,
        @PathVariable final String sliceKindId, @PathVariable final String sliceId,
        @RequestBody final Specifier<Void> newSliceKind, @RequestHeader("DN") final String dn) {
    GNDMSResponseHeader headers = setHeaders(subspaceId, sliceKindId, sliceId, dn);

    try {/* w  w w . ja va 2  s.c  om*/
        Slice slice = findSliceOfKind(subspaceId, sliceKindId, sliceId);

        SliceKind newSliceK = sliceKindProvider.get(subspaceId, newSliceKind.getUrl());
        Subspace space = subspaceProvider.get(subspaceId);

        EntityManager em = emf.createEntityManager();
        TxFrame tx = new TxFrame(em);
        try {
            // TODO is this right? what is this uuid generator (last entry)?
            TransformSliceAction action = new TransformSliceAction(dn, slice.getTerminationTime(), newSliceK,
                    space, slice.getTotalStorageSize(), null);
            action.setOwnEntityManager(em);
            logger.info("Calling action for transforming sliceId " + sliceId + ".");
            action.call();
            tx.commit();
        } finally {
            tx.finish();
            if (em != null && em.isOpen()) {
                em.close();
            }
        }

        Specifier<Void> spec = new Specifier<Void>();

        HashMap<String, String> urimap = new HashMap<String, String>(2);
        urimap.put("service", "dspace");
        urimap.put(UriFactory.SUBSPACE, subspaceId);
        urimap.put(UriFactory.SLICE_KIND, sliceKindId);
        urimap.put(UriFactory.SLICE, sliceId);
        spec.setUriMap(new HashMap<String, String>(urimap));
        spec.setUrl(uriFactory.quoteUri(urimap));

        return new ResponseEntity<Specifier<Void>>(spec, headers, HttpStatus.OK);
    } catch (NoSuchElementException ne) {
        logger.warn(ne.getMessage());
        return new ResponseEntity<Specifier<Void>>(null, headers, HttpStatus.NOT_FOUND);
    }
}

From source file:de.zib.gndms.dspace.service.SliceServiceImpl.java

@Override
@RequestMapping(value = "/_{subspaceId}/_{sliceKindId}/_{sliceId}/_{fileName:.*}", method = RequestMethod.GET)
@Secured("ROLE_USER")
public ResponseEntity<Integer> listFileContent(@PathVariable final String subspaceId,
        @PathVariable final String sliceKindId, @PathVariable final String sliceId,
        @PathVariable final String fileName,
        @RequestParam(value = "attrs", required = false) final List<String> attrs,
        @RequestHeader("DN") final String dn, final OutputStream out) {
    GNDMSResponseHeader headers = setHeaders(subspaceId, sliceKindId, sliceId, dn);

    try {//from www . j  a v  a  2s  . c  om
        Subspace space = subspaceProvider.get(subspaceId);
        Slice slice = findSliceOfKind(subspaceId, sliceKindId, sliceId);
        String path = space.getPathForSlice(slice);
        File file = new File(path + File.separatorChar + fileName);

        if (out == null) {
            final IllegalStateException illegalStateException = new IllegalStateException(
                    "OutputStream not defined.");
            logger.warn(illegalStateException.getMessage());
            throw illegalStateException;
        }

        if (file.exists() && file.canRead() && file.isFile()) {
            // TODO get requested file attributes

            if (attrs == null || attrs.contains("contents")) {
                FileCopyUtils.copy(new FileInputStream(file), out);
            }

            return new ResponseEntity<Integer>(0, headers, HttpStatus.OK);
        } else {
            logger.warn("File " + file + " cannot be read or is no file.");
            return new ResponseEntity<Integer>(0, headers, HttpStatus.FORBIDDEN);
        }

    } catch (NoSuchElementException ne) {
        logger.warn(ne.getMessage());
        return new ResponseEntity<Integer>(0, headers, HttpStatus.NOT_FOUND);
    } catch (FileNotFoundException e) {
        logger.warn(e.getMessage());
        return new ResponseEntity<Integer>(0, headers, HttpStatus.FORBIDDEN);
    } catch (IOException e) {
        logger.warn(e.getMessage());
        return new ResponseEntity<Integer>(0, headers, HttpStatus.FORBIDDEN);
    }
}

From source file:org.opennms.web.asset.ImportAssetsServlet.java

/**
 * <p>decodeAssetsText</p>//from   w  ww. j  av a  2  s. c  o  m
 *
 * @param text a {@link java.lang.String} object.
 * @return a {@link java.util.List} object.
 * @throws org.opennms.web.asset.ImportAssetsServlet$AssetException if any.
 */
public List<Asset> decodeAssetsText(String text) throws AssetException {
    CSVReader csvReader = null;
    StringReader stringReader = null;
    String[] line;
    List<Asset> list = new ArrayList<Asset>();
    text = text.trim();

    int count = 0;

    try {
        stringReader = new StringReader(text);
        csvReader = new CSVReader(stringReader);

        while ((line = csvReader.readNext()) != null) {
            count++;
            try {
                logger.debug("asset line is:'{}'", (Object) line);
                if (line.length <= 37) {
                    logger.error(
                            "csv test row length was not at least 37 line length: '{}' line was:'{}', line length",
                            line.length, line);
                    throw new NoSuchElementException();
                }

                // skip the first line if it's the headers
                if (line[0].equals("Node Label")) {
                    logger.debug("line was header. line:'{}'", (Object) line);
                    continue;
                }

                final Asset asset = new Asset();

                asset.setNodeId(WebSecurityUtils.safeParseInt(line[1]));
                asset.setCategory(Util.decode(line[2]));
                asset.setManufacturer(Util.decode(line[3]));
                asset.setVendor(Util.decode(line[4]));
                asset.setModelNumber(Util.decode(line[5]));
                asset.setSerialNumber(Util.decode(line[6]));
                asset.setDescription(Util.decode(line[7]));
                asset.setCircuitId(Util.decode(line[8]));
                asset.setAssetNumber(Util.decode(line[9]));
                asset.setOperatingSystem(Util.decode(line[10]));
                asset.setRack(Util.decode(line[11]));
                asset.setSlot(Util.decode(line[12]));
                asset.setPort(Util.decode(line[13]));
                asset.setRegion(Util.decode(line[14]));
                asset.setDivision(Util.decode(line[15]));
                asset.setDepartment(Util.decode(line[16]));
                asset.setAddress1(Util.decode(line[17]));
                asset.setAddress2(Util.decode(line[18]));
                asset.setCity(Util.decode(line[19]));
                asset.setState(Util.decode(line[20]));
                asset.setZip(Util.decode(line[21]));
                asset.setBuilding(Util.decode(line[22]));
                asset.setFloor(Util.decode(line[23]));
                asset.setRoom(Util.decode(line[24]));
                asset.setVendorPhone(Util.decode(line[25]));
                asset.setVendorFax(Util.decode(line[26]));
                asset.setDateInstalled(Util.decode(line[27]));
                asset.setLease(Util.decode(line[28]));
                asset.setLeaseExpires(Util.decode(line[29]));
                asset.setSupportPhone(Util.decode(line[30]));
                asset.setMaintContract(Util.decode(line[31]));
                asset.setVendorAssetNumber(Util.decode(line[32]));
                asset.setMaintContractExpires(Util.decode(line[33]));
                asset.setDisplayCategory(Util.decode(line[34]));
                asset.setNotifyCategory(Util.decode(line[35]));
                asset.setPollerCategory(Util.decode(line[36]));

                if (line.length > 37) {
                    asset.setThresholdCategory(Util.decode(line[37]));
                    asset.setUsername(Util.decode(line[38]));
                    asset.setPassword(Util.decode(line[39]));
                    asset.setEnable(Util.decode(line[40]));
                    asset.setConnection(Util.decode(line[41]));
                    asset.setAutoenable(Util.decode(line[42]));
                    asset.setComments(Util.decode(line[43]));
                }

                if (line.length > 44) {
                    asset.setCpu(Util.decode(line[44]));
                    asset.setRam(Util.decode(line[45]));
                    asset.setStoragectrl(Util.decode(line[46]));
                    asset.setHdd1(Util.decode(line[47]));
                    asset.setHdd2(Util.decode(line[48]));
                    asset.setHdd3(Util.decode(line[49]));
                    asset.setHdd4(Util.decode(line[50]));
                    asset.setHdd5(Util.decode(line[51]));
                    asset.setHdd6(Util.decode(line[52]));

                    asset.setNumpowersupplies(Util.decode(line[53]));
                    asset.setInputpower(Util.decode(line[54]));

                    asset.setAdditionalhardware(Util.decode(line[55]));
                    asset.setAdmin(Util.decode(line[56]));
                    asset.setSnmpcommunity(Util.decode(line[57]));
                    asset.setRackunitheight(Util.decode(line[58]));
                }

                if (line.length > 59) {
                    asset.setCountry(Util.decode(line[59]));
                    asset.setLongitude(Util.decode(line[60]));
                    asset.setLatitude(Util.decode(line[61]));
                }

                list.add(asset);
                logger.debug("decoded asset:'{}'", (Object) asset);

            } catch (NoSuchElementException e) {
                errors.add("Ignoring malformed import for entry " + count + ", not enough values.");
            } catch (NumberFormatException e) {
                logger.error(
                        "NodeId parsing to int faild, ignoreing malformed import for entry number '{}' exception message:'{}'",
                        count, e.getMessage());
                errors.add("Ignoring malformed import for entry " + count + ", node id not a number.");
            }
        }
    } catch (IOException e) {
        logger.error("An error occurred reading the CSV input. Message:'{}'", e.getMessage());
        throw new AssetException("An error occurred reading the CSV input.", e);
    } finally {
        IOUtils.closeQuietly(stringReader);
        IOUtils.closeQuietly(csvReader);
    }

    if (list.size() == 0) {
        logger.error("No asset information was found, list size was 0");
        throw new AssetException("No asset information was found.");
    }

    return list;
}