added documentation
This commit is contained in:
parent
d09c7623bb
commit
eb1ecef78d
@ -41,6 +41,8 @@ public abstract class AbstractProcess {
|
|||||||
public static final String ARTIFACT_GROUP_SUBSCRIPTIONS = "SUBSCRIPTIONS";
|
public static final String ARTIFACT_GROUP_SUBSCRIPTIONS = "SUBSCRIPTIONS";
|
||||||
public static final String ARTIFACT_NAME_SUBSCRIPTIONS = "subs.yaml";
|
public static final String ARTIFACT_NAME_SUBSCRIPTIONS = "subs.yaml";
|
||||||
|
|
||||||
|
public static final String DEFAULT_DOC_FILE_NAME = "document.yaml";
|
||||||
|
|
||||||
public static ObjectMapper mapper;
|
public static ObjectMapper mapper;
|
||||||
public static ObjectMapper mapperYaml;
|
public static ObjectMapper mapperYaml;
|
||||||
|
|
||||||
|
|||||||
@ -25,7 +25,7 @@ public class ApiSync {
|
|||||||
log.info("Import command selected.");
|
log.info("Import command selected.");
|
||||||
ImportToApicurio imp = new ImportToApicurio();
|
ImportToApicurio imp = new ImportToApicurio();
|
||||||
imp.process();
|
imp.process();
|
||||||
} else if (sp.getCommand().equals("apicurioToWso2")) {
|
} else if (sp.getCommand().equalsIgnoreCase("apicurioToWso2")) {
|
||||||
log.info("Export command selected.");
|
log.info("Export command selected.");
|
||||||
ExportToWso2FromV32 exp = new ExportToWso2FromV32();
|
ExportToWso2FromV32 exp = new ExportToWso2FromV32();
|
||||||
exp.process();
|
exp.process();
|
||||||
|
|||||||
@ -56,6 +56,9 @@ public class ZipUtils {
|
|||||||
return FileType.POLICY_FAULT;
|
return FileType.POLICY_FAULT;
|
||||||
} else if (lowerFileName.endsWith("/meta-information/endpoint_certificates.yaml")) {
|
} else if (lowerFileName.endsWith("/meta-information/endpoint_certificates.yaml")) {
|
||||||
return FileType.CERTIFICATE;
|
return FileType.CERTIFICATE;
|
||||||
|
} else if (lowerFileName.contains("/docs/")) {
|
||||||
|
return FileType.DOCUMENTATION;
|
||||||
|
|
||||||
}
|
}
|
||||||
return FileType.UNKNOWN;
|
return FileType.UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,8 +26,10 @@ import cz.trask.migration.model.FileType;
|
|||||||
import cz.trask.migration.model.HttpResponse;
|
import cz.trask.migration.model.HttpResponse;
|
||||||
import cz.trask.migration.model.TokenResponse;
|
import cz.trask.migration.model.TokenResponse;
|
||||||
import cz.trask.migration.model.v32.ApiDefinition32;
|
import cz.trask.migration.model.v32.ApiDefinition32;
|
||||||
|
import cz.trask.migration.model.v32.Documents32;
|
||||||
import cz.trask.migration.model.v32.HostInfo32;
|
import cz.trask.migration.model.v32.HostInfo32;
|
||||||
import cz.trask.migration.model.v45.ApiDefinition45;
|
import cz.trask.migration.model.v45.ApiDefinition45;
|
||||||
|
import cz.trask.migration.model.v45.Documents45;
|
||||||
import cz.trask.migration.model.v45.EndpointCertificates45;
|
import cz.trask.migration.model.v45.EndpointCertificates45;
|
||||||
import cz.trask.migration.model.v45.OperationPolicySpecification45;
|
import cz.trask.migration.model.v45.OperationPolicySpecification45;
|
||||||
import io.apicurio.registry.rest.client.RegistryClient;
|
import io.apicurio.registry.rest.client.RegistryClient;
|
||||||
@ -62,8 +64,8 @@ public class ExportToWso2FromV32 extends AbstractProcess {
|
|||||||
|
|
||||||
TokenResponse token = authenticateToWso2AndGetToken();
|
TokenResponse token = authenticateToWso2AndGetToken();
|
||||||
|
|
||||||
ArtifactSearchResults apis = client.searchArtifacts(config.getApicurio().getDefaultApiGroup(), null, null, null, null,
|
ArtifactSearchResults apis = client.searchArtifacts(config.getApicurio().getDefaultApiGroup(), null, null,
|
||||||
null, null, null, null);
|
null, null, null, null, null, null);
|
||||||
|
|
||||||
log.info("Found {} APIs", apis.getCount());
|
log.info("Found {} APIs", apis.getCount());
|
||||||
|
|
||||||
@ -92,13 +94,13 @@ public class ExportToWso2FromV32 extends AbstractProcess {
|
|||||||
try {
|
try {
|
||||||
log.info("Processing API {} of {}", index, total);
|
log.info("Processing API {} of {}", index, total);
|
||||||
|
|
||||||
VersionSearchResults versions = client.listArtifactVersions(config.getApicurio().getDefaultApiGroup(), api.getId(), null,
|
VersionSearchResults versions = client.listArtifactVersions(config.getApicurio().getDefaultApiGroup(),
|
||||||
null);
|
api.getId(), null, null);
|
||||||
|
|
||||||
for (SearchedVersion ver : versions.getVersions()) {
|
for (SearchedVersion ver : versions.getVersions()) {
|
||||||
log.info(" - Found version: {}", ver.getVersion());
|
log.info(" - Found version: {}", ver.getVersion());
|
||||||
List<ArtifactReference> ref = client.getArtifactReferencesByCoordinates(config.getApicurio().getDefaultApiGroup(),
|
List<ArtifactReference> ref = client.getArtifactReferencesByCoordinates(
|
||||||
api.getId(), ver.getVersion());
|
config.getApicurio().getDefaultApiGroup(), api.getId(), ver.getVersion());
|
||||||
if (ref != null && !ref.isEmpty()) {
|
if (ref != null && !ref.isEmpty()) {
|
||||||
log.info("Artifact has {} references", ref.size());
|
log.info("Artifact has {} references", ref.size());
|
||||||
byte[] data = prepareApiZipFile32to45(client, ver, ref);
|
byte[] data = prepareApiZipFile32to45(client, ver, ref);
|
||||||
@ -203,12 +205,21 @@ public class ExportToWso2FromV32 extends AbstractProcess {
|
|||||||
} else if (FileType.APIDEF.toString().equals(amd.getGroupId())) {
|
} else if (FileType.APIDEF.toString().equals(amd.getGroupId())) {
|
||||||
apiDef = mapperYaml.readValue(content, ApiDefinition32.class);
|
apiDef = mapperYaml.readValue(content, ApiDefinition32.class);
|
||||||
appendFile = false;
|
appendFile = false;
|
||||||
|
} else if (FileType.DOCUMENTATION.toString().equals(amd.getGroupId())) {
|
||||||
|
subDir = "Docs/";
|
||||||
|
if (content != null && content.length > 0) {
|
||||||
|
List<Documents32> docs = mapperYaml.readValue(content, new TypeReference<List<Documents32>>() {
|
||||||
|
});
|
||||||
|
for (Documents32 doc : docs) {
|
||||||
|
convertAndAddDocument(zos, baseDir + subDir, doc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
appendFile = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (appendFile) {
|
||||||
String fileName = baseDir + subDir + (specialName != null ? specialName : r.getName());
|
String fileName = baseDir + subDir + (specialName != null ? specialName : r.getName());
|
||||||
log.info(" - Adding file: {}", fileName);
|
log.info(" - Adding file: {}", fileName);
|
||||||
|
|
||||||
if (appendFile) {
|
|
||||||
zos.putNextEntry(new ZipEntry(fileName));
|
zos.putNextEntry(new ZipEntry(fileName));
|
||||||
zos.write(content);
|
zos.write(content);
|
||||||
zos.closeEntry();
|
zos.closeEntry();
|
||||||
@ -227,6 +238,32 @@ public class ExportToWso2FromV32 extends AbstractProcess {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void convertAndAddDocument(ZipOutputStream zos, String subDir, Documents32 doc) throws Exception {
|
||||||
|
Documents45 doc45 = new Documents45();
|
||||||
|
|
||||||
|
Documents45.Data doc45Data = new Documents45.Data();
|
||||||
|
doc45Data.setName(doc.getName());
|
||||||
|
doc45Data.setType(doc.getType());
|
||||||
|
doc45Data.setSummary(doc.getSummary());
|
||||||
|
doc45Data.setSourceType(doc.getSourceType());
|
||||||
|
doc45Data.setSourceUrl(doc.getSourceUrl());
|
||||||
|
doc45Data.setFileName(doc.getFileName());
|
||||||
|
doc45Data.setInlineContent(doc.getInlineContent());
|
||||||
|
doc45Data.setOtherTypeName(doc.getOtherTypeName());
|
||||||
|
doc45Data.setVisibility(doc.getVisibility());
|
||||||
|
doc45Data.setCreatedTime(doc.getCreatedTime());
|
||||||
|
doc45Data.setCreatedBy(doc.getCreatedBy());
|
||||||
|
doc45Data.setLastUpdatedTime(doc.getLastUpdatedTime());
|
||||||
|
doc45Data.setLastUpdatedBy(doc.getLastUpdatedBy());
|
||||||
|
|
||||||
|
doc45.setData(doc45Data);
|
||||||
|
|
||||||
|
String fileName = subDir + doc.getName() + "/" + DEFAULT_DOC_FILE_NAME;
|
||||||
|
zos.putNextEntry(new ZipEntry(fileName));
|
||||||
|
zos.write(mapperYaml.writeValueAsBytes(doc45));
|
||||||
|
zos.closeEntry();
|
||||||
|
}
|
||||||
|
|
||||||
private byte[] convertCertificateToEPCertificate(ZipOutputStream zos, String subDir, byte[] content) {
|
private byte[] convertCertificateToEPCertificate(ZipOutputStream zos, String subDir, byte[] content) {
|
||||||
if (content != null && content.length > 0) {
|
if (content != null && content.length > 0) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -42,7 +42,8 @@ public class ApiDefinitionMapper32to45 {
|
|||||||
: "");
|
: "");
|
||||||
data.setVersion(oldApi.getId() != null ? oldApi.getId().getVersion() : null);
|
data.setVersion(oldApi.getId() != null ? oldApi.getId().getVersion() : null);
|
||||||
data.setProvider(oldApi.getId() != null ? oldApi.getId().getProviderName() : null);
|
data.setProvider(oldApi.getId() != null ? oldApi.getId().getProviderName() : null);
|
||||||
data.setContext(swaggerData.get("basePath") != null ? swaggerData.get("basePath").toString() : "");
|
//data.setContext(swaggerData.get("basePath") != null ? swaggerData.get("basePath").toString() : "");
|
||||||
|
data.setContext(oldApi.getContext());
|
||||||
data.setLifeCycleStatus(oldApi.getStatus());
|
data.setLifeCycleStatus(oldApi.getStatus());
|
||||||
data.setDefaultVersion(oldApi.isDefaultVersion());
|
data.setDefaultVersion(oldApi.isDefaultVersion());
|
||||||
data.setRevision(false);
|
data.setRevision(false);
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
package cz.trask.migration.model;
|
package cz.trask.migration.model;
|
||||||
|
|
||||||
public enum FileType {
|
public enum FileType {
|
||||||
APIDEF, OPENAPI, WSDL, POLICY_IN, POLICY_OUT, POLICY_FAULT, CERTIFICATE, SUBSCRIPTIONS, UNKNOWN
|
APIDEF, OPENAPI, WSDL, POLICY_IN, POLICY_OUT, POLICY_FAULT, CERTIFICATE, SUBSCRIPTIONS, DOCUMENTATION, UNKNOWN
|
||||||
}
|
}
|
||||||
|
|||||||
112
src/main/java/cz/trask/migration/model/v32/Documents32.java
Normal file
112
src/main/java/cz/trask/migration/model/v32/Documents32.java
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
package cz.trask.migration.model.v32;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
|
public class Documents32 {
|
||||||
|
|
||||||
|
private String id = null;
|
||||||
|
private String name = null;
|
||||||
|
private TypeEnum type = null;
|
||||||
|
private String summary = null;
|
||||||
|
private SourceTypeEnum sourceType = null;
|
||||||
|
private String sourceUrl = null;
|
||||||
|
private String fileName = null;
|
||||||
|
private String inlineContent = null;
|
||||||
|
private String otherTypeName = null;
|
||||||
|
private VisibilityEnum visibility = null;
|
||||||
|
private String createdTime = null;
|
||||||
|
private String createdBy = null;
|
||||||
|
private String lastUpdatedTime = null;
|
||||||
|
private String lastUpdatedBy = null;
|
||||||
|
|
||||||
|
public enum TypeEnum {
|
||||||
|
HOWTO,
|
||||||
|
SAMPLES,
|
||||||
|
PUBLIC_FORUM,
|
||||||
|
SUPPORT_FORUM,
|
||||||
|
API_MESSAGE_FORMAT,
|
||||||
|
SWAGGER_DOC,
|
||||||
|
OTHER
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum SourceTypeEnum {
|
||||||
|
INLINE,
|
||||||
|
MARKDOWN,
|
||||||
|
URL,
|
||||||
|
FILE
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public enum VisibilityEnum {
|
||||||
|
OWNER_ONLY,
|
||||||
|
PRIVATE,
|
||||||
|
API_LEVEL
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(java.lang.Object o) {
|
||||||
|
if (this == o) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || getClass() != o.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Documents32 document = (Documents32) o;
|
||||||
|
return Objects.equals(id, document.id) && Objects.equals(name, document.name)
|
||||||
|
&& Objects.equals(type, document.type) && Objects.equals(summary, document.summary)
|
||||||
|
&& Objects.equals(sourceType, document.sourceType) && Objects.equals(sourceUrl, document.sourceUrl)
|
||||||
|
&& Objects.equals(fileName, document.fileName) && Objects.equals(inlineContent, document.inlineContent)
|
||||||
|
&& Objects.equals(otherTypeName, document.otherTypeName)
|
||||||
|
&& Objects.equals(visibility, document.visibility) && Objects.equals(createdTime, document.createdTime)
|
||||||
|
&& Objects.equals(createdBy, document.createdBy)
|
||||||
|
&& Objects.equals(lastUpdatedTime, document.lastUpdatedTime)
|
||||||
|
&& Objects.equals(lastUpdatedBy, document.lastUpdatedBy);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(id, name, type, summary, sourceType, sourceUrl, fileName, inlineContent, otherTypeName,
|
||||||
|
visibility, createdTime, createdBy, lastUpdatedTime, lastUpdatedBy);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append("class DocumentDTO {\n");
|
||||||
|
|
||||||
|
sb.append(" documentId: ").append(toIndentedString(id)).append("\n");
|
||||||
|
sb.append(" name: ").append(toIndentedString(name)).append("\n");
|
||||||
|
sb.append(" type: ").append(toIndentedString(type)).append("\n");
|
||||||
|
sb.append(" summary: ").append(toIndentedString(summary)).append("\n");
|
||||||
|
sb.append(" sourceType: ").append(toIndentedString(sourceType)).append("\n");
|
||||||
|
sb.append(" sourceUrl: ").append(toIndentedString(sourceUrl)).append("\n");
|
||||||
|
sb.append(" fileName: ").append(toIndentedString(fileName)).append("\n");
|
||||||
|
sb.append(" inlineContent: ").append(toIndentedString(inlineContent)).append("\n");
|
||||||
|
sb.append(" otherTypeName: ").append(toIndentedString(otherTypeName)).append("\n");
|
||||||
|
sb.append(" visibility: ").append(toIndentedString(visibility)).append("\n");
|
||||||
|
sb.append(" createdTime: ").append(toIndentedString(createdTime)).append("\n");
|
||||||
|
sb.append(" createdBy: ").append(toIndentedString(createdBy)).append("\n");
|
||||||
|
sb.append(" lastUpdatedTime: ").append(toIndentedString(lastUpdatedTime)).append("\n");
|
||||||
|
sb.append(" lastUpdatedBy: ").append(toIndentedString(lastUpdatedBy)).append("\n");
|
||||||
|
sb.append("}");
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert the given object to string with each line indented by 4 spaces
|
||||||
|
* (except the first line).
|
||||||
|
*/
|
||||||
|
private String toIndentedString(java.lang.Object o) {
|
||||||
|
if (o == null) {
|
||||||
|
return "null";
|
||||||
|
}
|
||||||
|
return o.toString().replace("\n", "\n ");
|
||||||
|
}
|
||||||
|
}
|
||||||
40
src/main/java/cz/trask/migration/model/v45/Documents45.java
Normal file
40
src/main/java/cz/trask/migration/model/v45/Documents45.java
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
package cz.trask.migration.model.v45;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
|
||||||
|
import cz.trask.migration.model.v32.Documents32.SourceTypeEnum;
|
||||||
|
import cz.trask.migration.model.v32.Documents32.TypeEnum;
|
||||||
|
import cz.trask.migration.model.v32.Documents32.VisibilityEnum;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
|
public class Documents45 {
|
||||||
|
|
||||||
|
private String type = "document";
|
||||||
|
private String version = "v4.5.0";
|
||||||
|
|
||||||
|
private Data data = null;
|
||||||
|
|
||||||
|
@lombok.Data
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
|
public static class Data {
|
||||||
|
private String id = null;
|
||||||
|
private String name = null;
|
||||||
|
private TypeEnum type = null;
|
||||||
|
private String summary = null;
|
||||||
|
private SourceTypeEnum sourceType = null;
|
||||||
|
private String sourceUrl = null;
|
||||||
|
private String fileName = null;
|
||||||
|
private String inlineContent = null;
|
||||||
|
private String otherTypeName = null;
|
||||||
|
private VisibilityEnum visibility = null;
|
||||||
|
private String createdTime = null;
|
||||||
|
private String createdBy = null;
|
||||||
|
private String lastUpdatedTime = null;
|
||||||
|
private String lastUpdatedBy = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user