Search in sources :

Example 1 with ScmResourceFile

use of com.hp.octane.integrations.uft.items.ScmResourceFile in project octane-ci-java-sdk by MicroFocus.

the class UftDiscoveryResultPreparerImpl method handleMovedDataTables.

private void handleMovedDataTables(UftTestDiscoveryResult result) {
    List<ScmResourceFile> newItems = result.getNewScmResourceFiles();
    List<ScmResourceFile> deletedItems = result.getDeletedScmResourceFiles();
    if (!newItems.isEmpty() && !deletedItems.isEmpty()) {
        Map<String, ScmResourceFile> dst2File = new HashMap<>();
        Map<ScmResourceFile, ScmResourceFile> deleted2newMovedFiles = new HashMap<>();
        for (ScmResourceFile newFile : newItems) {
            if (SdkStringUtils.isNotEmpty(newFile.getChangeSetDst())) {
                dst2File.put(newFile.getChangeSetDst(), newFile);
            }
        }
        for (ScmResourceFile deletedFile : deletedItems) {
            if (SdkStringUtils.isNotEmpty(deletedFile.getChangeSetDst()) && dst2File.containsKey(deletedFile.getChangeSetDst())) {
                ScmResourceFile newFile = dst2File.get(deletedFile.getChangeSetDst());
                deleted2newMovedFiles.put(deletedFile, newFile);
            }
        }
        for (Map.Entry<ScmResourceFile, ScmResourceFile> entry : deleted2newMovedFiles.entrySet()) {
            ScmResourceFile deletedFile = entry.getKey();
            ScmResourceFile newFile = entry.getValue();
            newFile.setIsMoved(true);
            newFile.setOldName(deletedFile.getName());
            newFile.setOldRelativePath(deletedFile.getRelativePath());
            newFile.setOctaneStatus(OctaneStatus.MODIFIED);
            result.getAllScmResourceFiles().remove(deletedFile);
        }
    }
}
Also used : ScmResourceFile(com.hp.octane.integrations.uft.items.ScmResourceFile)

Example 2 with ScmResourceFile

use of com.hp.octane.integrations.uft.items.ScmResourceFile 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;
}
Also used : Entity(com.hp.octane.integrations.dto.entities.Entity) ScmResourceFile(com.hp.octane.integrations.uft.items.ScmResourceFile)

Example 3 with ScmResourceFile

use of com.hp.octane.integrations.uft.items.ScmResourceFile 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;
}
Also used : Entity(com.hp.octane.integrations.dto.entities.Entity) ScmResourceFile(com.hp.octane.integrations.uft.items.ScmResourceFile)

Aggregations

ScmResourceFile (com.hp.octane.integrations.uft.items.ScmResourceFile)3 Entity (com.hp.octane.integrations.dto.entities.Entity)2