Search in sources :

Example 6 with FactoryImpl

use of org.eclipse.che.api.factory.server.model.impl.FactoryImpl in project che by eclipse.

the class FactoryDaoTest method shouldCreateFactory.

@Test(dependsOnMethods = "shouldGetFactoryById")
public void shouldCreateFactory() throws Exception {
    final FactoryImpl factory = createFactory(10, users[0].getId());
    factory.getCreator().setUserId(factories[0].getCreator().getUserId());
    factoryDao.create(factory);
    assertEquals(factoryDao.getById(factory.getId()), new FactoryImpl(factory));
}
Also used : FactoryImpl(org.eclipse.che.api.factory.server.model.impl.FactoryImpl) Test(org.testng.annotations.Test)

Example 7 with FactoryImpl

use of org.eclipse.che.api.factory.server.model.impl.FactoryImpl in project che by eclipse.

the class FactoryDaoTest method shouldThrowConflictExceptionWhenCreatingFactoryWithExistingId.

@Test(expectedExceptions = ConflictException.class)
public void shouldThrowConflictExceptionWhenCreatingFactoryWithExistingId() throws Exception {
    final FactoryImpl factory = createFactory(10, users[0].getId());
    final FactoryImpl existing = factories[0];
    factory.getCreator().setUserId(existing.getCreator().getUserId());
    factory.setId(existing.getId());
    factoryDao.create(factory);
}
Also used : FactoryImpl(org.eclipse.che.api.factory.server.model.impl.FactoryImpl) Test(org.testng.annotations.Test)

Example 8 with FactoryImpl

use of org.eclipse.che.api.factory.server.model.impl.FactoryImpl in project che by eclipse.

the class JpaFactoryDao method doUpdate.

@Transactional
protected FactoryImpl doUpdate(FactoryImpl update) throws NotFoundException {
    final EntityManager manager = managerProvider.get();
    if (manager.find(FactoryImpl.class, update.getId()) == null) {
        throw new NotFoundException(format("Could not update factory with id %s because it doesn't exist", update.getId()));
    }
    if (update.getWorkspace() != null) {
        update.getWorkspace().getProjects().forEach(ProjectConfigImpl::prePersistAttributes);
    }
    FactoryImpl merged = manager.merge(update);
    manager.flush();
    return merged;
}
Also used : EntityManager(javax.persistence.EntityManager) NotFoundException(org.eclipse.che.api.core.NotFoundException) FactoryImpl(org.eclipse.che.api.factory.server.model.impl.FactoryImpl) ProjectConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl) Transactional(com.google.inject.persist.Transactional)

Example 9 with FactoryImpl

use of org.eclipse.che.api.factory.server.model.impl.FactoryImpl in project che by eclipse.

the class JpaFactoryDao method doRemove.

@Transactional
protected void doRemove(String id) {
    final EntityManager manager = managerProvider.get();
    final FactoryImpl factory = manager.find(FactoryImpl.class, id);
    if (factory != null) {
        manager.remove(factory);
        manager.flush();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) FactoryImpl(org.eclipse.che.api.factory.server.model.impl.FactoryImpl) Transactional(com.google.inject.persist.Transactional)

Example 10 with FactoryImpl

use of org.eclipse.che.api.factory.server.model.impl.FactoryImpl in project che by eclipse.

the class JpaFactoryDao method getByAttribute.

@Override
@Transactional
public List<FactoryImpl> getByAttribute(int maxItems, int skipCount, List<Pair<String, String>> attributes) throws ServerException {
    try {
        LOG.info("FactoryDao#getByAttributes #maxItems: {} #skipCount: {}, #attributes: {}", maxItems, skipCount, attributes);
        final Map<String, String> params = new HashMap<>();
        String query = "SELECT factory FROM Factory factory";
        if (!attributes.isEmpty()) {
            final StringJoiner matcher = new StringJoiner(" AND ", " WHERE ", " ");
            int i = 0;
            for (Pair<String, String> attribute : attributes) {
                final String parameterName = "parameterName" + i++;
                params.put(parameterName, attribute.second);
                matcher.add("factory." + attribute.first + " = :" + parameterName);
            }
            query = query + matcher;
        }
        final TypedQuery<FactoryImpl> typedQuery = managerProvider.get().createQuery(query, FactoryImpl.class).setFirstResult(skipCount).setMaxResults(maxItems);
        for (Map.Entry<String, String> entry : params.entrySet()) {
            typedQuery.setParameter(entry.getKey(), entry.getValue());
        }
        return typedQuery.getResultList().stream().map(FactoryImpl::new).collect(Collectors.toList());
    } catch (RuntimeException ex) {
        throw new ServerException(ex.getLocalizedMessage(), ex);
    }
}
Also used : ServerException(org.eclipse.che.api.core.ServerException) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) StringJoiner(java.util.StringJoiner) FactoryImpl(org.eclipse.che.api.factory.server.model.impl.FactoryImpl) Transactional(com.google.inject.persist.Transactional)

Aggregations

FactoryImpl (org.eclipse.che.api.factory.server.model.impl.FactoryImpl)13 Test (org.testng.annotations.Test)6 Transactional (com.google.inject.persist.Transactional)3 AuthorImpl (org.eclipse.che.api.factory.server.model.impl.AuthorImpl)3 EntityManager (javax.persistence.EntityManager)2 ActionImpl (org.eclipse.che.api.factory.server.model.impl.ActionImpl)2 ButtonAttributesImpl (org.eclipse.che.api.factory.server.model.impl.ButtonAttributesImpl)2 ButtonImpl (org.eclipse.che.api.factory.server.model.impl.ButtonImpl)2 PoliciesImpl (org.eclipse.che.api.factory.server.model.impl.PoliciesImpl)2 Pair (org.eclipse.che.commons.lang.Pair)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 StringJoiner (java.util.StringJoiner)1 NotFoundException (org.eclipse.che.api.core.NotFoundException)1 ServerException (org.eclipse.che.api.core.ServerException)1 FactoryImage (org.eclipse.che.api.factory.server.FactoryImage)1 IdeImpl (org.eclipse.che.api.factory.server.model.impl.IdeImpl)1 OnAppClosedImpl (org.eclipse.che.api.factory.server.model.impl.OnAppClosedImpl)1