airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dimuthu...@apache.org
Subject [airavata] branch develop updated: Adding custom save method to parser repository
Date Tue, 15 Jan 2019 19:23:30 GMT
This is an automated email from the ASF dual-hosted git repository.

dimuthuupe pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/airavata.git


The following commit(s) were added to refs/heads/develop by this push:
     new bec5809  Adding custom save method to parser repository
bec5809 is described below

commit bec5809160d0ad2e5dcc49c0d27b54d25f560b90
Author: Dimuthu Wannipurage <dimuthu.upeksha2@gmail.com>
AuthorDate: Tue Jan 15 14:23:19 2019 -0500

    Adding custom save method to parser repository
---
 .../repositories/appcatalog/ParserRepository.java  | 36 +++++++++++++++++++++-
 .../api/service/handler/RegistryServerHandler.java |  2 +-
 2 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/appcatalog/ParserRepository.java
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/appcatalog/ParserRepository.java
index c01e0d7..6e2157c 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/appcatalog/ParserRepository.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/appcatalog/ParserRepository.java
@@ -1,10 +1,14 @@
 package org.apache.airavata.registry.core.repositories.appcatalog;
 
 import org.apache.airavata.model.appcatalog.parser.Parser;
-import org.apache.airavata.model.appcatalog.parser.ParsingTemplate;
 import org.apache.airavata.registry.core.entities.appcatalog.ParserEntity;
 import org.apache.airavata.registry.core.utils.DBConstants;
+import org.apache.airavata.registry.core.utils.ObjectMapperSingleton;
 import org.apache.airavata.registry.core.utils.QueryConstants;
+import org.apache.airavata.registry.cpi.AppCatalogException;
+import org.dozer.Mapper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.util.HashMap;
 import java.util.List;
@@ -12,10 +16,40 @@ import java.util.Map;
 
 public class ParserRepository extends AppCatAbstractRepository<Parser, ParserEntity, String>
{
 
+    private final static Logger logger = LoggerFactory.getLogger(ParserRepository.class);
+
     public ParserRepository() {
         super(Parser.class, ParserEntity.class);
     }
 
+    public Parser saveParser(Parser parser) throws AppCatalogException {
+
+        try {
+            Mapper mapper = ObjectMapperSingleton.getInstance();
+            ParserEntity parserEntity = mapper.map(parser, ParserEntity.class);
+
+            if (parser.getInputFiles() != null) {
+                parserEntity.getInputFiles().forEach(input -> {
+                    input.setParser(parserEntity);
+                    input.setParserId(parserEntity.getId());
+                });
+            }
+
+            if (parser.getOutputFiles() != null) {
+                parserEntity.getOutputFiles().forEach(output -> {
+                    output.setParser(parserEntity);
+                    output.setParserId(parserEntity.getId());
+                });
+            }
+
+            ParserEntity savedParserEntity = execute(entityManager -> entityManager.merge(parserEntity));
+            return mapper.map(savedParserEntity, Parser.class);
+        } catch (Exception e) {
+            logger.error("Failed to save parser with id " + parser.getId(), e);
+            throw new AppCatalogException("Failed to save parser with id " + parser.getId(),
e);
+        }
+    }
+
     public List<Parser> getAllParsers(String gatewayId) {
         Map<String, Object> queryParameters = new HashMap<>();
         queryParameters.put(DBConstants.Parser.GATEWAY_ID, gatewayId);
diff --git a/modules/registry/registry-server/registry-api-service/src/main/java/org/apache/airavata/registry/api/service/handler/RegistryServerHandler.java
b/modules/registry/registry-server/registry-api-service/src/main/java/org/apache/airavata/registry/api/service/handler/RegistryServerHandler.java
index 6cf742e..8d85250 100644
--- a/modules/registry/registry-server/registry-api-service/src/main/java/org/apache/airavata/registry/api/service/handler/RegistryServerHandler.java
+++ b/modules/registry/registry-server/registry-api-service/src/main/java/org/apache/airavata/registry/api/service/handler/RegistryServerHandler.java
@@ -4831,7 +4831,7 @@ public class RegistryServerHandler implements RegistryService.Iface
{
     public String saveParser(Parser parser) throws RegistryServiceException, TException {
 
         try {
-            Parser created = parserRepository.create(parser);
+            Parser created = parserRepository.saveParser(parser);
             return created.getId();
 
         } catch (Exception e) {


Mime
View raw message