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));
}
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);
}
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;
}
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();
}
}
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);
}
}
Aggregations