initial public commit
This commit is contained in:
@ -0,0 +1,44 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* schema-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.registry.schema.exception;
|
||||
|
||||
public class ResourceInfoNotFound extends RuntimeException {
|
||||
|
||||
public ResourceInfoNotFound() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ResourceInfoNotFound(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
|
||||
public ResourceInfoNotFound(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public ResourceInfoNotFound(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ResourceInfoNotFound(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* schema-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.registry.schema.exception;
|
||||
|
||||
public class ResourceNotFound extends RuntimeException {
|
||||
|
||||
public ResourceNotFound() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ResourceNotFound(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
|
||||
public ResourceNotFound(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public ResourceNotFound(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ResourceNotFound(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,380 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* schema-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.registry.schema.impl;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import ru.entaxy.esb.system.registry.schema.api.ResourceService;
|
||||
import ru.entaxy.esb.system.registry.schema.api.entity.Resource;
|
||||
import ru.entaxy.esb.system.registry.schema.api.entity.ResourceInfo;
|
||||
import ru.entaxy.esb.system.registry.schema.exception.ResourceInfoNotFound;
|
||||
import ru.entaxy.esb.system.registry.schema.exception.ResourceNotFound;
|
||||
|
||||
import javax.persistence.EntityNotFoundException;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Root;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class ResourceServiceImpl implements ResourceService {
|
||||
|
||||
private SessionFactory sessionFactory;
|
||||
|
||||
public void setSessionFactory(SessionFactory sessionFactory) {
|
||||
this.sessionFactory = sessionFactory;
|
||||
}
|
||||
|
||||
public Session getSession() {
|
||||
return sessionFactory.openSession();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long loadResource(Resource resource) {
|
||||
long id;
|
||||
try (Session s = getSession()) {
|
||||
s.getTransaction().begin();
|
||||
id = (long) s.save(resource);
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long reloadResource(Resource resource) {
|
||||
try (Session s = getSession()) {
|
||||
s.getTransaction().begin();
|
||||
s.saveOrUpdate(reloadingResource(resource));
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
return resource.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Resource> getResource(long id) {
|
||||
Optional<Resource> resource;
|
||||
try (Session s = getSession()) {
|
||||
s.getTransaction().begin();
|
||||
|
||||
CriteriaBuilder builder = s.getCriteriaBuilder();
|
||||
CriteriaQuery<Resource> criteriaQuery = builder.createQuery(Resource.class);
|
||||
Root<Resource> root = criteriaQuery.from(Resource.class);
|
||||
criteriaQuery.where(
|
||||
builder.equal(root.get("id"), id)
|
||||
);
|
||||
resource = s.createQuery(criteriaQuery).uniqueResultOptional();
|
||||
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
return resource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Resource> getResourceByNamespace(String namespace) {
|
||||
Optional<ResourceInfo> resourceInfo;
|
||||
Optional<Resource> resource;
|
||||
try (Session s = getSession()) {
|
||||
s.getTransaction().begin();
|
||||
|
||||
CriteriaBuilder builder = s.getCriteriaBuilder();
|
||||
CriteriaQuery<ResourceInfo> criteriaQuery = builder.createQuery(ResourceInfo.class);
|
||||
Root<ResourceInfo> root = criteriaQuery.from(ResourceInfo.class);
|
||||
criteriaQuery.where(
|
||||
builder.equal(root.get("namespace"), namespace)
|
||||
);
|
||||
resourceInfo = s.createQuery(criteriaQuery).uniqueResultOptional();
|
||||
|
||||
if (resourceInfo.isEmpty()) {
|
||||
throw new ResourceInfoNotFound();
|
||||
}
|
||||
|
||||
resource = getResource(resourceInfo.get().getResourceId());
|
||||
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
return resource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Resource> getResourceByName(String name) {
|
||||
Optional<ResourceInfo> resourceInfo;
|
||||
Optional<Resource> resource;
|
||||
try (Session s = getSession()) {
|
||||
s.getTransaction().begin();
|
||||
|
||||
CriteriaBuilder builder = s.getCriteriaBuilder();
|
||||
CriteriaQuery<ResourceInfo> criteriaQuery = builder.createQuery(ResourceInfo.class);
|
||||
Root<ResourceInfo> root = criteriaQuery.from(ResourceInfo.class);
|
||||
criteriaQuery.where(
|
||||
builder.equal(root.get("name"), name)
|
||||
);
|
||||
resourceInfo = s.createQuery(criteriaQuery).uniqueResultOptional();
|
||||
|
||||
if (resourceInfo.isEmpty()) {
|
||||
throw new ResourceInfoNotFound();
|
||||
}
|
||||
|
||||
resource = getResource(resourceInfo.get().getResourceId());
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
return resource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Resource> getResourceByIdAndVersion(long id, String version) {
|
||||
Optional<ResourceInfo> resourceInfo;
|
||||
Optional<Resource> resource;
|
||||
try (Session s = getSession()) {
|
||||
s.getTransaction().begin();
|
||||
|
||||
CriteriaBuilder builder = s.getCriteriaBuilder();
|
||||
CriteriaQuery<ResourceInfo> criteriaQuery = builder.createQuery(ResourceInfo.class);
|
||||
Root<ResourceInfo> root = criteriaQuery.from(ResourceInfo.class);
|
||||
criteriaQuery.where(
|
||||
builder.and(
|
||||
builder.equal(root.get("id"), id),
|
||||
builder.equal(root.get("version"), version)
|
||||
)
|
||||
);
|
||||
resourceInfo = s.createQuery(criteriaQuery).uniqueResultOptional();
|
||||
if (resourceInfo.isEmpty()) {
|
||||
throw new ResourceInfoNotFound();
|
||||
}
|
||||
|
||||
resource = getResource(resourceInfo.get().getResourceId());
|
||||
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
return resource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeResource(long id) {
|
||||
try (Session session = getSession()) {
|
||||
session.getTransaction().begin();
|
||||
Optional<Resource> resource = getResource(id);
|
||||
if (resource.isEmpty()) {
|
||||
throw new ResourceNotFound("Resource not found with id {" + id + "}");
|
||||
}
|
||||
session.delete(Resource.class.getName(), resource.get());
|
||||
session.getTransaction().commit();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long loadResourceInfo(ResourceInfo resourceInfo) {
|
||||
long id;
|
||||
try (Session s = getSession()) {
|
||||
s.getTransaction().begin();
|
||||
if (resourceInfo.getResourceId() == null || getResource(resourceInfo.getResourceId()).isEmpty()) {
|
||||
throw new ResourceNotFound("Resource not found id {" + resourceInfo.getResourceId() + "}");
|
||||
}
|
||||
id = (long) s.save(resourceInfo);
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long editResourceInfo(ResourceInfo resourceInfo) {
|
||||
try (Session s = getSession()) {
|
||||
s.getTransaction().begin();
|
||||
s.saveOrUpdate(editedResourceInfo(resourceInfo));
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
return resourceInfo.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ResourceInfo> getResourceInfo(long id) {
|
||||
Optional<ResourceInfo> resourceInfo;
|
||||
try (Session s = getSession()) {
|
||||
s.getTransaction().begin();
|
||||
|
||||
CriteriaBuilder builder = s.getCriteriaBuilder();
|
||||
CriteriaQuery<ResourceInfo> criteriaQuery = builder.createQuery(ResourceInfo.class);
|
||||
Root<ResourceInfo> root = criteriaQuery.from(ResourceInfo.class);
|
||||
criteriaQuery.where(
|
||||
builder.equal(root.get("id"), id)
|
||||
);
|
||||
resourceInfo = s.createQuery(criteriaQuery).uniqueResultOptional();
|
||||
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
return resourceInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ResourceInfo> getResourceInfoByNamespace(String namespace) {
|
||||
Optional<ResourceInfo> resourceInfo;
|
||||
try (Session s = getSession()) {
|
||||
s.getTransaction().begin();
|
||||
|
||||
CriteriaBuilder builder = s.getCriteriaBuilder();
|
||||
CriteriaQuery<ResourceInfo> criteriaQuery = builder.createQuery(ResourceInfo.class);
|
||||
Root<ResourceInfo> root = criteriaQuery.from(ResourceInfo.class);
|
||||
criteriaQuery.where(
|
||||
builder.equal(root.get("namespace"), namespace)
|
||||
);
|
||||
resourceInfo = s.createQuery(criteriaQuery).uniqueResultOptional();
|
||||
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
return resourceInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ResourceInfo> getResourceInfoByName(String name) {
|
||||
Optional<ResourceInfo> resourceInfo;
|
||||
try (Session s = getSession()) {
|
||||
s.getTransaction().begin();
|
||||
|
||||
CriteriaBuilder builder = s.getCriteriaBuilder();
|
||||
CriteriaQuery<ResourceInfo> criteriaQuery = builder.createQuery(ResourceInfo.class);
|
||||
Root<ResourceInfo> root = criteriaQuery.from(ResourceInfo.class);
|
||||
criteriaQuery.where(
|
||||
builder.equal(root.get("name"), name)
|
||||
);
|
||||
resourceInfo = s.createQuery(criteriaQuery).uniqueResultOptional();
|
||||
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
return resourceInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ResourceInfo> getResourceInfoByIdAndVersion(long id, String version) {
|
||||
Optional<ResourceInfo> resourceInfo;
|
||||
try (Session s = getSession()) {
|
||||
s.getTransaction().begin();
|
||||
|
||||
CriteriaBuilder builder = s.getCriteriaBuilder();
|
||||
CriteriaQuery<ResourceInfo> criteriaQuery = builder.createQuery(ResourceInfo.class);
|
||||
Root<ResourceInfo> root = criteriaQuery.from(ResourceInfo.class);
|
||||
criteriaQuery.where(
|
||||
builder.and(
|
||||
builder.equal(root.get("id"), id),
|
||||
builder.equal(root.get("version"), version)
|
||||
)
|
||||
);
|
||||
resourceInfo = s.createQuery(criteriaQuery).uniqueResultOptional();
|
||||
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
return resourceInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeResourceInfo(long id) {
|
||||
try (Session session = getSession()) {
|
||||
session.getTransaction().begin();
|
||||
Optional<ResourceInfo> resourceInfo = getResourceInfo(id);
|
||||
if (resourceInfo.isEmpty()) {
|
||||
throw new ResourceInfoNotFound("Resource info not found with id {" + id + "}");
|
||||
}
|
||||
session.delete(ResourceInfo.class.getName(), resourceInfo.get());
|
||||
session.getTransaction().commit();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ResourceInfo> getListResourceInfo() {
|
||||
List<ResourceInfo> list;
|
||||
try (Session session = getSession()) {
|
||||
session.getTransaction().begin();
|
||||
CriteriaQuery<ResourceInfo> criteriaQuery = session.getCriteriaBuilder().createQuery(ResourceInfo.class);
|
||||
criteriaQuery.from(ResourceInfo.class);
|
||||
list = session.createQuery(criteriaQuery).getResultList();
|
||||
session.getTransaction().commit();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ResourceInfo> getListResourceInfoByName(String name) {
|
||||
List<ResourceInfo> list;
|
||||
try (Session session = getSession()) {
|
||||
session.getTransaction().begin();
|
||||
|
||||
CriteriaBuilder builder = session.getCriteriaBuilder();
|
||||
CriteriaQuery<ResourceInfo> criteriaQuery = builder.createQuery(ResourceInfo.class);
|
||||
Root<ResourceInfo> root = criteriaQuery.from(ResourceInfo.class);
|
||||
criteriaQuery.where(
|
||||
builder.like(root.get("name"), "%" + name + "%")
|
||||
);
|
||||
list = session.createQuery(criteriaQuery).getResultList();
|
||||
session.getTransaction().commit();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ResourceInfo> getListResourceInfoByNamespace(String namespace) {
|
||||
List<ResourceInfo> list;
|
||||
try (Session session = getSession()) {
|
||||
session.getTransaction().begin();
|
||||
|
||||
CriteriaBuilder builder = session.getCriteriaBuilder();
|
||||
CriteriaQuery<ResourceInfo> criteriaQuery = builder.createQuery(ResourceInfo.class);
|
||||
Root<ResourceInfo> root = criteriaQuery.from(ResourceInfo.class);
|
||||
criteriaQuery.where(
|
||||
builder.like(root.get("namespace"), "%" + namespace + "%")
|
||||
);
|
||||
list = session.createQuery(criteriaQuery).getResultList();
|
||||
session.getTransaction().commit();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private ResourceInfo editedResourceInfo(ResourceInfo newResourceInfo) {
|
||||
Optional<ResourceInfo> oldResource = getResourceInfo(newResourceInfo.getId());
|
||||
if (oldResource.isPresent()) {
|
||||
newResourceInfo.setCreatedBy(oldResource.get().getCreatedBy());
|
||||
newResourceInfo.setCreatedDate(oldResource.get().getCreatedDate());
|
||||
} else {
|
||||
throw new EntityNotFoundException();
|
||||
}
|
||||
return newResourceInfo;
|
||||
}
|
||||
|
||||
private Resource reloadingResource(Resource newResource) {
|
||||
Optional<Resource> oldResource = getResource(newResource.getId());
|
||||
if (oldResource.isPresent()) {
|
||||
newResource.setCreatedBy(oldResource.get().getCreatedBy());
|
||||
newResource.setCreatedDate(oldResource.get().getCreatedDate());
|
||||
newResource.setResourceValue(oldResource.get().getResourceValue());
|
||||
} else {
|
||||
throw new EntityNotFoundException();
|
||||
}
|
||||
return newResource;
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* schema-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.registry.schema.resolver.resource;
|
||||
|
||||
import org.apache.cxf.resource.ResourceResolver;
|
||||
import ru.entaxy.esb.system.registry.schema.api.ResourceService;
|
||||
import ru.entaxy.esb.system.registry.schema.api.entity.Resource;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.Optional;
|
||||
|
||||
public class CxfDBResourceResolver implements ResourceResolver {
|
||||
|
||||
private ResourceService resourceService;
|
||||
|
||||
@Override
|
||||
public <T> T resolve(String resourceName, Class<T> resourceType) {
|
||||
// null - because we need only resource from db
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getAsStream(String name) {
|
||||
Optional<Resource> resource = resourceService.getResourceByName(name);
|
||||
if (resource.isPresent()) {
|
||||
return new ByteArrayInputStream(resource.get().getResourceValue());
|
||||
} else {
|
||||
Optional<Resource> xsd = resourceService.getResourceByName(name);
|
||||
return xsd.map(value -> new ByteArrayInputStream(value.getResourceValue())).orElse(null);
|
||||
}
|
||||
}
|
||||
|
||||
public ResourceService getResourceService() {
|
||||
return resourceService;
|
||||
}
|
||||
|
||||
public void setResourceService(ResourceService resourceService) {
|
||||
this.resourceService = resourceService;
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* schema-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.registry.schema.resolver.resource;
|
||||
|
||||
import org.apache.cxf.Bus;
|
||||
import org.apache.cxf.resource.ResourceManager;
|
||||
import org.apache.cxf.resource.ResourceResolver;
|
||||
|
||||
public class DBResolverSettings {
|
||||
|
||||
private Bus bus;
|
||||
private ResourceResolver resourceResolver;
|
||||
|
||||
public void init() {
|
||||
if (bus != null) {
|
||||
ResourceManager resourceManager = bus.getExtension(org.apache.cxf.resource.ResourceManager.class);
|
||||
if (resourceManager != null) {
|
||||
resourceManager.addResourceResolver(resourceResolver);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setBus(Bus bus) {
|
||||
this.bus = bus;
|
||||
}
|
||||
|
||||
public void setResourceResolver(ResourceResolver resourceResolver) {
|
||||
this.resourceResolver = resourceResolver;
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* schema-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.registry.schema.resolver.resource;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.w3c.dom.ls.DOMImplementationLS;
|
||||
import org.w3c.dom.ls.LSInput;
|
||||
import org.w3c.dom.ls.LSResourceResolver;
|
||||
import ru.entaxy.esb.system.registry.schema.api.ResourceService;
|
||||
import ru.entaxy.esb.system.registry.schema.api.entity.Resource;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.Optional;
|
||||
|
||||
public class DBResourceResolver implements LSResourceResolver {
|
||||
|
||||
private static final Log LOG = LogFactory.getLog(DBResourceResolver.class);
|
||||
|
||||
private ResourceService resourceService;
|
||||
|
||||
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
|
||||
try {
|
||||
Optional<Resource> resource = resourceService.getResourceByName(systemId);
|
||||
if (resource.isPresent()) {
|
||||
DOMImplementationLS dils = (DOMImplementationLS) DocumentBuilderFactory.newInstance().newDocumentBuilder().getDOMImplementation();
|
||||
LSInput input = dils.createLSInput();
|
||||
input.setByteStream(new ByteArrayInputStream(resource.get().getResourceValue()));
|
||||
return input;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setResourceService(ResourceService resourceService) {
|
||||
this.resourceService = resourceService;
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* schema-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.registry.schema.resolver.resource;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import ru.entaxy.esb.system.registry.schema.api.ResourceService;
|
||||
import ru.entaxy.esb.system.registry.schema.api.entity.Resource;
|
||||
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.URIResolver;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.Optional;
|
||||
|
||||
public class XslUrlResolver implements URIResolver {
|
||||
|
||||
private static final Log LOG = LogFactory.getLog(XslUrlResolver.class);
|
||||
|
||||
private ResourceService resourceService;
|
||||
|
||||
@Override
|
||||
public Source resolve(String href, String base) throws TransformerException {
|
||||
try {
|
||||
Optional<Resource> resource = resourceService.getResourceByName(href);
|
||||
if (resource.isPresent()) {
|
||||
return new StreamSource(new ByteArrayInputStream(resource.get().getResourceValue()));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setResourceService(ResourceService resourceService) {
|
||||
this.resourceService = resourceService;
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~~~~~~licensing~~~~~~
|
||||
schema-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="resourceService" class="ru.entaxy.esb.system.registry.schema.impl.ResourceServiceImpl">
|
||||
<property name="sessionFactory" ref="sessionFactory"/>
|
||||
</bean>
|
||||
|
||||
<service ref="resourceService" interface="ru.entaxy.esb.system.registry.schema.api.ResourceService"/>
|
||||
|
||||
<bean id="cxfDBResourceResolver"
|
||||
class="ru.entaxy.esb.system.registry.schema.resolver.resource.CxfDBResourceResolver">
|
||||
<property name="resourceService" ref="resourceService"/>
|
||||
</bean>
|
||||
<service ref="cxfDBResourceResolver" interface="org.apache.cxf.resource.ResourceResolver"/>
|
||||
|
||||
<bean id="dbResourceResolver" class="ru.entaxy.esb.system.registry.schema.resolver.resource.DBResourceResolver">
|
||||
<property name="resourceService" ref="resourceService"/>
|
||||
</bean>
|
||||
<service ref="dbResourceResolver" interface="org.w3c.dom.ls.LSResourceResolver"/>
|
||||
|
||||
<bean id="xslUrlResolver" class="ru.entaxy.esb.system.registry.schema.resolver.resource.XslUrlResolver">
|
||||
<property name="resourceService" ref="resourceService"/>
|
||||
</bean>
|
||||
<service ref="xslUrlResolver" interface="javax.xml.transform.URIResolver"/>
|
||||
</blueprint>
|
@ -0,0 +1,38 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<!--
|
||||
~~~~~~licensing~~~~~~
|
||||
schema-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>
|
||||
|
||||
<mapping class="ru.entaxy.esb.system.registry.schema.api.entity.ResourceInfo"/>
|
||||
<mapping class="ru.entaxy.esb.system.registry.schema.api.entity.Resource"/>
|
||||
|
||||
</session-factory>
|
||||
|
||||
</hibernate-configuration>
|
Reference in New Issue
Block a user