use of com.hp.octane.integrations.dto.entities.Entity in project octane-ci-java-sdk by MicroFocus.
the class UftDiscoveryResultDispatcherImpl method updateScmResources.
private boolean updateScmResources(EntitiesService entitiesService, List<ScmResourceFile> updatedResourceFiles, String workspaceId) {
try {
// CONVERT TO DTO
List<Entity> entitiesForUpdate = new ArrayList<>(updatedResourceFiles.size());
for (ScmResourceFile resource : updatedResourceFiles) {
Entity entity = dtoFactory.newDTO(Entity.class).setType(EntityConstants.ScmResourceFile.ENTITY_NAME).setName(resource.getName()).setId(resource.getId()).setField(EntityConstants.ScmResourceFile.RELATIVE_PATH_FIELD, resource.getRelativePath());
entitiesForUpdate.add(entity);
}
if (!updatedResourceFiles.isEmpty()) {
for (int i = 0; i < updatedResourceFiles.size(); i += POST_BULK_SIZE) {
List<Entity> data = entitiesForUpdate.subList(i, Math.min(i + POST_BULK_SIZE, entitiesForUpdate.size()));
entitiesService.updateEntities(Long.parseLong(workspaceId), EntityConstants.ScmResourceFile.COLLECTION_NAME, data);
}
}
return true;
} catch (Exception e) {
logger.error("Failed to update data tables : " + e.getMessage());
return false;
}
}
use of com.hp.octane.integrations.dto.entities.Entity in project octane-ci-java-sdk by MicroFocus.
the class UftDiscoveryResultPreparerImpl method matchDiscoveryDataTablesResultsWithOctaneForFullSync.
/**
* Go over discovered and octane data tables
* 1.if DT doesn't exist on octane - this is new DT
* 2. all DTs that are found in Octane but not discovered - delete those DTs from server
*/
private boolean matchDiscoveryDataTablesResultsWithOctaneForFullSync(EntitiesService entitiesService, UftTestDiscoveryResult discoveryResult) {
boolean hasDiff = false;
Map<String, Entity> octaneDataTablesMap = getDataTablesFromServer(entitiesService, Long.parseLong(discoveryResult.getWorkspaceId()), Long.parseLong(discoveryResult.getScmRepositoryId()), null);
for (ScmResourceFile dataTable : discoveryResult.getAllScmResourceFiles()) {
Entity octaneDataTable = octaneDataTablesMap.remove(dataTable.getRelativePath());
if (octaneDataTable != null) {
// found in Octnat - skip
dataTable.setOctaneStatus(OctaneStatus.NONE);
hasDiff = true;
}
}
// go over DT that exist in Octane but not discovered
for (Entity octaneDataTable : octaneDataTablesMap.values()) {
hasDiff = true;
ScmResourceFile dt = new ScmResourceFile();
dt.setId(octaneDataTable.getId());
dt.setName(octaneDataTable.getName());
dt.setRelativePath(octaneDataTable.getStringValue(EntityConstants.ScmResourceFile.RELATIVE_PATH_FIELD));
dt.setOctaneStatus(OctaneStatus.DELETED);
discoveryResult.getAllScmResourceFiles().add(dt);
}
return hasDiff;
}
use of com.hp.octane.integrations.dto.entities.Entity in project octane-ci-java-sdk by MicroFocus.
the class UftDiscoveryResultPreparerImpl method validateTestDiscoveryAndCompleteDataTableIdsForScmChangeDetection.
private boolean validateTestDiscoveryAndCompleteDataTableIdsForScmChangeDetection(EntitiesService entitiesService, UftTestDiscoveryResult result) {
boolean hasDiff = false;
Set<String> allNames = new HashSet<>();
for (ScmResourceFile file : result.getAllScmResourceFiles()) {
if (file.getIsMoved()) {
allNames.add(file.getOldName());
} else {
allNames.add(file.getName());
}
}
// GET DataTables FROM OCTANE
Map<String, Entity> octaneEntityMapByRelativePath = getDataTablesFromServer(entitiesService, Long.parseLong(result.getWorkspaceId()), Long.parseLong(result.getScmRepositoryId()), allNames);
// MATCHING
for (ScmResourceFile file : result.getAllScmResourceFiles()) {
String key = file.getIsMoved() ? file.getOldRelativePath() : file.getRelativePath();
Entity octaneFile = octaneEntityMapByRelativePath.get(key);
boolean octaneFileFound = (octaneFile != null);
if (octaneFileFound) {
file.setId(octaneFile.getId());
}
switch(file.getOctaneStatus()) {
case DELETED:
if (!octaneFileFound) {
// file that is marked to be deleted - doesn't exist in Octane - do nothing
hasDiff = true;
file.setOctaneStatus(OctaneStatus.NONE);
}
break;
case MODIFIED:
if (!octaneFileFound) {
// updated file that has no matching in Octane, possibly was remove from Octane. So we move it to new
hasDiff = true;
file.setOctaneStatus(OctaneStatus.NEW);
}
break;
case NEW:
if (octaneFileFound) {
// new file was found in Octane - do nothing(there is nothing to update)
hasDiff = true;
file.setOctaneStatus(OctaneStatus.NONE);
}
break;
default:
}
}
return hasDiff;
}
use of com.hp.octane.integrations.dto.entities.Entity in project octane-ci-java-sdk by MicroFocus.
the class UftDiscoveryResultPreparerImpl method getOctaneVersion.
private String getOctaneVersion(EntitiesService entitiesService) {
String octaneVersion = null;
List<Entity> entities = entitiesService.getEntities(null, "server_version", null, null);
if (entities.size() == 1) {
Entity entity = entities.get(0);
octaneVersion = entity.getStringValue("version");
logger.debug("Received Octane version - " + octaneVersion);
} else {
logger.error(String.format("Request for Octane version returned %s items. return version is not defined.", entities.size()));
}
return octaneVersion;
}
use of com.hp.octane.integrations.dto.entities.Entity in project octane-ci-java-sdk by MicroFocus.
the class UftDiscoveryResultPreparerImpl method validateTestDiscoveryAndCompleteTestIdsForScmChangeDetection.
/**
* This method try to find ids of updated and deleted tests for scm change detection
* if test is found on server - update id of discovered test
* if test is not found and test is marked for update - move it to new tests (possibly test was deleted on server)
*
* @return true if there were changes comparing to discoverede results
*/
private boolean validateTestDiscoveryAndCompleteTestIdsForScmChangeDetection(EntitiesService entitiesService, UftTestDiscoveryResult result) {
boolean hasDiff = false;
Set<String> allTestNames = new HashSet<>();
for (AutomatedTest test : result.getAllTests()) {
if (test.getIsMoved()) {
allTestNames.add(test.getOldName());
} else {
allTestNames.add(test.getName());
}
}
// GET TESTS FROM OCTANE
Collection<String> additionalFields = SdkStringUtils.isNotEmpty(result.getTestRunnerId()) ? Collections.singletonList(EntityConstants.AutomatedTest.TEST_RUNNER_FIELD) : null;
Map<String, Entity> octaneTestsMapByKey = getTestsFromServer(entitiesService, Long.parseLong(result.getWorkspaceId()), Long.parseLong(result.getScmRepositoryId()), true, allTestNames, additionalFields);
// MATCHING
for (AutomatedTest discoveredTest : result.getAllTests()) {
String key = discoveredTest.getIsMoved() ? createKey(discoveredTest.getOldPackage(), discoveredTest.getOldName()) : createKey(discoveredTest.getPackage(), discoveredTest.getName());
Entity octaneTest = octaneTestsMapByKey.get(key);
boolean octaneTestFound = (octaneTest != null);
if (octaneTestFound) {
discoveredTest.setId(octaneTest.getId());
}
switch(discoveredTest.getOctaneStatus()) {
case DELETED:
if (!octaneTestFound) {
// discoveredTest that is marked to be deleted - doesn't exist in Octane - do nothing
hasDiff = true;
discoveredTest.setOctaneStatus(OctaneStatus.NONE);
}
break;
case MODIFIED:
if (!octaneTestFound) {
// updated discoveredTest that has no matching in Octane, possibly was remove from Octane. So we move it to new tests
hasDiff = true;
discoveredTest.setOctaneStatus(OctaneStatus.NEW);
} else {
boolean testsEqual = checkTestEquals(discoveredTest, octaneTest, result.getTestRunnerId());
if (testsEqual) {
// if equal - skip
discoveredTest.setOctaneStatus(OctaneStatus.NONE);
}
}
break;
case NEW:
if (octaneTestFound) {
// new discoveredTest was found in Octane - move it to update
hasDiff = true;
discoveredTest.setOctaneStatus(OctaneStatus.MODIFIED);
}
break;
default:
}
}
return hasDiff;
}
Aggregations