use of org.eclipse.che.api.factory.server.model.impl.FactoryImpl in project che by eclipse.
the class FactoryDaoTest method setUp.
@BeforeMethod
public void setUp() throws Exception {
factories = new FactoryImpl[ENTRY_COUNT];
users = new UserImpl[ENTRY_COUNT];
for (int i = 0; i < ENTRY_COUNT; i++) {
users[i] = new UserImpl("userId_" + i, "email_" + i, "name" + i);
}
for (int i = 0; i < ENTRY_COUNT; i++) {
factories[i] = createFactory(i, users[i].getId());
}
userTckRepository.createAll(Arrays.asList(users));
factoryTckRepository.createAll(Stream.of(factories).map(FactoryImpl::new).collect(toList()));
}
use of org.eclipse.che.api.factory.server.model.impl.FactoryImpl in project che by eclipse.
the class FactoryDaoTest method shouldGetFactoryByIdAttribute.
@Test
public void shouldGetFactoryByIdAttribute() throws Exception {
final FactoryImpl factory = factories[0];
final List<Pair<String, String>> attributes = ImmutableList.of(Pair.of("id", factory.getId()));
final List<FactoryImpl> result = factoryDao.getByAttribute(1, 0, attributes);
assertEquals(new HashSet<>(result), ImmutableSet.of(factory));
}
use of org.eclipse.che.api.factory.server.model.impl.FactoryImpl in project che by eclipse.
the class FactoryManager method updateFactory.
/**
* Updates factory and its images accordance to the new configuration.
*
* <p>Note: Updating uses replacement strategy,
* therefore existing factory would be replaced with given update {@code update}
*
* @param update
* factory update
* @return updated factory
* @throws NullPointerException
* when {@code update} is null
* @throws ConflictException
* when any conflict occurs (e.g Factory with given name already exists for {@code creator})
* @throws NotFoundException
* when factory with given id not found
* @throws ServerException
* when any server error occurs
*/
public Factory updateFactory(Factory update, Set<FactoryImage> images) throws ConflictException, NotFoundException, ServerException {
requireNonNull(update);
final AuthorImpl creator = factoryDao.getById(update.getId()).getCreator();
return factoryDao.update(FactoryImpl.builder().from(new FactoryImpl(update, images)).setCreator(new AuthorImpl(creator.getUserId(), creator.getCreated())).build());
}
use of org.eclipse.che.api.factory.server.model.impl.FactoryImpl in project che by eclipse.
the class FactoryDaoTest method shouldUpdateFactory.
// TODO fix after issue: https://github.com/eclipse/che/issues/2110
// @Test(expectedExceptions = ConflictException.class)
// public void shouldThrowConflictExceptionWhenCreatingFactoryWithExistingNameAndUserId() throws Exception {
// final FactoryImpl factory = createFactory(10, users[0].getId());
// final FactoryImpl existing = factories[0];
// factory.getCreator().setUserId(existing.getCreator().getUserId());
// factory.setName(existing.getName());
// factoryDao.create(factory);
// }
@Test
public void shouldUpdateFactory() throws Exception {
final FactoryImpl update = factories[0];
final String userId = update.getCreator().getUserId();
update.setName("new-name");
update.setV("5_0");
final long currentTime = System.currentTimeMillis();
update.setPolicies(new PoliciesImpl("ref", "match", "per-click", currentTime, currentTime + 1000));
update.setCreator(new AuthorImpl(userId, currentTime));
update.setButton(new ButtonImpl(new ButtonAttributesImpl("green", "icon", "opacity 0.9", true), Button.Type.NOLOGO));
update.getIde().getOnAppClosed().getActions().add(new ActionImpl("remove file", ImmutableMap.of("file1", "/che/core/pom.xml")));
update.getIde().getOnAppLoaded().getActions().add(new ActionImpl("edit file", ImmutableMap.of("file2", "/che/core/pom.xml")));
update.getIde().getOnProjectsLoaded().getActions().add(new ActionImpl("open file", ImmutableMap.of("file2", "/che/pom.xml")));
factoryDao.update(update);
assertEquals(factoryDao.getById(update.getId()), update);
}
use of org.eclipse.che.api.factory.server.model.impl.FactoryImpl in project che by eclipse.
the class FactoryDaoTest method createFactory.
private static FactoryImpl createFactory(int index, String userId) {
final long timeMs = System.currentTimeMillis();
final ButtonImpl factoryButton = new ButtonImpl(new ButtonAttributesImpl("red", "logo", "style", true), Button.Type.LOGO);
final AuthorImpl creator = new AuthorImpl(userId, timeMs);
final PoliciesImpl policies = new PoliciesImpl("referrer", "match", "perClick", timeMs, timeMs + 1000);
final Set<FactoryImage> images = new HashSet<>();
final List<ActionImpl> a1 = new ArrayList<>(singletonList(new ActionImpl("id" + index, ImmutableMap.of("key1", "value1"))));
final OnAppLoadedImpl onAppLoaded = new OnAppLoadedImpl(a1);
final List<ActionImpl> a2 = new ArrayList<>(singletonList(new ActionImpl("id" + index, ImmutableMap.of("key2", "value2"))));
final OnProjectsLoadedImpl onProjectsLoaded = new OnProjectsLoadedImpl(a2);
final List<ActionImpl> a3 = new ArrayList<>(singletonList(new ActionImpl("id" + index, ImmutableMap.of("key3", "value3"))));
final OnAppClosedImpl onAppClosed = new OnAppClosedImpl(a3);
final IdeImpl ide = new IdeImpl(onAppLoaded, onProjectsLoaded, onAppClosed);
final FactoryImpl factory = FactoryImpl.builder().generateId().setVersion("4_0").setName("factoryName" + index).setButton(factoryButton).setCreator(creator).setPolicies(policies).setImages(images).setIde(ide).build();
factory.setWorkspace(createWorkspaceConfig(index));
return factory;
}
Aggregations