use of io.syndesis.common.model.ChangeEvent in project syndesis by syndesisio.
the class ResourceUpdateController method run.
private void run() {
for (int h = 0; h < handlers.size(); h++) {
ResourceUpdateHandler handler = handlers.get(h);
for (int i = 0; i < allEvents.size(); i++) {
ChangeEvent event = allEvents.get(i);
if (handler.canHandle(event)) {
LOGGER.debug("Trigger handler {}", handler);
handler.process(event);
// to trigger the handler multiple time.
break;
}
}
}
}
use of io.syndesis.common.model.ChangeEvent in project syndesis by syndesisio.
the class IntegrationSupportHandler method importIntegration.
@POST
@Path("/import")
@Produces(MediaType.APPLICATION_JSON)
public List<ChangeEvent> importIntegration(@Context SecurityContext sec, InputStream is) {
try (ZipInputStream zis = new ZipInputStream(is)) {
HashSet<String> extensionIds = new HashSet<>();
ArrayList<ChangeEvent> changeEvents = new ArrayList<>();
ModelExport modelExport = null;
while (true) {
ZipEntry entry = zis.getNextEntry();
if (entry == null) {
break;
}
if (EXPORT_MODEL_INFO_FILE_NAME.equals(entry.getName())) {
modelExport = Json.reader().forType(ModelExport.class).readValue(zis);
}
if (EXPORT_MODEL_FILE_NAME.equals(entry.getName())) {
CloseableJsonDB memJsonDB = MemorySqlJsonDB.create(jsonDB.getIndexes());
memJsonDB.set("/", nonClosing(zis));
changeEvents.addAll(importModels(sec, modelExport, memJsonDB));
memJsonDB.close();
for (ChangeEvent changeEvent : changeEvents) {
if (changeEvent.getKind().get().equals("extension")) {
extensionIds.add(changeEvent.getId().get());
}
}
}
// import missing extensions that were in the model.
if (entry.getName().startsWith("extensions/")) {
for (String extensionId : extensionIds) {
if (entry.getName().equals("extensions/" + Names.sanitize(extensionId) + ".jar")) {
String path = "/extensions/" + extensionId;
InputStream existing = extensionDataManager.getExtensionDataAccess().read(path);
if (existing == null) {
extensionDataManager.getExtensionDataAccess().write(path, zis);
} else {
existing.close();
}
}
}
}
zis.closeEntry();
}
if (changeEvents.isEmpty()) {
LOG.info("Could not import integration: No integration data model found.");
throw new ClientErrorException("Does not look like an integration export.", Response.Status.BAD_REQUEST);
}
return changeEvents;
} catch (IOException e) {
if (LOG.isInfoEnabled()) {
LOG.info("Could not import integration: " + e, e);
}
throw new ClientErrorException("Could not import integration: " + e, Response.Status.BAD_REQUEST, e);
}
}
use of io.syndesis.common.model.ChangeEvent in project syndesis by syndesisio.
the class ConnectionUpdateHandler method compute.
@Override
protected List<ConnectionBulletinBoard> compute(ChangeEvent event) {
final List<ConnectionBulletinBoard> boards = new ArrayList<>();
final DataManager dataManager = getDataManager();
final List<Connector> connectors = dataManager.fetchAll(Connector.class).getItems();
for (int i = 0; i < connectors.size(); i++) {
final Connector connector = connectors.get(i);
final String id = connector.getId().get();
dataManager.fetchAllByPropertyValue(Connection.class, "connectorId", id).filter(connection -> connection.getConnector().isPresent()).map(connection -> computeBoard(connection, connection.getConnector().get(), connector)).forEach(boards::add);
}
return boards;
}
Aggregations