use of io.syndesis.common.model.extension.Extension in project syndesis by syndesisio.
the class ExtensionSchemaValidationTest method upgradePublicModelExtensionTest.
@Test
public void upgradePublicModelExtensionTest() throws ProcessingException, IOException {
String syndesisExtensionSchema = "/syndesis/syndesis-extension-definition-schema.json";
JsonSchema schema = JsonSchemaFactory.byDefault().getJsonSchema("resource:" + syndesisExtensionSchema);
ExtensionConverter converter = new DefaultExtensionConverter();
Extension extension = new Extension.Builder().extensionId("my-extension").name("Name").description("Description").version("1.0.0").schemaVersion("old-V0.1").extensionType(Extension.Type.Steps).build();
JsonNode tree = converter.toPublicExtension(extension);
ProcessingReport report = schema.validate(tree);
assertFalse(report.toString(), report.iterator().hasNext());
Extension extensionClone = converter.toInternalExtension(tree);
assertNotEquals(extensionClone, extension);
assertEquals(ExtensionConverter.getCurrentSchemaVersion(), extensionClone.getSchemaVersion());
}
use of io.syndesis.common.model.extension.Extension in project syndesis by syndesisio.
the class IntegrationSupportHandler method addToExport.
private void addToExport(JsonDB export, Integration integration) {
addModelToExport(export, integration);
for (Step step : integration.getSteps()) {
Optional<Connection> c = step.getConnection();
if (c.isPresent()) {
Connection connection = c.get();
addModelToExport(export, connection);
Connector connector = integrationHandler.getDataManager().fetch(Connector.class, connection.getConnectorId());
if (connector != null) {
addModelToExport(export, connector);
}
}
Optional<Extension> e = step.getExtension();
if (e.isPresent()) {
Extension extension = e.get();
addModelToExport(export, extension);
}
}
}
use of io.syndesis.common.model.extension.Extension in project syndesis by syndesisio.
the class ExtensionActivator method activateExtension.
public void activateExtension(Extension extension) {
Date rightNow = new Date();
// Uninstall other active extensions
doDeleteInstalled(extension.getExtensionId());
updateConnectors(extension);
dataManager.update(new Extension.Builder().createFrom(extension).status(Extension.Status.Installed).lastUpdated(rightNow).build());
if (extension.getTags().contains("jdbc-driver")) {
verifier.uploadToVerifier(extension);
}
}
use of io.syndesis.common.model.extension.Extension in project syndesis by syndesisio.
the class ExtensionHandler method upload.
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
@SuppressWarnings("PMD.CyclomaticComplexity")
public Extension upload(MultipartFormDataInput dataInput, @Context SecurityContext sec, @QueryParam("updatedId") String updatedId) {
Date rightNow = new Date();
String id = KeyGenerator.createKey();
String fileLocation = "/extensions/" + id;
try {
storeFile(fileLocation, dataInput);
Extension embeddedExtension = extractExtension(fileLocation);
if (updatedId != null) {
// Update
Extension replacedExtension = getDataManager().fetch(Extension.class, updatedId);
if (!replacedExtension.getExtensionId().equals(embeddedExtension.getExtensionId())) {
String message = "The uploaded extensionId (" + embeddedExtension.getExtensionId() + ") does not match the existing extensionId (" + replacedExtension.getExtensionId() + ")";
throw new SyndesisRestException(message, message, null, Response.Status.BAD_REQUEST.getStatusCode());
}
} else {
// New import
Set<String> ids = getDataManager().fetchIdsByPropertyValue(Extension.class, "extensionId", embeddedExtension.getExtensionId(), "status", Extension.Status.Installed.name());
if (!ids.isEmpty()) {
String message = "An extension with the same extensionId (" + embeddedExtension.getExtensionId() + ") is already installed. Please update the existing extension instead of importing a new one.";
throw new SyndesisRestException(message, message, null, Response.Status.BAD_REQUEST.getStatusCode());
}
}
String icon = embeddedExtension.getIcon();
if (icon == null) {
icon = IconGenerator.generate("extension", embeddedExtension.getName());
}
Extension extension = new Extension.Builder().createFrom(embeddedExtension).id(id).status(Extension.Status.Draft).uses(OptionalInt.empty()).lastUpdated(rightNow).createdDate(rightNow).userId(sec.getUserPrincipal().getName()).icon(icon).build();
return getDataManager().create(extension);
} catch (SyndesisRestException ex) {
try {
delete(id);
} catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") Exception ignored) {
// ignore
}
throw ex;
} catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") Exception ex) {
try {
delete(id);
} catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") Exception ignored) {
// ignore
}
String message = "An error has occurred while trying to process the technical extension. Please, check the input file.";
throw new SyndesisRestException(message + " " + ex.getMessage(), message, null, Response.Status.BAD_REQUEST.getStatusCode(), ex);
}
}
use of io.syndesis.common.model.extension.Extension in project syndesis by syndesisio.
the class ExtensionHandler method delete.
@Override
public void delete(String id) {
// Not a real delete of the extension: changing the status to Deleted
Extension extension = getDataManager().fetch(Extension.class, id);
// Delete from verifier
extensionActivator.deleteExtension(extension);
}
Aggregations