return mapper(session).selectComponentsHavingSameKeyOrderedById(key);
}
- /**
- * Optional parent. It is absent if specified component is root.
- */
- public Optional<ComponentDto> selectParent(DbSession dbSession, ComponentDto component) {
- if (component.isRoot()) {
- return Optional.absent();
- }
- List<String> path = component.getUuidPathAsList();
- String parentUuid = path.get(path.size() - 1);
- return Optional.of(mapper(dbSession).selectByUuid(parentUuid));
- }
-
/**
* List of ancestors, ordered from root to parent. The list is empty
* if the component is a tree root. Disabled components are excluded by design
mapper(session).insert(item);
}
- public void insertBatch(DbSession session, ComponentDto item) {
- mapper(session).insertBatch(item);
- }
-
public void insert(DbSession session, Collection<ComponentDto> items) {
for (ComponentDto item : items) {
insert(session, item);
db.assertDbUnit(getClass(), "insert-result.xml", "projects");
}
- @Test
- public void insertBatch() {
- try (DbSession batchSession = db.myBatis().openSession(true)) {
- db.prepareDbUnit(getClass(), "empty.xml");
-
- ComponentDto componentDto = new ComponentDto()
- .setOrganizationUuid("org1")
- .setUuid("GHIJ")
- .setUuidPath("ABCD.EFGH.GHIJ.")
- .setProjectUuid("ABCD")
- .setModuleUuid("EFGH")
- .setModuleUuidPath(".ABCD.EFGH.")
- .setKey("org.struts:struts-core:src/org/struts/RequestContext.java")
- .setDeprecatedKey("org.struts:struts-core:src/org/struts/RequestContext.java")
- .setName("RequestContext.java")
- .setLongName("org.struts.RequestContext")
- .setQualifier("FIL")
- .setScope("FIL")
- .setLanguage("java")
- .setDescription("description")
- .setPath("src/org/struts/RequestContext.java")
- .setRootUuid("uuid_3")
- .setCopyComponentUuid("uuid_5")
- .setDeveloperUuid("uuid_7")
- .setEnabled(true)
- .setCreatedAt(DateUtils.parseDate("2014-06-18"))
- .setAuthorizationUpdatedAt(123456789L);
-
- underTest.insertBatch(batchSession, componentDto);
- batchSession.commit();
-
- assertThat(componentDto.getId()).isNull();
- db.assertDbUnit(getClass(), "insert-result.xml", "projects");
- }
- }
-
@Test
public void insert_disabled_component() {
db.prepareDbUnit(getClass(), "empty.xml");
.doesNotContain(cLang.getId());
}
- @Test
- public void selectParent() {
- // project -> module -> file
- ComponentDto project = newProjectDto(db.getDefaultOrganization(), PROJECT_UUID);
- componentDb.insertProjectAndSnapshot(project);
- ComponentDto module = newModuleDto(MODULE_UUID, project);
- componentDb.insertComponent(module);
- ComponentDto file = newFileDto(module, null, FILE_1_UUID);
- componentDb.insertComponent(file);
- db.commit();
-
- assertThat(underTest.selectParent(dbSession, project)).isAbsent();
- assertThat(underTest.selectParent(dbSession, module).get().uuid()).isEqualTo(PROJECT_UUID);
- assertThat(underTest.selectParent(dbSession, file).get().uuid()).isEqualTo(MODULE_UUID);
- }
-
@Test
public void selectAncestors() {
// organization