2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the “License”);
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the “License”);
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
36 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
38 package org.openecomp.portalapp.widget.service.impl;
40 import java.util.List;
42 import javax.transaction.Transactional;
44 import org.hibernate.Criteria;
45 import org.hibernate.Session;
46 import org.hibernate.SessionFactory;
47 import org.hibernate.Transaction;
48 import org.hibernate.criterion.Restrictions;
49 import org.openecomp.portalapp.widget.domain.MicroserviceData;
50 import org.openecomp.portalapp.widget.domain.MicroserviceParameter;
51 import org.openecomp.portalapp.widget.service.MicroserviceService;
52 import org.slf4j.Logger;
53 import org.slf4j.LoggerFactory;
54 import org.springframework.beans.factory.annotation.Autowired;
55 import org.springframework.context.annotation.EnableAspectJAutoProxy;
56 import org.springframework.stereotype.Service;
59 * TODO: moved all microservice-related code (domain, controller, service)
60 * from ecomp portal Backend to widget microservice
62 @Service("microserviceService")
64 @org.springframework.context.annotation.Configuration
65 @EnableAspectJAutoProxy
66 public class MicroserviceServiceImpl implements MicroserviceService{
68 private static final Logger logger = LoggerFactory.getLogger(MicroserviceServiceImpl.class);
71 private SessionFactory sessionFactory;
74 public Long saveMicroserivce(MicroserviceData newService) {
76 logger.debug("MicroserviceServiceImpl.saveMicroserivce: microservice={}", newService);
77 Session session = sessionFactory.openSession();
78 Transaction tx = session.beginTransaction();
79 session.save(newService);
85 logger.error("Exception occurred while performing MicroserviceServiceImpl.saveMicroserivce in widget microservices. Details:" + e.getMessage());
87 return newService.getId();
91 public void saveMicroserviceParameter(MicroserviceParameter newParameter) {
93 logger.debug("MicroserviceServiceImpl.saveMicroserviceData: microservice={}", newParameter);
94 Session session = sessionFactory.openSession();
95 Transaction tx = session.beginTransaction();
96 session.save(newParameter);
102 logger.error("Exception occurred while performing MicroserviceServiceImpl.saveMicroserviceData in widget microservices. Details:" + e.getMessage());
106 @SuppressWarnings("unchecked")
108 public Long getMicroserviceIdByName(String newServiceName) {
110 Session session = sessionFactory.openSession();
111 Criteria criteria = session.createCriteria(MicroserviceData.class)
112 .add(Restrictions.eq("name", newServiceName))
113 .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
115 List<MicroserviceData> services = criteria.list();
116 logger.debug("MicroserviceServiceImpl.getMicroserviceByName: result={}", services);
120 return (services.size() > 0) ? services.get(0).getId() : null;