Package org.dspace.submit.util

Examples of org.dspace.submit.util.SubmissionLookupDTO


        if (StringUtils.isBlank(uuidSubmission))
        {
            return STATUS_NO_SUUID;
        }

        SubmissionLookupDTO submissionDTO = slService.getSubmissionLookupDTO(
                request, uuidSubmission);

        if (submissionDTO == null)
        {
            return STATUS_SUBMISSION_EXPIRED;
        }

        ItemSubmissionLookupDTO itemLookup = null;
        if (fuuidLookup == null || fuuidLookup.isEmpty())
        {
            if (StringUtils.isNotBlank(uuidLookup))
            {
                itemLookup = submissionDTO.getLookupItem(uuidLookup);
                if (itemLookup == null)
                {
                    return STATUS_SUBMISSION_EXPIRED;
                }
            }
        }
        // if the user didn't select a collection,
        // send him/her back to "select a collection" page
        if (id < 0)
        {
            return STATUS_NO_COLLECTION;
        }

        // try to load the collection
        Collection col = Collection.find(context, id);

        // Show an error if the collection is invalid
        if (col == null)
        {
            return STATUS_INVALID_COLLECTION;
        }
        else
        {
            // create our new Workspace Item
            DCInputSet inputSet = null;
            try
            {
                inputSet = new DCInputsReader().getInputs(col.getHandle());
            }
            catch (Exception e)
            {
                log.error(e.getMessage(), e);
                throw new RuntimeException(e);
            }

            List<ItemSubmissionLookupDTO> dto = new ArrayList<ItemSubmissionLookupDTO>();

            if (itemLookup != null)
            {
                dto.add(itemLookup);
            }
            else if (fuuidLookup != null && !fuuidLookup.isEmpty())
            {
                String[] ss = fuuidLookup.split(",");
                for (String s : ss)
                {
                    itemLookup = submissionDTO.getLookupItem(s);
                    if (itemLookup == null)
                    {
                        return STATUS_SUBMISSION_EXPIRED;
                    }
                    dto.add(itemLookup);
View Full Code Here


    }

    public SubmissionLookupDTO getSubmissionLookupDTO(
            HttpServletRequest request, String uuidSubmission)
    {
        SubmissionLookupDTO dto = (SubmissionLookupDTO) request.getSession()
                .getAttribute("submission_lookup_" + uuidSubmission);
        if (dto == null)
        {
            dto = new SubmissionLookupDTO();
            storeDTOs(request, uuidSubmission, dto);
        }
        return dto;
    }
View Full Code Here

    public void doJSONRequest(Context context, HttpServletRequest req,
            HttpServletResponse resp) throws AuthorizeException, IOException
    {
        Gson json = new Gson();
        String suuid = req.getParameter("s_uuid");
        SubmissionLookupDTO subDTO = service.getSubmissionLookupDTO(req, suuid);
        // Check that we have a file upload request
        boolean isMultipart = ServletFileUpload.isMultipartContent(req);
        if ("identifiers".equalsIgnoreCase(req.getParameter("type")))
        {
            Map<String, Set<String>> identifiers = new HashMap<String, Set<String>>();
            Enumeration e = req.getParameterNames();

            while (e.hasMoreElements())
            {
                String parameterName = (String) e.nextElement();
                String parameterValue = req.getParameter(parameterName);

                if (parameterName.startsWith("identifier_")
                        && StringUtils.isNotBlank(parameterValue))
                {
                    Set<String> set = new HashSet<String>();
                    set.add(parameterValue);
                    identifiers.put(
                            parameterName.substring("identifier_".length()),
                            set);
                }
            }

            List<ItemSubmissionLookupDTO> result = new ArrayList<ItemSubmissionLookupDTO>();

            TransformationEngine transformationEngine = service
                    .getPhase1TransformationEngine();
            if (transformationEngine != null)
            {
                MultipleSubmissionLookupDataLoader dataLoader = (MultipleSubmissionLookupDataLoader) transformationEngine
                        .getDataLoader();
                dataLoader.setIdentifiers(identifiers);

                try
                {
                    SubmissionLookupOutputGenerator outputGenerator = (SubmissionLookupOutputGenerator) transformationEngine
                            .getOutputGenerator();
                    outputGenerator.setDtoList(new ArrayList<ItemSubmissionLookupDTO>());
                    log.debug("BTE transformation is about to start!");
                    transformationEngine.transform(new TransformationSpec());
                    log.debug("BTE transformation finished!");
                    result = outputGenerator.getDtoList();
                }
                catch (BadTransformationSpec e1)
                {
                    log.error(e1.getMessage(), e1);
                }
                catch (MalformedSourceException e1)
                {
                    log.error(e1.getMessage(), e1);
                }
            }

            subDTO.setItems(result);
            service.storeDTOs(req, suuid, subDTO);
            List<Map<String, Object>> dto = getLightResultList(result);
            JsonElement tree = json.toJsonTree(dto);
            JsonObject jo = new JsonObject();
            jo.add("result", tree);
            resp.getWriter().write(jo.toString());

        }
        else if ("search".equalsIgnoreCase(req.getParameter("type")))
        {
            String title = req.getParameter("title");
            String author = req.getParameter("authors");
            int year = UIUtil.getIntParameter(req, "year");

            Map<String, Set<String>> searchTerms = new HashMap<String, Set<String>>();
            Set<String> tmp1 = new HashSet<String>();
            tmp1.add(title);
            Set<String> tmp2 = new HashSet<String>();
            tmp2.add(author);
            Set<String> tmp3 = new HashSet<String>();
            tmp3.add(String.valueOf(year));
            searchTerms.put("title", tmp1);
            searchTerms.put("authors", tmp2);
            searchTerms.put("year", tmp3);

            List<ItemSubmissionLookupDTO> result = new ArrayList<ItemSubmissionLookupDTO>();

            TransformationEngine transformationEngine = service
                    .getPhase1TransformationEngine();
            if (transformationEngine != null)
            {
                MultipleSubmissionLookupDataLoader dataLoader = (MultipleSubmissionLookupDataLoader) transformationEngine
                        .getDataLoader();
                dataLoader.setSearchTerms(searchTerms);

                try
                {
                    SubmissionLookupOutputGenerator outputGenerator = (SubmissionLookupOutputGenerator) transformationEngine
                            .getOutputGenerator();
                    outputGenerator.setDtoList(new ArrayList<ItemSubmissionLookupDTO>());
                    log.debug("BTE transformation is about to start!");
                    transformationEngine.transform(new TransformationSpec());
                    log.debug("BTE transformation finished!");
                    result = outputGenerator.getDtoList();
                }
                catch (BadTransformationSpec e1)
                {
                    log.error(e1.getMessage(), e1);
                }
                catch (MalformedSourceException e1)
                {
                    log.error(e1.getMessage(), e1);
                }
            }

            subDTO.setItems(result);
            service.storeDTOs(req, suuid, subDTO);
            List<Map<String, Object>> dto = getLightResultList(result);
            JsonElement tree = json.toJsonTree(dto);
            JsonObject jo = new JsonObject();
            jo.add("result", tree);
            resp.getWriter().write(jo.toString());
        }
        else if ("details".equalsIgnoreCase(req.getParameter("type")))
        {
            String i_uuid = req.getParameter("i_uuid");
            Map<String, Object> dto = getDetails(subDTO.getLookupItem(i_uuid),
                    context);
            JsonElement tree = json.toJsonTree(dto);
            JsonObject jo = new JsonObject();
            jo.add("result", tree);
            resp.getWriter().write(jo.toString());
        }
        else if (isMultipart)
        {

            // Create a factory for disk-based file items
            FileItemFactory factory = new DiskFileItemFactory();

            // Create a new file upload handler
            ServletFileUpload upload = new ServletFileUpload(factory);
            // Parse the request
            Map<String, String> valueMap = new HashMap<String, String>();
            InputStream io = null;

            // Parse the request
            List<FileItem> iter;
            String filename = null;
            try
            {
                iter = upload.parseRequest(req);
                for (FileItem item : iter)
                {
                    String name = item.getFieldName();
                    InputStream stream = item.getInputStream();
                    if (item.isFormField())
                    {
                        String value = Streams.asString(stream);
                        valueMap.put(name, value);
                    }
                    else
                    {
                        io = stream;
                    }
                }
            }
            catch (FileUploadException e)
            {
                throw new IOException(e);
            }

            suuid = valueMap.get("s_uuid");
            subDTO = service.getSubmissionLookupDTO(req, suuid);

            List<ItemSubmissionLookupDTO> result = new ArrayList<ItemSubmissionLookupDTO>();

            TransformationEngine transformationEngine = service
                    .getPhase1TransformationEngine();
            if (transformationEngine != null)
            {
                MultipleSubmissionLookupDataLoader dataLoader = (MultipleSubmissionLookupDataLoader) transformationEngine
                        .getDataLoader();

                String tempDir = (ConfigurationManager
                        .getProperty("upload.temp.dir") != null) ? ConfigurationManager
                        .getProperty("upload.temp.dir") : System
                        .getProperty("java.io.tmpdir");
                File uploadDir = new File(tempDir);
                if (!uploadDir.exists()) {
                    if (!uploadDir.mkdir()) {
                        uploadDir = null;
                    }
                }
                File file = File.createTempFile("submissionlookup-loader",
                                                ".temp",
                                                uploadDir);
                BufferedOutputStream out = new BufferedOutputStream(
                        new FileOutputStream(file));
                Utils.bufferedCopy(io, out);
                dataLoader.setFile(file.getAbsolutePath(),
                        valueMap.get("provider_loader"));

                try
                {
                    SubmissionLookupOutputGenerator outputGenerator = (SubmissionLookupOutputGenerator) transformationEngine
                            .getOutputGenerator();
                    outputGenerator.setDtoList(new ArrayList<ItemSubmissionLookupDTO>());
                    log.debug("BTE transformation is about to start!");
                    transformationEngine.transform(new TransformationSpec());
                    log.debug("BTE transformation finished!");
                    result = outputGenerator.getDtoList();
                }
                catch (BadTransformationSpec e1)
                {
                    log.error(e1.getMessage(), e1);
                }
                catch (MalformedSourceException e1)
                {
                    log.error(e1.getMessage(), e1);
                }
                finally
                {
                    file.delete();
                }
            }
            subDTO.setItems(result);
            service.storeDTOs(req, suuid, subDTO);
            List<Map<String, Object>> dto = getLightResultList(result);
            if (valueMap.containsKey("skip_loader"))
            {
                if (valueMap.get("skip_loader").equals("true"))
View Full Code Here

TOP

Related Classes of org.dspace.submit.util.SubmissionLookupDTO

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.