Package gr.ekt.bte.core

Examples of gr.ekt.bte.core.TransformationEngine


            }

            List<WorkspaceItem> result = null;

            TransformationEngine transformationEngine = slService
                    .getPhase2TransformationEngine();
            if (transformationEngine != null)
            {
                SubmissionItemDataLoader dataLoader = (SubmissionItemDataLoader) transformationEngine
                        .getDataLoader();
                dataLoader.setDtoList(dto);
                // dataLoader.setProviders()

                DSpaceWorkspaceItemOutputGenerator outputGenerator = (DSpaceWorkspaceItemOutputGenerator) transformationEngine
                        .getOutputGenerator();
                outputGenerator.setCollection(col);
                outputGenerator.setContext(context);
                outputGenerator.setFormName(inputSet.getFormName());
                outputGenerator.setDto(dto.get(0));

                try
                {
                    transformationEngine.transform(new TransformationSpec());
                    result = outputGenerator.getWitems();
                }
                catch (BadTransformationSpec e1)
                {
                    e1.printStackTrace();
View Full Code Here


      }

        BTEBatchImportService dls  = new DSpace().getSingletonService(BTEBatchImportService.class);
        DataLoader dataLoader = dls.getDataLoaders().get(inputType);
        Map<String, String> outputMap = dls.getOutputMap();
        TransformationEngine te = dls.getTransformationEngine();

        if (dataLoader==null){
            System.out.println("ERROR: The key used in -i parameter must match a valid DataLoader in the BTE Spring XML configuration file!");
            return;
        }

        if (outputMap==null){
            System.out.println("ERROR: The key used in -i parameter must match a valid outputMapping in the BTE Spring XML configuration file!");
            return;
        }

        if (dataLoader instanceof FileDataLoader){
            FileDataLoader fdl = (FileDataLoader) dataLoader;
            if (!StringUtils.isBlank(sourceDir)) {
                System.out.println("INFO: Dataloader will load data from the file specified in the command prompt (and not from the Spring XML configuration file)");
                fdl.setFilename(sourceDir);
            }
        }
        else if (dataLoader instanceof OAIPMHDataLoader){
            OAIPMHDataLoader fdl = (OAIPMHDataLoader) dataLoader;
            System.out.println(sourceDir);
            if (!StringUtils.isBlank(sourceDir)){
                System.out.println("INFO: Dataloader will load data from the address specified in the command prompt (and not from the Spring XML configuration file)");
                fdl.setServerAddress(sourceDir);
            }
        }
        if (dataLoader!=null){
            System.out.println("INFO: Dataloader " + dataLoader.toString()+" will be used for the import!");

          te.setDataLoader(dataLoader);

          DSpaceOutputGenerator outputGenerator = new DSpaceOutputGenerator(outputMap);
          outputGenerator.setOutputDirectory(outputFolder);

          te.setOutputGenerator(outputGenerator);

          try {
            TransformationResult res = te.transform(new TransformationSpec());
            List<String> output = res.getOutput();
            outputGenerator.writeOutput(output);
          } catch (Exception e) {
            System.err.println("Exception");
            e.printStackTrace();
View Full Code Here

                }
            }

            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)
                {
View Full Code Here

TOP

Related Classes of gr.ekt.bte.core.TransformationEngine

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.