initial public commit
This commit is contained in:
@ -0,0 +1,344 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* events-impl
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2021 EmDev LLC
|
||||
* ==========
|
||||
* Licensed 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.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.esb.system.core.events.jpa.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.query.Query;
|
||||
import ru.entaxy.esb.system.core.events.jpa.EventTopicService;
|
||||
import ru.entaxy.esb.system.core.events.jpa.SystemSubscriptionService;
|
||||
import ru.entaxy.esb.system.core.events.jpa.entity.EventTopic;
|
||||
import ru.entaxy.esb.system.core.permission.common.PermissionConstants;
|
||||
import ru.entaxy.esb.system.core.permission.jpa.PermissionService;
|
||||
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Root;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class EventTopicServiceImpl implements EventTopicService {
|
||||
|
||||
private static final Log LOG = LogFactory.getLog(EventTopicServiceImpl.class);
|
||||
|
||||
private SessionFactory sessionFactory;
|
||||
private PermissionService permissionService;
|
||||
private SystemSubscriptionService systemSubscriptionService;
|
||||
|
||||
public void setSessionFactory(SessionFactory sessionFactory) {
|
||||
this.sessionFactory = sessionFactory;
|
||||
}
|
||||
|
||||
public Session getSession() {
|
||||
return sessionFactory.openSession();
|
||||
}
|
||||
|
||||
public PermissionService getPermissionService() {
|
||||
return permissionService;
|
||||
}
|
||||
|
||||
public void setPermissionService(PermissionService permissionService) {
|
||||
this.permissionService = permissionService;
|
||||
}
|
||||
|
||||
public SystemSubscriptionService getSystemSubscriptionService() {
|
||||
return systemSubscriptionService;
|
||||
}
|
||||
|
||||
public void setSystemSubscriptionService(SystemSubscriptionService systemSubscriptionService) {
|
||||
this.systemSubscriptionService = systemSubscriptionService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EventTopic> list() {
|
||||
List<EventTopic> list;
|
||||
try (Session s = getSession()) {
|
||||
s.getTransaction().begin();
|
||||
CriteriaQuery<EventTopic> cq = s.getCriteriaBuilder().createQuery(EventTopic.class);
|
||||
cq.from(EventTopic.class);
|
||||
list = s.createQuery(cq).getResultList();
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EventTopic> listByDeleted(boolean deleted) {
|
||||
List<EventTopic> list;
|
||||
|
||||
try (Session s = getSession()) {
|
||||
s.getTransaction().begin();
|
||||
|
||||
CriteriaBuilder builder = s.getCriteriaBuilder();
|
||||
CriteriaQuery<EventTopic> cq = s.getCriteriaBuilder().createQuery(EventTopic.class);
|
||||
Root<EventTopic> root = cq.from(EventTopic.class);
|
||||
cq.where(builder.equal(root.get("deleted"), deleted));
|
||||
|
||||
list = s.createQuery(cq).getResultList();
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventTopic get(long id) {
|
||||
EventTopic eventTopic;
|
||||
try (Session s = getSession()) {
|
||||
s.getTransaction().begin();
|
||||
|
||||
Query<EventTopic> query = prepareQueryGet(s, id);
|
||||
eventTopic = query.getSingleResult();
|
||||
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
return eventTopic;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<EventTopic> fetch(long id) {
|
||||
Optional<EventTopic> eventTopic;
|
||||
try (Session s = getSession()) {
|
||||
s.getTransaction().begin();
|
||||
|
||||
Query<EventTopic> query = prepareQueryGet(s, id);
|
||||
eventTopic = query.uniqueResultOptional();
|
||||
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
return eventTopic;
|
||||
}
|
||||
|
||||
private Query<EventTopic> prepareQueryGet(Session s, long id) {
|
||||
CriteriaBuilder builder = s.getCriteriaBuilder();
|
||||
CriteriaQuery<EventTopic> criteriaQuery = builder.createQuery(EventTopic.class);
|
||||
Root<EventTopic> root = criteriaQuery.from(EventTopic.class);
|
||||
criteriaQuery.where(builder.equal(root.get("id"), id));
|
||||
return s.createQuery(criteriaQuery);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventTopic getByName(String name) {
|
||||
EventTopic eventTopic;
|
||||
try (Session s = getSession()) {
|
||||
s.getTransaction().begin();
|
||||
|
||||
Query<EventTopic> query = prepareQueryGetByName(s, name);
|
||||
eventTopic = query.getSingleResult();
|
||||
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
return eventTopic;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<EventTopic> fetchByName(String name) {
|
||||
Optional<EventTopic> eventTopic;
|
||||
try (Session s = getSession()) {
|
||||
s.getTransaction().begin();
|
||||
|
||||
Query<EventTopic> query = prepareQueryGetByName(s, name);
|
||||
eventTopic = query.uniqueResultOptional();
|
||||
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
return eventTopic;
|
||||
}
|
||||
|
||||
private Query<EventTopic> prepareQueryGetByName(Session s, String name) {
|
||||
CriteriaBuilder builder = s.getCriteriaBuilder();
|
||||
CriteriaQuery<EventTopic> criteriaQuery = builder.createQuery(EventTopic.class);
|
||||
Root<EventTopic> root = criteriaQuery.from(EventTopic.class);
|
||||
criteriaQuery.where(builder.equal(root.get("name"), name));
|
||||
return s.createQuery(criteriaQuery);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventTopic getByNameAndDeleted(String name, boolean deleted) {
|
||||
EventTopic eventTopic;
|
||||
try (Session s = getSession()) {
|
||||
s.getTransaction().begin();
|
||||
|
||||
Query<EventTopic> query = prepareQueryGetByNameAndDeleted(s, name, deleted);
|
||||
eventTopic = query.getSingleResult();
|
||||
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
return eventTopic;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<EventTopic> fetchByNameAndDeleted(String name, boolean deleted) {
|
||||
Optional<EventTopic> eventTopic;
|
||||
try (Session s = getSession()) {
|
||||
s.getTransaction().begin();
|
||||
|
||||
Query<EventTopic> query = prepareQueryGetByNameAndDeleted(s, name, deleted);
|
||||
eventTopic = query.uniqueResultOptional();
|
||||
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
return eventTopic;
|
||||
}
|
||||
|
||||
private Query<EventTopic> prepareQueryGetByNameAndDeleted(Session s, String name, boolean deleted) {
|
||||
CriteriaBuilder builder = s.getCriteriaBuilder();
|
||||
CriteriaQuery<EventTopic> criteriaQuery = builder.createQuery(EventTopic.class);
|
||||
Root<EventTopic> root = criteriaQuery.from(EventTopic.class);
|
||||
criteriaQuery.where(builder.and(
|
||||
builder.equal(root.get("name"), name),
|
||||
builder.equal(root.get("deleted"), deleted)
|
||||
));
|
||||
return s.createQuery(criteriaQuery);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventTopic add(EventTopic eventTopic) {
|
||||
try (Session s = getSession()) {
|
||||
s.getTransaction().begin();
|
||||
s.persist(eventTopic);
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
return eventTopic;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventTopic add(String name, String createdBy) {
|
||||
EventTopic eventTopic = new EventTopic();
|
||||
eventTopic.setName(name);
|
||||
eventTopic.setCreateDate(new Date());
|
||||
eventTopic.setCreatedBy(createdBy);
|
||||
|
||||
return add(eventTopic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventTopic update(EventTopic eventTopic) {
|
||||
Optional<EventTopic> topicOldOpt = fetch(eventTopic.getId());
|
||||
return save(eventTopic, topicOldOpt.isPresent());
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventTopic update(long id, String name, String editedBy) {
|
||||
EventTopic eventTopic = get(id);
|
||||
fillModel(eventTopic, name, eventTopic.getCreateDate(), eventTopic.getCreatedBy(), new Date(), editedBy);
|
||||
return save(eventTopic, true);
|
||||
}
|
||||
|
||||
private void fillModel(EventTopic eventTopic, String name, Date createDate,
|
||||
String createdBy, Date editDate, String editedBy) {
|
||||
eventTopic.setName(name);
|
||||
eventTopic.setCreateDate(createDate);
|
||||
eventTopic.setCreatedBy(createdBy);
|
||||
eventTopic.setEditDate(editDate);
|
||||
eventTopic.setEditedBy(editedBy);
|
||||
}
|
||||
|
||||
private EventTopic save(EventTopic topic, boolean isExist) {
|
||||
try (Session s = getSession()) {
|
||||
s.getTransaction().begin();
|
||||
if (isExist) {
|
||||
s.update(topic);
|
||||
} else {
|
||||
s.persist(topic);
|
||||
}
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
return topic;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(EventTopic eventTopic) {
|
||||
try (Session s = getSession()) {
|
||||
s.getTransaction().begin();
|
||||
|
||||
processRemove(s, eventTopic);
|
||||
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void processRemove(Session s, EventTopic eventTopic) {
|
||||
permissionService.removeAll(s, eventTopic.getId(), PermissionConstants.TYPE_EVENT_TOPIC);
|
||||
s.flush();
|
||||
systemSubscriptionService.removeByTopic(s, eventTopic.getId());
|
||||
s.flush();
|
||||
s.delete(EventTopic.class.getName(), eventTopic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(long id) {
|
||||
try (Session s = getSession()) {
|
||||
s.getTransaction().begin();
|
||||
|
||||
EventTopic eventTopic = get(id);
|
||||
|
||||
processRemove(s, eventTopic);
|
||||
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markAsDeleted(long id, boolean deleted) {
|
||||
try (Session s = getSession()) {
|
||||
s.getTransaction().begin();
|
||||
|
||||
EventTopic eventTopic = get(id);
|
||||
|
||||
systemSubscriptionService.markAsDeletedByTopic(s, eventTopic.getId(), deleted);
|
||||
s.flush();
|
||||
|
||||
eventTopic.setDeleted(deleted);
|
||||
s.update(eventTopic);
|
||||
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int clean() {
|
||||
List<EventTopic> listToDelete = listByDeleted(true);
|
||||
|
||||
listToDelete.forEach(t -> remove(t));
|
||||
|
||||
return listToDelete.size();
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,339 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* events-impl
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2021 EmDev LLC
|
||||
* ==========
|
||||
* Licensed 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.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.esb.system.core.events.jpa.impl;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import ru.entaxy.esb.system.core.events.common.SubscriptionType;
|
||||
import ru.entaxy.esb.system.core.events.jpa.SystemSubscriptionService;
|
||||
import ru.entaxy.esb.system.core.events.jpa.entity.EventTopic;
|
||||
import ru.entaxy.esb.system.core.events.jpa.entity.SystemSubscription;
|
||||
import ru.entaxy.esb.system.core.permission.common.PermissionConstants;
|
||||
import ru.entaxy.esb.system.core.permission.jpa.PermissionService;
|
||||
import ru.entaxy.esb.system.jpa.entity.System;
|
||||
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Join;
|
||||
import javax.persistence.criteria.Root;
|
||||
import java.util.List;
|
||||
|
||||
public class SystemSubscriptionServiceImpl implements SystemSubscriptionService {
|
||||
|
||||
private SessionFactory sessionFactory;
|
||||
private PermissionService permissionService;
|
||||
|
||||
|
||||
public void setSessionFactory(SessionFactory sessionFactory) {
|
||||
this.sessionFactory = sessionFactory;
|
||||
}
|
||||
|
||||
public Session getSession() {
|
||||
return sessionFactory.openSession();
|
||||
}
|
||||
|
||||
public PermissionService getPermissionService() {
|
||||
return permissionService;
|
||||
}
|
||||
|
||||
public void setPermissionService(PermissionService permissionService) {
|
||||
this.permissionService = permissionService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SystemSubscription> list() {
|
||||
List<SystemSubscription> list;
|
||||
|
||||
try (Session s = getSession()) {
|
||||
s.getTransaction().begin();
|
||||
|
||||
CriteriaQuery<SystemSubscription> cq = s.getCriteriaBuilder().createQuery(SystemSubscription.class);
|
||||
cq.from(SystemSubscription.class);
|
||||
list = s.createQuery(cq).getResultList();
|
||||
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SystemSubscription> listByDeleted(boolean deleted) {
|
||||
List<SystemSubscription> list;
|
||||
|
||||
try (Session s = getSession()) {
|
||||
s.getTransaction().begin();
|
||||
|
||||
CriteriaBuilder builder = s.getCriteriaBuilder();
|
||||
CriteriaQuery<SystemSubscription> criteriaQuery = builder.createQuery(SystemSubscription.class);
|
||||
Root<SystemSubscription> root = criteriaQuery.from(SystemSubscription.class);
|
||||
criteriaQuery.where(builder.equal(root.get("deleted"), deleted));
|
||||
list = s.createQuery(criteriaQuery).getResultList();
|
||||
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SystemSubscription get(long id) {
|
||||
SystemSubscription systemSubscriptionRegistry;
|
||||
|
||||
try (Session s = getSession()) {
|
||||
s.getTransaction().begin();
|
||||
|
||||
CriteriaBuilder builder = s.getCriteriaBuilder();
|
||||
CriteriaQuery<SystemSubscription> criteriaQuery = builder.createQuery(SystemSubscription.class);
|
||||
Root<SystemSubscription> root = criteriaQuery.from(SystemSubscription.class);
|
||||
criteriaQuery.where(builder.equal(root.get("id"), id));
|
||||
systemSubscriptionRegistry = s.createQuery(criteriaQuery).getSingleResult();
|
||||
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
return systemSubscriptionRegistry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SystemSubscription> getBySystem(long systemId) {
|
||||
List<SystemSubscription> list;
|
||||
|
||||
try (Session s = getSession()) {
|
||||
s.getTransaction().begin();
|
||||
|
||||
CriteriaBuilder builder = s.getCriteriaBuilder();
|
||||
CriteriaQuery<SystemSubscription> criteriaQuery = builder.createQuery(SystemSubscription.class);
|
||||
Root<SystemSubscription> root = criteriaQuery.from(SystemSubscription.class);
|
||||
Join<SystemSubscription, System> systemJoin = root.join("system");
|
||||
criteriaQuery.where(builder.equal(systemJoin.get("id"), systemId));
|
||||
list = s.createQuery(criteriaQuery).getResultList();
|
||||
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SystemSubscription getBySystemAndTopic(long systemId, long eventTopicId) {
|
||||
SystemSubscription systemSubscriptionRegistry;
|
||||
|
||||
try (Session s = getSession()) {
|
||||
s.getTransaction().begin();
|
||||
|
||||
CriteriaBuilder builder = s.getCriteriaBuilder();
|
||||
CriteriaQuery<SystemSubscription> criteriaQuery = builder.createQuery(SystemSubscription.class);
|
||||
Root<SystemSubscription> root = criteriaQuery.from(SystemSubscription.class);
|
||||
Join<SystemSubscription, System> systemJoin = root.join("system");
|
||||
Join<SystemSubscription, EventTopic> eventTopicJoin = root.join("eventTopic");
|
||||
criteriaQuery.where(builder.and(
|
||||
builder.equal(systemJoin.get("id"), systemId),
|
||||
builder.equal(eventTopicJoin.get("id"), eventTopicId)));
|
||||
systemSubscriptionRegistry = s.createQuery(criteriaQuery).getSingleResult();
|
||||
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
return systemSubscriptionRegistry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SystemSubscription> getByTopic(long eventTopicId) {
|
||||
List<SystemSubscription> list;
|
||||
|
||||
try (Session s = getSession()) {
|
||||
s.getTransaction().begin();
|
||||
|
||||
list = getByTopic(s, eventTopicId);
|
||||
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SystemSubscription> getByTopic(Session s, long eventTopicId) {
|
||||
CriteriaBuilder builder = s.getCriteriaBuilder();
|
||||
CriteriaQuery<SystemSubscription> criteriaQuery = builder.createQuery(SystemSubscription.class);
|
||||
Root<SystemSubscription> root = criteriaQuery.from(SystemSubscription.class);
|
||||
Join<SystemSubscription, EventTopic> eventTopicJoin = root.join("eventTopic");
|
||||
criteriaQuery.where(builder.equal(eventTopicJoin.get("id"), eventTopicId));
|
||||
return s.createQuery(criteriaQuery).getResultList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SystemSubscription> getByTopicAndType(long eventTopicId, SubscriptionType type) {
|
||||
List<SystemSubscription> list;
|
||||
|
||||
try (Session s = getSession()) {
|
||||
s.getTransaction().begin();
|
||||
|
||||
CriteriaBuilder builder = s.getCriteriaBuilder();
|
||||
CriteriaQuery<SystemSubscription> criteriaQuery = builder.createQuery(SystemSubscription.class);
|
||||
Root<SystemSubscription> root = criteriaQuery.from(SystemSubscription.class);
|
||||
Join<SystemSubscription, EventTopic> eventTopicJoin = root.join("eventTopic");
|
||||
criteriaQuery.where(builder.and(
|
||||
builder.equal(root.get("type"), type),
|
||||
builder.equal(eventTopicJoin.get("id"), eventTopicId)));
|
||||
list = s.createQuery(criteriaQuery).getResultList();
|
||||
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SystemSubscription> getByType(SubscriptionType type) {
|
||||
List<SystemSubscription> list;
|
||||
|
||||
try (Session s = getSession()) {
|
||||
s.getTransaction().begin();
|
||||
|
||||
CriteriaBuilder builder = s.getCriteriaBuilder();
|
||||
CriteriaQuery<SystemSubscription> criteriaQuery = builder.createQuery(SystemSubscription.class);
|
||||
Root<SystemSubscription> root = criteriaQuery.from(SystemSubscription.class);
|
||||
criteriaQuery.where(builder.equal(root.get("type"), type));
|
||||
list = s.createQuery(criteriaQuery).getResultList();
|
||||
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SystemSubscription add(SystemSubscription systemSubscriptionRegistry) throws IllegalAccessException {
|
||||
try (Session s = getSession()) {
|
||||
s.getTransaction().begin();
|
||||
if (!permissionService.existByAllParameters(
|
||||
systemSubscriptionRegistry.getEventTopic().getId(),
|
||||
PermissionConstants.TYPE_EVENT_TOPIC,
|
||||
String.valueOf(systemSubscriptionRegistry.getSystem().getId()),
|
||||
PermissionConstants.TYPE_SYSTEM,
|
||||
PermissionConstants.ACTION_SUBSCRIBE)) {
|
||||
throw new IllegalAccessException("No permission to subscribe");
|
||||
}
|
||||
|
||||
s.persist(systemSubscriptionRegistry);
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
return systemSubscriptionRegistry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SystemSubscription add(System system, EventTopic eventTopic, SubscriptionType type) throws IllegalAccessException {
|
||||
SystemSubscription systemSubscriptionRegistry = new SystemSubscription();
|
||||
|
||||
systemSubscriptionRegistry.setSystem(system);
|
||||
systemSubscriptionRegistry.setEventTopic(eventTopic);
|
||||
systemSubscriptionRegistry.setType(type);
|
||||
|
||||
return add(systemSubscriptionRegistry);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SystemSubscription update(SystemSubscription systemSubscriptionRegistry) {
|
||||
try (Session s = getSession()) {
|
||||
s.getTransaction().begin();
|
||||
s.merge(systemSubscriptionRegistry);
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
return systemSubscriptionRegistry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(long id) {
|
||||
try (Session s = getSession()) {
|
||||
s.getTransaction().begin();
|
||||
|
||||
SystemSubscription systemSubscriptionRegistry = get(id);
|
||||
s.delete(SystemSubscription.class.getName(), systemSubscriptionRegistry);
|
||||
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeByTopic(long eventTopicId) {
|
||||
try (Session s = getSession()) {
|
||||
s.getTransaction().begin();
|
||||
removeByTopic(s, eventTopicId);
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeByTopic(Session s, long eventTopicId) {
|
||||
List<SystemSubscription> subscriptions = getByTopic(s, eventTopicId);
|
||||
subscriptions.forEach(s::delete);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markAsDeleted(long id, boolean deleted) {
|
||||
try (Session s = getSession()) {
|
||||
SystemSubscription systemSubscription = get(id);
|
||||
s.getTransaction().begin();
|
||||
systemSubscription.setDeleted(deleted);
|
||||
s.update(systemSubscription);
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markAsDeletedByTopic(long eventTopicId, boolean deleted) {
|
||||
try (Session s = getSession()) {
|
||||
s.getTransaction().begin();
|
||||
markAsDeletedByTopic(s, eventTopicId, deleted);
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markAsDeletedByTopic(Session s, long eventTopicId, boolean deleted) {
|
||||
List<SystemSubscription> subscriptions = getByTopic(s, eventTopicId);
|
||||
subscriptions.forEach(subscription -> this.markAsDeletedProc(s, subscription, deleted));
|
||||
}
|
||||
|
||||
private void markAsDeletedProc(Session s, SystemSubscription subscription, boolean deleted) {
|
||||
subscription.setDeleted(deleted);
|
||||
s.update(subscription);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,136 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~~~~~~licensing~~~~~~
|
||||
events-impl
|
||||
==========
|
||||
Copyright (C) 2020 - 2021 EmDev LLC
|
||||
==========
|
||||
Licensed 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.
|
||||
~~~~~~/licensing~~~~~~
|
||||
-->
|
||||
|
||||
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
|
||||
xmlns:jpa="http://aries.apache.org/xmlns/jpa/v2.0.0"
|
||||
xmlns:tx="http://aries.apache.org/xmlns/transactions/v1.2.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 https://osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
|
||||
|
||||
<jpa:enable/>
|
||||
<tx:enable-annotations/>
|
||||
|
||||
<reference id="sessionFactory"
|
||||
interface="org.hibernate.SessionFactory"
|
||||
timeout="30000"/>
|
||||
|
||||
<reference id="permissionService"
|
||||
interface="ru.entaxy.esb.system.core.permission.jpa.PermissionService"
|
||||
timeout="30000"
|
||||
availability="mandatory"/>
|
||||
|
||||
<service ref="eventTopicService"
|
||||
interface="ru.entaxy.esb.system.core.events.jpa.EventTopicService"/>
|
||||
|
||||
<bean id="eventTopicService"
|
||||
class="ru.entaxy.esb.system.core.events.jpa.impl.EventTopicServiceImpl">
|
||||
<property name="sessionFactory" ref="sessionFactory"/>
|
||||
<property name="permissionService" ref="permissionService"/>
|
||||
<property name="systemSubscriptionService" ref="systemSubscriptionService"/>
|
||||
</bean>
|
||||
|
||||
<service ref="systemSubscriptionService"
|
||||
interface="ru.entaxy.esb.system.core.events.jpa.SystemSubscriptionService"/>
|
||||
|
||||
<bean id="systemSubscriptionService"
|
||||
class="ru.entaxy.esb.system.core.events.jpa.impl.SystemSubscriptionServiceImpl">
|
||||
<property name="sessionFactory" ref="sessionFactory"/>
|
||||
<property name="permissionService" ref="permissionService"/>
|
||||
</bean>
|
||||
|
||||
<camelContext id="test-hiber-context" xmlns="http://camel.apache.org/schema/blueprint">
|
||||
|
||||
<route id="list" autoStartup="false">
|
||||
<from uri="timer:foo?period=15000&repeatCount=1"/>
|
||||
|
||||
<to uri="direct:eventTopicService"/>
|
||||
|
||||
</route>
|
||||
|
||||
<route id="eventTopicService" autoStartup="true">
|
||||
<from uri="direct:eventTopicService"/>
|
||||
|
||||
<log message="TEST---------------------EventTopicService------------------"/>
|
||||
|
||||
<bean ref="eventTopicService" method="list"/>
|
||||
<log message="All topics ${body}"/>
|
||||
|
||||
<when>
|
||||
<simple>${body} != null && ${body.size()} > 0</simple>
|
||||
<split>
|
||||
<simple>${body}</simple>
|
||||
|
||||
<log message="-----------------Preferred involved topic ${body}-----------"/>
|
||||
|
||||
<setHeader name="TOPIC">
|
||||
<simple>${body}</simple>
|
||||
</setHeader>
|
||||
<setBody>
|
||||
<simple>null</simple>
|
||||
</setBody>
|
||||
<bean ref="eventTopicService" method="get(${header.TOPIC.getId()})"/>
|
||||
<log message="Topic by id ${body}"/>
|
||||
|
||||
<bean ref="eventTopicService" method="getByName(${header.TOPIC.getName()})"/>
|
||||
<log message="Topic by name ${body}"/>
|
||||
|
||||
<log message="----------------------------------------------}-----------"/>
|
||||
</split>
|
||||
|
||||
<setHeader name="TOPIC">
|
||||
<simple>${body.get(0)}</simple>
|
||||
</setHeader>
|
||||
|
||||
<log message="Set id 0 ${header.TOPIC.setId(0)}"/>
|
||||
<log message="Set topicName ${header.TOPIC.setName('testTopic')}"/>
|
||||
<log message="ADD NEW topic - testTopic"/>
|
||||
<bean ref="eventTopicService" method="add(${header.TOPIC})"/>
|
||||
|
||||
<!-- <setBody> -->
|
||||
<!-- <simple resultType="java.lang.String">testTopic2</simple> -->
|
||||
<!-- </setBody> -->
|
||||
|
||||
<!-- <bean ref="eventTopicService" method="saveOrUpdate(java.lang.String, ${header.TOPIC.getCreateDate()}, ${header.TOPIC.getCreatedBy())" /> -->
|
||||
|
||||
<bean ref="eventTopicService" method="getByName('testTopic')"/>
|
||||
<log message="NEW Topic by topicName ${body}"/>
|
||||
<bean ref="eventTopicService" method="remove(${body.getId()})"/>
|
||||
<log message="DELETE Topic by Id ${body.getId()}"/>
|
||||
|
||||
<!-- <bean ref="eventTopicService" method="getByName('testTopic2')" /> -->
|
||||
<!-- <log message="NEW Topic by topicName ${body}" /> -->
|
||||
<!-- <bean ref="eventTopicService" method="remove(${body.getId()})" /> -->
|
||||
<!-- <log message="DELETE Topic by Id ${body.getId()}" /> -->
|
||||
|
||||
<doTry>
|
||||
<bean ref="eventTopicService" method="getByName('testTopic')"/>
|
||||
<log message="NEW Topic by topicName AFTER DELETE ${body}"/>
|
||||
<doCatch>
|
||||
<exception>javax.persistence.NoResultException</exception>
|
||||
<log message="EventTopic not found" loggingLevel="WARN"/>
|
||||
</doCatch>
|
||||
</doTry>
|
||||
</when>
|
||||
</route>
|
||||
|
||||
</camelContext>
|
||||
|
||||
</blueprint>
|
@ -0,0 +1,48 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<!--
|
||||
~~~~~~licensing~~~~~~
|
||||
events-impl
|
||||
==========
|
||||
Copyright (C) 2020 - 2021 EmDev LLC
|
||||
==========
|
||||
Licensed 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.
|
||||
~~~~~~/licensing~~~~~~
|
||||
-->
|
||||
|
||||
<!DOCTYPE hibernate-configuration PUBLIC
|
||||
"-//Hibernate/Hibernate Configuration DTD//EN"
|
||||
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
|
||||
|
||||
<hibernate-configuration>
|
||||
|
||||
<session-factory>
|
||||
<property name="connection.datasource">osgi:service/entaxy.esb.storage</property>
|
||||
<property name="hibernate.hbm2ddl.auto">validate</property>
|
||||
|
||||
<property name="hibernate.enable_lazy_load_no_trans">true</property>
|
||||
|
||||
<property name="show_sql">${hibernate.show_sql}</property>
|
||||
<property name="format_sql">${hibernate.format_sql}</property>
|
||||
|
||||
<mapping class="ru.entaxy.esb.system.core.events.jpa.entity.EventTopic"/>
|
||||
<mapping class="ru.entaxy.esb.system.core.events.jpa.entity.SystemSubscription"/>
|
||||
|
||||
<mapping class="ru.entaxy.esb.system.jpa.entity.System"/>
|
||||
<mapping class="ru.entaxy.esb.system.management.bundle.jpa.entity.BundleEntity"/>
|
||||
<mapping class="ru.entaxy.esb.system.jpa.entity.ExportAllowed"/>
|
||||
<mapping class="ru.entaxy.esb.system.connector.entity.Connector"/>
|
||||
<mapping class="ru.entaxy.esb.system.connector.entity.ConnectorParam"/>
|
||||
<mapping class="ru.entaxy.esb.system.core.permission.jpa.entity.Permission"/>
|
||||
</session-factory>
|
||||
|
||||
</hibernate-configuration>
|
Reference in New Issue
Block a user