[ https://issues.apache.org/jira/browse/AIRAVATA-2657?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16411612#comment-16411612 ]
ASF GitHub Bot commented on AIRAVATA-2657: ------------------------------------------ DImuthuUpe commented on a change in pull request #167: [AIRAVATA-2657] Refactoring App Catalog Implementation - ApplicationDeployment and ApplicationInterface Modules URL: https://github.com/apache/airavata/pull/167#discussion_r176781978 ########## File path: modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/appcatalog/ApplicationInterfaceRepository.java ########## @@ -0,0 +1,256 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.airavata.registry.core.repositories.appcatalog; + +import org.apache.airavata.model.appcatalog.appdeployment.ApplicationModule; +import org.apache.airavata.model.appcatalog.appinterface.ApplicationInterfaceDescription; +import org.apache.airavata.model.appcatalog.appinterface.application_interface_modelConstants; +import org.apache.airavata.model.application.io.InputDataObjectType; +import org.apache.airavata.model.application.io.OutputDataObjectType; +import org.apache.airavata.registry.core.utils.*; +import org.apache.airavata.registry.cpi.AppCatalogException; +import org.apache.airavata.registry.cpi.ApplicationInterface; +import org.apache.airavata.registry.core.entities.appcatalog.*; +import org.dozer.Mapper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class ApplicationInterfaceRepository extends AppCatAbstractRepository<ApplicationInterfaceDescription, ApplicationInterfaceEntity, String> implements ApplicationInterface { + private final static Logger logger = LoggerFactory.getLogger(ApplicationInterfaceRepository.class); + + public ApplicationInterfaceRepository () { + super(ApplicationInterfaceDescription.class, ApplicationInterfaceEntity.class); + } + + protected String saveApplicationInterfaceDescriptorData( + ApplicationInterfaceDescription applicationInterfaceDescription, String gatewayId) throws AppCatalogException { + ApplicationInterfaceEntity applicationInterfaceEntity = saveApplicationInterface(applicationInterfaceDescription, gatewayId); + return applicationInterfaceEntity.getApplicationInterfaceId(); + } + + protected ApplicationInterfaceEntity saveApplicationInterface( + ApplicationInterfaceDescription applicationInterfaceDescription, String gatewayId) throws AppCatalogException { + String applicationInterfaceId = applicationInterfaceDescription.getApplicationInterfaceId(); + Mapper mapper = ObjectMapperSingleton.getInstance(); + ApplicationInterfaceEntity applicationInterfaceEntity = mapper.map(applicationInterfaceDescription, ApplicationInterfaceEntity.class); + if (gatewayId != null) + applicationInterfaceEntity.setGatewayId(gatewayId); + if (applicationInterfaceEntity.getApplicationInputs() != null) { + applicationInterfaceEntity.getApplicationInputs().forEach(applicationInputEntity -> applicationInputEntity.setInterfaceId(applicationInterfaceId)); + } + if (applicationInterfaceEntity.getApplicationOutputs() != null) { + applicationInterfaceEntity.getApplicationOutputs().forEach(applicationOutputEntity -> applicationOutputEntity.setInterfaceId(applicationInterfaceId)); + } + if (!isApplicationInterfaceExists(applicationInterfaceId)) + applicationInterfaceEntity.setCreationTime(new Timestamp(System.currentTimeMillis())); + applicationInterfaceEntity.setUpdateTime(new Timestamp(System.currentTimeMillis())); + return execute(entityManager -> entityManager.merge(applicationInterfaceEntity)); + } + + protected String saveApplicationModuleData( + ApplicationModule applicationModule, String gatewayId) throws AppCatalogException { + ApplicationModuleEntity applicationModuleEntity = saveApplicationModule(applicationModule, gatewayId); + return applicationModuleEntity.getAppModuleId(); + } + + protected ApplicationModuleEntity saveApplicationModule( + ApplicationModule applicationModule, String gatewayId) throws AppCatalogException { + String applicationModuleId = applicationModule.getAppModuleId(); + Mapper mapper = ObjectMapperSingleton.getInstance(); + ApplicationModuleEntity applicationModuleEntity = mapper.map(applicationModule, ApplicationModuleEntity.class); + if (gatewayId != null) + applicationModuleEntity.setGatewayId(gatewayId); + if (!applicationModuleEntity.getAppModuleId().equals("") && !applicationModule.getAppModuleId().equals(application_interface_modelConstants.DEFAULT_ID)) { + applicationModuleEntity.setAppModuleId(applicationModule.getAppModuleId()); + } else { + applicationModuleEntity.setAppModuleId(applicationModule.getAppModuleName()); + } + if (!isApplicationModuleExists(applicationModuleId)) + applicationModuleEntity.setCreationTime(new Timestamp(System.currentTimeMillis())); + applicationModuleEntity.setUpdateTime(new Timestamp(System.currentTimeMillis())); + return execute(entityManager -> entityManager.merge(applicationModuleEntity)); + } + + @Override + public String addApplicationModule(ApplicationModule applicationModule, String gatewayId) throws AppCatalogException { + return saveApplicationModuleData(applicationModule, gatewayId); + } + + @Override + public String addApplicationInterface(ApplicationInterfaceDescription applicationInterfaceDescription, String gatewayId) throws AppCatalogException { + return saveApplicationInterfaceDescriptorData(applicationInterfaceDescription, gatewayId); + } + + @Override + public void addApplicationModuleMapping(String moduleId, String interfaceId) throws AppCatalogException { + Mapper mapper = ObjectMapperSingleton.getInstance(); + ApplicationModule applicationModule = getApplicationModule(moduleId); + ApplicationInterfaceDescription applicationInterfaceDescription = getApplicationInterface(interfaceId); + ApplicationModuleEntity applicationModuleEntity = mapper.map(applicationModule, ApplicationModuleEntity.class); + ApplicationInterfaceEntity applicationInterfaceEntity = mapper.map(applicationInterfaceDescription, ApplicationInterfaceEntity.class); + AppModuleMappingEntity appModuleMappingEntity = new AppModuleMappingEntity(); + appModuleMappingEntity.setModuleId(moduleId); + appModuleMappingEntity.setInterfaceId(interfaceId); + appModuleMappingEntity.setApplicationModule(applicationModuleEntity); + appModuleMappingEntity.setApplicationInterface(applicationInterfaceEntity); + execute(entityManager -> entityManager.merge(appModuleMappingEntity)); + } + + @Override + public void updateApplicationModule(String moduleId, ApplicationModule updatedApplicationModule) throws AppCatalogException { + saveApplicationModuleData(updatedApplicationModule, null); + } + + @Override + public void updateApplicationInterface(String interfaceId, ApplicationInterfaceDescription updatedApplicationInterfaceDescription) throws AppCatalogException { + saveApplicationInterfaceDescriptorData(updatedApplicationInterfaceDescription, null); + } + + @Override + public ApplicationModule getApplicationModule(String moduleId) throws AppCatalogException { + ApplicationModuleRepository applicationModuleRepository = new ApplicationModuleRepository(); + Map<String, Object> queryParameters = new HashMap<>(); + queryParameters.put(DBConstants.ApplicationModule.APPLICATION_MODULE_ID, moduleId); + ApplicationModule applicationModule = applicationModuleRepository.select(QueryConstants.FIND_APPLICATION_MODULE, -1, 0, queryParameters).get(0); Review comment: Is it safe to directly call get(0)? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Refactoring App Catalog implementation - ApplicationDeployment and > ApplicationInterface > --------------------------------------------------------------------------------------- > > Key: AIRAVATA-2657 > URL: https://issues.apache.org/jira/browse/AIRAVATA-2657 > Project: Airavata > Issue Type: Task > Components: Application Catalog > Reporter: Sneha Tilak > Assignee: Sneha Tilak > Priority: Major > -- This message was sent by Atlassian JIRA (v7.6.3#76005)