ENTAXY-480 release version 1.8.3
This commit is contained in:
@ -0,0 +1,128 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* schema-impl
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 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.platform.runtime.core.infrastructure.schema.resolver.resource;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Calendar;
|
||||
|
||||
import org.apache.camel.Exchange;
|
||||
import org.apache.camel.Processor;
|
||||
import org.apache.camel.component.file.GenericFile;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ru.entaxy.esb.platform.runtime.core.infrastructure.schema.api.ResourceService;
|
||||
import ru.entaxy.esb.platform.runtime.core.infrastructure.schema.api.entity.Resource;
|
||||
import ru.entaxy.esb.platform.runtime.core.infrastructure.schema.api.entity.ResourceInfo;
|
||||
|
||||
public class ResourceLoader implements Processor {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(ResourceLoader.class);
|
||||
|
||||
protected ResourceService resourceService;
|
||||
|
||||
public ResourceService getResourceService() {
|
||||
return resourceService;
|
||||
}
|
||||
|
||||
public void setResourceService(ResourceService resourceService) {
|
||||
this.resourceService = resourceService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(Exchange exchange) throws Exception {
|
||||
log.info("BODY IS [{}]\nHEADERS ARE:\n{}"
|
||||
, exchange.getIn().getBody().getClass().getName()
|
||||
, exchange.getIn().getHeaders().toString());
|
||||
String camelFileName = exchange.getIn().getHeader("CamelFilePath", String.class);
|
||||
String fileNameAndPath = camelFileName;//.substring(0, camelFileName.lastIndexOf("."));
|
||||
String fileName = getFileName(camelFileName);
|
||||
String filePath = getFilePath(camelFileName);
|
||||
String fileType = camelFileName.substring(camelFileName.lastIndexOf(".")+1);
|
||||
|
||||
Resource resource = null;
|
||||
|
||||
try {
|
||||
resource = resourceService.getResourceByFullName(fileNameAndPath).orElse(null);
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
if (resource ==null) {
|
||||
|
||||
resource = new Resource();
|
||||
resource.setCreatedBy("admin");
|
||||
resource.setCreatedDate(Calendar.getInstance().getTime());
|
||||
|
||||
GenericFile<?> genericFile = exchange.getIn().getBody(GenericFile.class);
|
||||
log.info("FILE IS {}", genericFile.getFile().getClass().getName());
|
||||
|
||||
|
||||
resource.setResourceValue(
|
||||
Files.readAllBytes(((File)genericFile.getFile()).toPath())
|
||||
);
|
||||
|
||||
long resourceId = resourceService.loadResource(resource);
|
||||
|
||||
ResourceInfo resourceInfo = new ResourceInfo();
|
||||
resourceInfo.setCreatedBy("admin");
|
||||
resourceInfo.setCreatedDate(Calendar.getInstance().getTime());
|
||||
resourceInfo.setConvertor(false);
|
||||
resourceInfo.setDescription("Automatically loaded with type [" + fileType + "]");
|
||||
|
||||
|
||||
resourceInfo.setName(fileName);
|
||||
resourceInfo.setPath(filePath);
|
||||
|
||||
resourceInfo.setVersion("1.0");
|
||||
resourceInfo.setResourceId(resourceId);
|
||||
|
||||
long resourceInfoId = resourceService.loadResourceInfo(resourceInfo);
|
||||
|
||||
log.info("ResourceInfo id is [" + resourceInfoId + "]");
|
||||
|
||||
} else {
|
||||
GenericFile<?> genericFile = exchange.getIn().getBody(GenericFile.class);
|
||||
log.info("FILE IS {}", genericFile.getFile().getClass().getName());
|
||||
|
||||
|
||||
resource.setResourceValue(
|
||||
Files.readAllBytes(((File)genericFile.getFile()).toPath())
|
||||
);
|
||||
|
||||
resourceService.reloadResource(resource);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private String getFileName(String fileNameAndPath) {
|
||||
String[] splitted = fileNameAndPath.split(File.separator);
|
||||
return splitted[splitted.length-1];
|
||||
}
|
||||
|
||||
private String getFilePath(String fileNameAndPath) {
|
||||
String[] splitted = fileNameAndPath.split(File.separator);
|
||||
String path = null;
|
||||
if (splitted.length>1) {
|
||||
path = fileNameAndPath.substring(0, fileNameAndPath.length() - splitted[splitted.length-1].length());
|
||||
}
|
||||
return path;
|
||||
}
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* schema-impl
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 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.platform.runtime.core.infrastructure.schema.resolver.resource;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
import org.osgi.service.component.annotations.CollectionType;
|
||||
import org.osgi.service.component.annotations.Component;
|
||||
import org.osgi.service.component.annotations.Reference;
|
||||
import org.osgi.service.component.annotations.ReferenceCardinality;
|
||||
import org.osgi.service.url.AbstractURLStreamHandlerService;
|
||||
import org.osgi.service.url.URLStreamHandlerService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ru.entaxy.esb.platform.runtime.core.infrastructure.schema.api.ResourceService;
|
||||
import ru.entaxy.esb.platform.runtime.core.infrastructure.schema.api.entity.Resource;
|
||||
|
||||
@Component(service = URLStreamHandlerService.class, property = "url.handler.protocol=resource-registry", immediate = true)
|
||||
public class ResourceRegistryURLResolver extends AbstractURLStreamHandlerService {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(ResourceRegistryURLResolver.class);
|
||||
|
||||
@Reference (collectionType = CollectionType.SERVICE, cardinality = ReferenceCardinality.MANDATORY)
|
||||
ResourceService resourceService;
|
||||
|
||||
protected static class SchemaRegistryURLConnection extends URLConnection {
|
||||
|
||||
ResourceService resourceService;
|
||||
|
||||
protected String resourceName = null;
|
||||
protected String resourceVersion = null;
|
||||
|
||||
protected SchemaRegistryURLConnection(URL url, ResourceService resourceService) {
|
||||
super(url);
|
||||
this.resourceService = resourceService;
|
||||
log.info("NEW CONNECTION TO: " + url.toString());
|
||||
String remaining = url.toString().substring(url.toString().indexOf(":")+1);
|
||||
String[] splitted = remaining.split(File.separator);
|
||||
if (splitted.length>1) {
|
||||
resourceVersion = splitted[splitted.length - 1];
|
||||
resourceName = remaining.substring(0, remaining.length() - resourceVersion.length());
|
||||
} else {
|
||||
resourceName = remaining;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connect() throws IOException {
|
||||
log.info("CONNECTING: " + url.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getInputStream() throws IOException {
|
||||
Resource resource = resourceService.getResourceByFullName(resourceName).orElse(null);
|
||||
log.info("RESOURCE [{}] {} FOUND "
|
||||
, resourceName
|
||||
, resource==null?"NOT":"");
|
||||
if (resource == null)
|
||||
return super.getInputStream();
|
||||
return new ByteArrayInputStream(resource.getResourceValue());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public URLConnection openConnection(URL u) throws IOException {
|
||||
return new SchemaRegistryURLConnection(u, resourceService);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* schema-impl
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 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.platform.runtime.core.infrastructure.schema.resolver.resource;
|
||||
|
||||
|
||||
public class SchemaRegistryHelper {
|
||||
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* schema-soap
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 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.platform.runtime.core.infrastructure.schema.soap.cxf;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
|
||||
|
||||
/**
|
||||
* <p>Java class for anonymous complex type.
|
||||
*
|
||||
* <p>The following schema fragment specifies the expected content contained within this class.
|
||||
*
|
||||
* <pre>
|
||||
* <complexType>
|
||||
* <complexContent>
|
||||
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
|
||||
* <sequence>
|
||||
* <element name="fullName" type="{http://www.w3.org/2001/XMLSchema}string"/>
|
||||
* </sequence>
|
||||
* </restriction>
|
||||
* </complexContent>
|
||||
* </complexType>
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
*/
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "", propOrder = {
|
||||
"fullName"
|
||||
})
|
||||
@XmlRootElement(name = "getResourceInfoListByFullNameRequest")
|
||||
public class GetResourceInfoListByFullNameRequest {
|
||||
|
||||
@XmlElement(required = true)
|
||||
protected String fullName;
|
||||
|
||||
/**
|
||||
* Gets the value of the fullName property.
|
||||
*
|
||||
* @return
|
||||
* possible object is
|
||||
* {@link String }
|
||||
*
|
||||
*/
|
||||
public String getFullName() {
|
||||
return fullName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the fullName property.
|
||||
*
|
||||
* @param value
|
||||
* allowed object is
|
||||
* {@link String }
|
||||
*
|
||||
*/
|
||||
public void setFullName(String value) {
|
||||
this.fullName = value;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* schema-soap
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 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.platform.runtime.core.infrastructure.schema.soap.cxf;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
|
||||
|
||||
/**
|
||||
* <p>Java class for anonymous complex type.
|
||||
*
|
||||
* <p>The following schema fragment specifies the expected content contained within this class.
|
||||
*
|
||||
* <pre>
|
||||
* <complexType>
|
||||
* <complexContent>
|
||||
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
|
||||
* <sequence>
|
||||
* <element name="path" type="{http://www.w3.org/2001/XMLSchema}string"/>
|
||||
* </sequence>
|
||||
* </restriction>
|
||||
* </complexContent>
|
||||
* </complexType>
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
*/
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "", propOrder = {
|
||||
"path"
|
||||
})
|
||||
@XmlRootElement(name = "getResourceInfoListByFullPathRequest")
|
||||
public class GetResourceInfoListByFullPathRequest {
|
||||
|
||||
@XmlElement(required = true)
|
||||
protected String path;
|
||||
|
||||
/**
|
||||
* Gets the value of the path property.
|
||||
*
|
||||
* @return
|
||||
* possible object is
|
||||
* {@link String }
|
||||
*
|
||||
*/
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the path property.
|
||||
*
|
||||
* @param value
|
||||
* allowed object is
|
||||
* {@link String }
|
||||
*
|
||||
*/
|
||||
public void setPath(String value) {
|
||||
this.path = value;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* schema-soap
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 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.platform.runtime.core.infrastructure.schema.soap.cxf;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
|
||||
|
||||
/**
|
||||
* <p>Java class for anonymous complex type.
|
||||
*
|
||||
* <p>The following schema fragment specifies the expected content contained within this class.
|
||||
*
|
||||
* <pre>
|
||||
* <complexType>
|
||||
* <complexContent>
|
||||
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
|
||||
* <sequence>
|
||||
* <element name="path" type="{http://www.w3.org/2001/XMLSchema}string"/>
|
||||
* </sequence>
|
||||
* </restriction>
|
||||
* </complexContent>
|
||||
* </complexType>
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
*/
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "", propOrder = {
|
||||
"path"
|
||||
})
|
||||
@XmlRootElement(name = "getResourceInfoListByPathRequest")
|
||||
public class GetResourceInfoListByPathRequest {
|
||||
|
||||
@XmlElement(required = true)
|
||||
protected String path;
|
||||
|
||||
/**
|
||||
* Gets the value of the path property.
|
||||
*
|
||||
* @return
|
||||
* possible object is
|
||||
* {@link String }
|
||||
*
|
||||
*/
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the path property.
|
||||
*
|
||||
* @param value
|
||||
* allowed object is
|
||||
* {@link String }
|
||||
*
|
||||
*/
|
||||
public void setPath(String value) {
|
||||
this.path = value;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user