initial public commit

This commit is contained in:
2021-09-06 17:46:59 +03:00
commit b744b08829
824 changed files with 91593 additions and 0 deletions

View File

@ -0,0 +1,44 @@
/*-
* ~~~~~~licensing~~~~~~
* connector-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.connector.impl;
import com.sun.istack.NotNull;
import ru.entaxy.esb.system.connector.entity.Connector;
import ru.entaxy.esb.system.jpa.entity.System;
import ru.entaxy.esb.system.management.bundle.jpa.entity.BundleEntity;
import java.util.List;
public interface ConnectorService {
List<Connector> getListConnector();
Connector getConnectorByName(String name);
Connector getConnectorByName(String systemUuid, String templateName);
void removeConnector(@NotNull Connector connector);
Connector saveOrUpdate(Connector connector);
Connector addConnector(System system, Connector connector);
Connector setBundleEntity(Connector connector, BundleEntity bundleEntity);
}

View File

@ -0,0 +1,180 @@
/*-
* ~~~~~~licensing~~~~~~
* connector-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.connector.impl;
import com.sun.istack.NotNull;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import ru.entaxy.esb.system.connector.entity.Connector;
import ru.entaxy.esb.system.jpa.entity.System;
import ru.entaxy.esb.system.management.bundle.jpa.entity.BundleEntity;
import javax.persistence.EntityGraph;
import javax.persistence.TypedQuery;
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 ConnectorServiceImpl implements ConnectorService {
private static final String JAVAX_PERSISTENCE_LOADGRAPH = "javax.persistence.loadgraph";
private static final String CONNECTOR_ENTITY_GRAPH = "connector-entity-graph";
private SessionFactory sessionFactory;
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
public Session getSession() {
return sessionFactory.openSession();
}
@Override
public Connector getConnectorByName(String name) {
Connector connector;
try (Session session = getSession()) {
session.getTransaction().begin();
EntityGraph entityGraph = session.getEntityGraph(CONNECTOR_ENTITY_GRAPH);
CriteriaBuilder builder = session.getCriteriaBuilder();
CriteriaQuery<Connector> criteriaQuery = builder.createQuery(Connector.class);
Root<Connector> root = criteriaQuery.from(Connector.class);
criteriaQuery.where(builder.equal(root.get("name"), name));
TypedQuery<Connector> typedQuery = session.createQuery(criteriaQuery);
typedQuery.setHint(JAVAX_PERSISTENCE_LOADGRAPH, entityGraph);
connector = typedQuery.getSingleResult();
session.getTransaction().commit();
}
return connector;
}
@Override
public Connector getConnectorByName(String systemUuid, String templateName) {
Connector connector;
try (Session session = getSession()) {
session.getTransaction().begin();
CriteriaBuilder builder = session.getCriteriaBuilder();
CriteriaQuery<Connector> criteriaQuery = builder.createQuery(Connector.class);
Root<System> root = criteriaQuery.from(System.class);
Join<System, Connector> connectorJoin = root.join("connectors");
criteriaQuery.select(connectorJoin);
criteriaQuery.where(builder.and(builder.equal(root.get("uuid"), systemUuid),
builder.equal(connectorJoin.get("templateName"), templateName)));
connector = session.createQuery(criteriaQuery).getSingleResult();
session.getTransaction().commit();
}
return connector;
}
@Override
public void removeConnector(@NotNull Connector connector) {
try (Session session = getSession()) {
session.getTransaction().begin();
session.delete(Connector.class.getName(), connector);
session.getTransaction().commit();
}
}
@Override
public Connector saveOrUpdate(Connector connector) {
try (Session session = getSession()) {
session.getTransaction().begin();
session.saveOrUpdate(connector);
session.getTransaction().commit();
}
return connector;
}
private System saveOrUpdate(System system) {
try (Session session = getSession()) {
session.getTransaction().begin();
session.saveOrUpdate(system);
session.getTransaction().commit();
}
return system;
}
@Override
public Connector addConnector(System system, Connector connector) {
Connector connectorEntity = getConnector(system, connector.getTemplateName());
if (connectorEntity == null) {
connectorEntity = connector;
connectorEntity.setName(connector.getTemplateName() + "-" + system.getName());
connectorEntity.setSystemId(system.getId());
system.getConnectors().add(connectorEntity);
} else {
connectorEntity.setEditDate(connector.getCreateDate());
connectorEntity.setEditedBy(connector.getCreatedBy());
}
this.saveOrUpdate(system);
return connectorEntity;
}
@Override
public Connector setBundleEntity(Connector connector, BundleEntity bundleEntity) {
bundleEntity.setVersion(connector.getVersion());
BundleEntity origin = connector.getBundleEntity();
if (connector.getBundleEntity() != null) {
origin.setUrl(bundleEntity.getUrl());
origin.setStatus(bundleEntity.getStatus());
} else {
bundleEntity.setVersion(connector.getVersion());
connector.setBundleEntity(bundleEntity);
}
return saveOrUpdate(connector);
}
@Override
public List<Connector> getListConnector() {
List<Connector> list;
try (Session session = getSession()) {
session.getTransaction().begin();
EntityGraph entityGraph = session.getEntityGraph(CONNECTOR_ENTITY_GRAPH);
CriteriaQuery<Connector> criteriaQuery = session.getCriteriaBuilder().createQuery(Connector.class);
criteriaQuery.from(Connector.class);
TypedQuery<Connector> typedQuery = session.createQuery(criteriaQuery);
typedQuery.setHint(JAVAX_PERSISTENCE_LOADGRAPH, entityGraph);
list = typedQuery.getResultList();
session.getTransaction().commit();
}
return list;
}
private Connector getConnector(System system, String templateName) {
for (Connector connector : system.getConnectors()) {
if (templateName.equals(connector.getTemplateName()))
return connector;
}
return null;
}
}

View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~~~~~~licensing~~~~~~
connector-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:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
<reference id="sessionFactory"
interface="org.hibernate.SessionFactory"
timeout="30000"/>
<bean id="connectorService" class="ru.entaxy.esb.system.connector.impl.ConnectorServiceImpl">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<service ref="connectorService" interface="ru.entaxy.esb.system.connector.impl.ConnectorService"/>
</blueprint>

View File

@ -0,0 +1,43 @@
<?xml version='1.0' encoding='utf-8'?>
<!--
~~~~~~licensing~~~~~~
connector-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.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"/>
</session-factory>
</hibernate-configuration>