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,40 @@
/*-
* ~~~~~~licensing~~~~~~
* bundle-service
* ==========
* 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.management.bundle.jpa;
import ru.entaxy.esb.system.management.bundle.jpa.entity.BundleEntity;
import ru.entaxy.esb.system.management.bundle.jpa.entity.BundleType;
import java.util.List;
public interface BundleService {
BundleEntity getByName(String name);
BundleEntity add(BundleEntity bundleEntity);
BundleEntity add(String name, String bundleUrl, String status);
BundleEntity add(String name, BundleType type, String bundleUrl, String status);
BundleEntity update(String name, String status);
List<BundleEntity> list();
}

View File

@ -0,0 +1,115 @@
/*-
* ~~~~~~licensing~~~~~~
* bundle-service
* ==========
* 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.management.bundle.jpa;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import ru.entaxy.esb.system.management.bundle.jpa.entity.BundleEntity;
import ru.entaxy.esb.system.management.bundle.jpa.entity.BundleType;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import java.util.List;
public class BundleServiceImpl implements BundleService {
private SessionFactory sessionFactory;
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
public Session getSession() {
return sessionFactory.openSession();
}
@Override
public List<BundleEntity> list() {
List<BundleEntity> list;
try (Session s = getSession()) {
s.getTransaction().begin();
CriteriaQuery<BundleEntity> cq = s.getCriteriaBuilder().createQuery(BundleEntity.class);
cq.from(BundleEntity.class);
list = s.createQuery(cq).getResultList();
s.getTransaction().commit();
s.close();
}
return list;
}
@Override
public BundleEntity add(BundleEntity bundleEntity) {
try (Session s = getSession()) {
s.getTransaction().begin();
s.saveOrUpdate(bundleEntity);
s.getTransaction().commit();
s.close();
}
return bundleEntity;
}
@Override
public BundleEntity add(String name, String bundleUrl, String status) {
BundleEntity bundleEntity = new BundleEntity();
bundleEntity.setName(name);
bundleEntity.setUrl(bundleUrl);
bundleEntity.setStatus(status);
return add(bundleEntity);
}
@Override
public BundleEntity add(String name, BundleType type, String bundleUrl, String status) {
BundleEntity bundleEntity = new BundleEntity();
bundleEntity.setName(name);
bundleEntity.setType(type);
bundleEntity.setUrl(bundleUrl);
bundleEntity.setStatus(status);
return add(bundleEntity);
}
@Override
public BundleEntity getByName(String name) {
BundleEntity bundleEntity;
try (Session s = getSession()) {
s.getTransaction().begin();
CriteriaBuilder builder = s.getCriteriaBuilder();
CriteriaQuery<BundleEntity> criteriaQuery = builder.createQuery(BundleEntity.class);
Root<BundleEntity> root = criteriaQuery.from(BundleEntity.class);
criteriaQuery.where(builder.equal(root.get("name"), name));
bundleEntity = s.createQuery(criteriaQuery).uniqueResult();
s.getTransaction().commit();
s.close();
}
return bundleEntity;
}
@Override
public BundleEntity update(String name, String status) {
BundleEntity bundleEntity = getByName(name);
bundleEntity.setStatus(status);
return add(bundleEntity);
}
}

View File

@ -0,0 +1,88 @@
/*-
* ~~~~~~licensing~~~~~~
* bundle-service
* ==========
* 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.management.bundle.jpa.dto;
import ru.entaxy.esb.system.management.bundle.jpa.entity.BundleType;
public class BundleDto {
private String bundleName;
private String bundleUrl;
private String version;
private BundleType type;
private BundleStatus status;
public BundleDto() {
}
public BundleDto(String bundleName) {
this.bundleName = bundleName;
}
public BundleDto(String bundleName, BundleStatus status) {
this.bundleName = bundleName;
this.status = status;
}
public BundleDto(String bundleName, BundleType type) {
this.bundleName = bundleName;
this.type = type;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public String getBundleName() {
return bundleName;
}
public void setBundleName(String bundleName) {
this.bundleName = bundleName;
}
public String getBundleUrl() {
return bundleUrl;
}
public void setBundleUrl(String bundleUrl) {
this.bundleUrl = bundleUrl;
}
public BundleType getType() {
return type;
}
public void setType(BundleType type) {
this.type = type;
}
public BundleStatus getStatus() {
return status;
}
public void setStatus(BundleStatus status) {
this.status = status;
}
}

View File

@ -0,0 +1,43 @@
/*-
* ~~~~~~licensing~~~~~~
* bundle-service
* ==========
* 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.management.bundle.jpa.dto;
public enum BundleStatus {
ACTIVE("ACTIVE"),
INSTALL("INSTALL"),
RESOLVED("RESOLVED"),
UNINSTALL("UNINSTALL");
private final String status;
BundleStatus(String status) {
this.status = status;
}
public String getStatus() {
return status;
}
// public static BundleStatus getStatus(String name) {
// return valueOf(name.toUpperCase());
// }
}

View File

@ -0,0 +1,102 @@
/*-
* ~~~~~~licensing~~~~~~
* bundle-service
* ==========
* 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.management.bundle.jpa.entity;
import javax.persistence.*;
@Entity
@Table(name = "bundle")
public class BundleEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private long id;
@Column(name = "name")
private String name;
@Column(name = "type")
@Enumerated(EnumType.STRING)
private BundleType type;
@Column(name = "status")
private String status;
@Column(name = "version")
private String version;
@Column(name = "url")
private String url;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public BundleType getType() {
return type;
}
public void setType(BundleType type) {
this.type = type;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
@Override
public String toString() {
return "BundleEntity{" +
"id=" + id +
", name='" + name + '\'' +
", status='" + status + '\'' +
", version='" + version + '\'' +
", url='" + url + '\'' +
'}';
}
}

View File

@ -0,0 +1,53 @@
/*-
* ~~~~~~licensing~~~~~~
* bundle-service
* ==========
* 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.management.bundle.jpa.entity;
import java.util.Arrays;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
public enum BundleType {
PROFILE("PROFILE"),
BRIDGE_PROFILE("BRIDGE-PROFILE"),
CONNECTOR("CONNECTOR");
public static final Map<String, BundleType> map;
private final String type;
BundleType(String type) {
this.type = type;
}
public String getType() {
return type;
}
public static BundleType getValueOf(String type) {
return map.containsKey(type) ? map.get(type) : null;
}
static {
map = Arrays.stream(BundleType.values())
.collect(Collectors.toMap(BundleType::getType, Function.identity()));
}
}

View File

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~~~~~~licensing~~~~~~
bundle-service
==========
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"/>
<service ref="bundleService"
interface="ru.entaxy.esb.system.management.bundle.jpa.BundleService"/>
<bean id="bundleService"
class="ru.entaxy.esb.system.management.bundle.jpa.BundleServiceImpl">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
</blueprint>

View File

@ -0,0 +1,39 @@
<?xml version='1.0' encoding='utf-8'?>
<!--
~~~~~~licensing~~~~~~
bundle-service
==========
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.management.bundle.jpa.entity.BundleEntity"/>
</session-factory>
</hibernate-configuration>