Search in sources :

Example 11 with Extension

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());
}
Also used : Extension(io.syndesis.common.model.extension.Extension) ProcessingReport(com.github.fge.jsonschema.core.report.ProcessingReport) JsonSchema(com.github.fge.jsonschema.main.JsonSchema) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.Test)

Example 12 with Extension

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);
        }
    }
}
Also used : Extension(io.syndesis.common.model.extension.Extension) Connector(io.syndesis.common.model.connection.Connector) Connection(io.syndesis.common.model.connection.Connection) Step(io.syndesis.common.model.integration.Step)

Example 13 with 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);
    }
}
Also used : Extension(io.syndesis.common.model.extension.Extension) Date(java.util.Date)

Example 14 with 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);
    }
}
Also used : Extension(io.syndesis.common.model.extension.Extension) SyndesisRestException(io.syndesis.server.endpoint.v1.SyndesisRestException) Date(java.util.Date) SyndesisServerException(io.syndesis.common.util.SyndesisServerException) SyndesisRestException(io.syndesis.server.endpoint.v1.SyndesisRestException) IOException(java.io.IOException) ConstraintViolationException(javax.validation.ConstraintViolationException) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

Example 15 with Extension

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);
}
Also used : Extension(io.syndesis.common.model.extension.Extension)

Aggregations

Extension (io.syndesis.common.model.extension.Extension)19 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 Test (org.junit.Test)5 Connection (io.syndesis.common.model.connection.Connection)4 Step (io.syndesis.common.model.integration.Step)4 ProcessingReport (com.github.fge.jsonschema.core.report.ProcessingReport)3 JsonSchema (com.github.fge.jsonschema.main.JsonSchema)3 Connector (io.syndesis.common.model.connection.Connector)3 Integration (io.syndesis.common.model.integration.Integration)3 Date (java.util.Date)3 Action (io.syndesis.common.model.action.Action)2 ConnectorAction (io.syndesis.common.model.action.ConnectorAction)2 StepAction (io.syndesis.common.model.action.StepAction)2 DataManager (io.syndesis.server.dao.manager.DataManager)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 POST (javax.ws.rs.POST)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ApiResponses (io.swagger.annotations.ApiResponses)1