overwrite application in Apicurio

This commit is contained in:
Radek Davidek 2025-11-04 14:07:05 +01:00
parent a36ee218c2
commit 8b14aa04b3
4 changed files with 43 additions and 19 deletions

View File

@ -22,18 +22,22 @@ public class ApiSync {
StartParameters sp = StartParameters.parse(commandLine);
log.info("Parsed parameters: " + sp);
if (sp.getCommand().equalsIgnoreCase("wso2ToApicurio")) {
log.info("Import command selected.");
if (sp.getCommand().equalsIgnoreCase("wso2ApisToApicurio")) {
log.info("wso2ApisToApicurio command selected.");
Wso2v32ToApicurio imp = new Wso2v32ToApicurio();
imp.process();
} else if (sp.getCommand().equalsIgnoreCase("apicurioToWso2")) {
log.info("Export command selected.");
} else if (sp.getCommand().equalsIgnoreCase("apicurioApisToWso2")) {
log.info("apicurioApisToWso2 command selected.");
ExportToWso2FromV32 exp = new ExportToWso2FromV32();
exp.process();
} else if (sp.getCommand().equalsIgnoreCase("wso2AppsToApicurio")) {
log.info("Export command selected.");
log.info("wso2AppsToApicurio command selected.");
Wso2AppsToApicurio apps = new Wso2AppsToApicurio();
apps.process();
} else if (sp.getCommand().equalsIgnoreCase("apicurioAppsToWso2")) {
log.info("apicurioAppsToWso2 command selected.");
ExportToWso2FromV32 exp = new ExportToWso2FromV32();
exp.process();
} else {
log.error("Unknown command: " + sp.getCommand());
printHelp();

View File

@ -105,20 +105,19 @@ public class Wso2AppsToApicurio extends AbstractProcess {
existingArtifacts = null;
}
if (existingArtifacts == null) {
log.info("Creating new Application to Apicurio '{}' ({}).", appDetail.getName(),
appDetail.getOwner());
// Create new artifact
ArtifactMetaData meta = client.createArtifact(group, mainArtifactId,
ARTIFACT_APPLICATION_DEFAULT_VERSION, null, null,
null,
appDetail.getName(), appDetail.getName(), null, null, null,
new ByteArrayInputStream(entry.getContent()), null);
// Create the three required rules
createRule(meta, "NONE", RuleType.COMPATIBILITY);
createRule(meta, "NONE", RuleType.VALIDITY);
createRule(meta, "NONE", RuleType.INTEGRITY);
if (existingArtifacts == null || existingArtifacts.getCount() == 0) {
createApplicationInApicurio(appDetail, group, mainArtifactId, entry.getContent());
} else if (existingArtifacts != null && existingArtifacts.getCount() > 0
&& config.getApicurio().isOverwriteExistingApplication()) {
try {
log.info("Deleting existing Application in Apicurio '{}' ({}).", appDetail.getName(),
appDetail.getOwner());
client.deleteArtifact(group, mainArtifactId);
createApplicationInApicurio(appDetail, group, mainArtifactId, entry.getContent());
} catch (Exception e) {
log.error("Error deleting existing Application '{}' ({}): {}", appDetail.getName(),
appDetail.getOwner(), e.getMessage());
}
}
}
@ -129,6 +128,24 @@ public class Wso2AppsToApicurio extends AbstractProcess {
}
}
private void createApplicationInApicurio(ApplicationDetail appDetail, String group, String mainArtifactId,
byte[] content)
throws Exception {
log.info("Creating new Application to Apicurio '{}' ({}).", appDetail.getName(),
appDetail.getOwner());
// Create new artifact
ArtifactMetaData meta = client.createArtifact(group, mainArtifactId,
ARTIFACT_APPLICATION_DEFAULT_VERSION, null, null,
null,
appDetail.getName(), appDetail.getName(), null, null, null,
new ByteArrayInputStream(content), null);
// Create the three required rules
createRule(meta, "NONE", RuleType.COMPATIBILITY);
createRule(meta, "NONE", RuleType.VALIDITY);
createRule(meta, "NONE", RuleType.INTEGRITY);
}
private ApplicationList getApplicationList(String adminApiUrl, TokenResponse tokenResponse) throws Exception {
ApplicationList listOfApps = null;

View File

@ -59,6 +59,8 @@ public class ApplicationConfig {
private String apiUrl;
@JsonProperty("default_api_group")
private String defaultApiGroup;
@JsonProperty("overwrite_existing_application")
private boolean overwriteExistingApplication = false;
}
@Data

View File

@ -24,5 +24,6 @@ patterns:
apicurio:
api_url: http://apicurio:8095/apis/registry/v2
default_api_group: api
overwrite_existing_application: true
max_threads: 1