Search in sources :

Example 6 with Kind

use of io.syndesis.common.model.Kind in project syndesis by syndesisio.

the class DataManager method fetchIds.

@SuppressWarnings("unchecked")
public <T extends WithId<T>> Set<String> fetchIds(Class<T> model) {
    if (getDataAccessObject(model) != null) {
        return doWithDataAccessObject(model, d -> d.fetchIds());
    } else {
        Kind kind = Kind.from(model);
        Map<String, T> cache = caches.getCache(kind.getModelName());
        return cache.keySet();
    }
}
Also used : Kind(io.syndesis.common.model.Kind)

Example 7 with Kind

use of io.syndesis.common.model.Kind in project syndesis by syndesisio.

the class DataStoreConfiguration method jsonDB.

@Bean
@Autowired
@SuppressWarnings("PMD.EmptyCatchBlock")
public SqlJsonDB jsonDB(DBI dbi, Optional<List<Index>> beanIndexes) {
    ArrayList<Index> indexes = new ArrayList<>();
    if (beanIndexes.isPresent()) {
        indexes.addAll(beanIndexes.get());
    }
    for (Kind kind : Kind.values()) {
        addIndex(indexes, kind, kind.getModelClass().getAnnotation(UniqueProperty.class));
        UniqueProperty.Multiple ump = kind.getModelClass().getAnnotation(UniqueProperty.Multiple.class);
        if (ump != null) {
            for (UniqueProperty p : ump.value()) {
                addIndex(indexes, kind, p);
            }
        }
        addIndex(indexes, kind, kind.getModelClass().getAnnotation(IndexedProperty.class));
        IndexedProperty.Multiple imp = kind.getModelClass().getAnnotation(IndexedProperty.Multiple.class);
        if (imp != null) {
            for (IndexedProperty p : imp.value()) {
                addIndex(indexes, kind, p);
            }
        }
    }
    SqlJsonDB jsondb = new SqlJsonDB(dbi, null, indexes);
    try {
        jsondb.createTables();
    } catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") Exception ignore) {
        LOG.debug("Could not create tables", ignore);
    }
    return jsondb;
}
Also used : SqlJsonDB(io.syndesis.server.jsondb.impl.SqlJsonDB) IndexedProperty(io.syndesis.common.util.IndexedProperty) Kind(io.syndesis.common.model.Kind) ArrayList(java.util.ArrayList) Index(io.syndesis.server.jsondb.impl.Index) UniqueProperty(io.syndesis.common.model.validation.UniqueProperty) Autowired(org.springframework.beans.factory.annotation.Autowired) Bean(org.springframework.context.annotation.Bean)

Example 8 with Kind

use of io.syndesis.common.model.Kind in project syndesis by syndesisio.

the class DataManager method delete.

public <T extends WithId<T>> boolean delete(Class<T> model, String id) {
    if (id == null || id.equals("")) {
        throw new EntityNotFoundException("Setting the id on the entity is required for updates");
    }
    Kind kind = Kind.from(model);
    Map<String, WithId<T>> cache = caches.getCache(kind.getModelName());
    // Remove it out of the cache
    WithId<T> entity = cache.remove(id);
    boolean deletedInCache = entity != null;
    // And out of the DAO
    boolean deletedFromDAO = Boolean.TRUE.equals(doWithDataAccessObject(model, d -> d.delete(id)));
    // Return true if the entity was found in any of the two.
    if (deletedInCache || deletedFromDAO) {
        broadcast(EventBus.Action.DELETED, kind.getModelName(), id);
        return true;
    }
    return false;
}
Also used : ModelData(io.syndesis.common.model.ModelData) KeyGenerator(io.syndesis.common.util.KeyGenerator) ResourcePatternUtils(org.springframework.core.io.support.ResourcePatternUtils) Kind(io.syndesis.common.model.Kind) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Value(org.springframework.beans.factory.annotation.Value) Connection(io.syndesis.common.model.connection.Connection) Service(org.springframework.stereotype.Service) Map(java.util.Map) EntityNotFoundException(javax.persistence.EntityNotFoundException) Resource(org.springframework.core.io.Resource) StreamUtils(org.springframework.util.StreamUtils) Logger(org.slf4j.Logger) ResourceLoader(org.springframework.core.io.ResourceLoader) EntityExistsException(javax.persistence.EntityExistsException) WithId(io.syndesis.common.model.WithId) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Connector(io.syndesis.common.model.connection.Connector) IOException(java.io.IOException) ListResult(io.syndesis.common.model.ListResult) FileNotFoundException(java.io.FileNotFoundException) StandardCharsets(java.nio.charset.StandardCharsets) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) PersistenceException(javax.persistence.PersistenceException) ReadApiClientData(io.syndesis.server.dao.init.ReadApiClientData) SyndesisServerException(io.syndesis.common.util.SyndesisServerException) WithVersion(io.syndesis.common.model.WithVersion) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) WithIdVersioned(io.syndesis.common.model.WithIdVersioned) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) EventBus(io.syndesis.common.util.EventBus) CacheManager(io.syndesis.common.util.cache.CacheManager) ChangeEvent(io.syndesis.common.model.ChangeEvent) Json(io.syndesis.common.util.Json) InputStream(java.io.InputStream) WithId(io.syndesis.common.model.WithId) Kind(io.syndesis.common.model.Kind) EntityNotFoundException(javax.persistence.EntityNotFoundException)

Example 9 with Kind

use of io.syndesis.common.model.Kind in project syndesis by syndesisio.

the class DataManager method store.

public <T extends WithId<T>> void store(ModelData<T> modelData) {
    try {
        final Kind kind = modelData.getKind();
        final T entity = modelData.getData();
        LOGGER.debug("{}:{}", kind, modelData.getDataAsJson());
        store(entity, kind.getModelClass());
    } catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") Exception e) {
        LOGGER.warn("Cannot load entity from file: ", e);
        throw SyndesisServerException.launderThrowable(e);
    }
}
Also used : Kind(io.syndesis.common.model.Kind) EntityNotFoundException(javax.persistence.EntityNotFoundException) EntityExistsException(javax.persistence.EntityExistsException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) PersistenceException(javax.persistence.PersistenceException) SyndesisServerException(io.syndesis.common.util.SyndesisServerException)

Example 10 with Kind

use of io.syndesis.common.model.Kind in project syndesis by syndesisio.

the class DataManager method set.

public <T extends WithId<T>> void set(T entity) {
    Optional<String> id = entity.getId();
    if (!id.isPresent()) {
        throw new EntityNotFoundException("Setting the id on the entity is required for set");
    }
    String idVal = id.get();
    Kind kind = entity.getKind();
    this.<T, T>doWithDataAccessObject(kind.getModelClass(), d -> {
        d.set(entity);
        return null;
    });
    Map<String, T> cache = caches.getCache(kind.getModelName());
    cache.put(idVal, entity);
    broadcast(EventBus.Action.UPDATED, kind.getModelName(), idVal);
}
Also used : Kind(io.syndesis.common.model.Kind) EntityNotFoundException(javax.persistence.EntityNotFoundException)

Aggregations

Kind (io.syndesis.common.model.Kind)11 EntityNotFoundException (javax.persistence.EntityNotFoundException)5 EntityExistsException (javax.persistence.EntityExistsException)4 ListResult (io.syndesis.common.model.ListResult)3 WithId (io.syndesis.common.model.WithId)3 WithIdVersioned (io.syndesis.common.model.WithIdVersioned)3 WithVersion (io.syndesis.common.model.WithVersion)3 SyndesisServerException (io.syndesis.common.util.SyndesisServerException)3 FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 PersistenceException (javax.persistence.PersistenceException)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 ChangeEvent (io.syndesis.common.model.ChangeEvent)2 ModelData (io.syndesis.common.model.ModelData)2 Connection (io.syndesis.common.model.connection.Connection)2 Connector (io.syndesis.common.model.connection.Connector)2 EventBus (io.syndesis.common.util.EventBus)2 Json (io.syndesis.common.util.Json)2 KeyGenerator (io.syndesis.common.util.KeyGenerator)2