Search in sources :

Example 31 with Entity

use of com.hp.octane.integrations.dto.entities.Entity in project octane-ci-java-sdk by MicroFocus.

the class MbtDiscoveryResultDispatcherImpl method dispatchDiscoveryResults.

@Override
public void dispatchDiscoveryResults(EntitiesService entitiesService, UftTestDiscoveryResult result, JobRunContext jobRunContext, CustomLogger customLogger) {
    List<UftTestAction> allActions = result.getAllTests().stream().map(AutomatedTest::getActions).flatMap(Collection::stream).collect(Collectors.toList());
    long workspaceId = Long.parseLong(result.getWorkspaceId());
    Map<OctaneStatus, List<UftTestAction>> actionsByStatusMap = allActions.stream().collect(Collectors.groupingBy(UftTestAction::getOctaneStatus));
    Entity autoDiscoveredFolder = null;
    if (CollectionUtils.isNotEmpty(actionsByStatusMap.get(OctaneStatus.NEW)) || CollectionUtils.isNotEmpty(actionsByStatusMap.get(OctaneStatus.MODIFIED))) {
        autoDiscoveredFolder = retrieveParentFolder(entitiesService, workspaceId);
    }
    // handle new actions- create new units and parameters in octane
    dispatchNewActions(entitiesService, actionsByStatusMap.get(OctaneStatus.NEW), autoDiscoveredFolder, workspaceId, customLogger);
    // handle deleted actions- currently do nothing
    dispatchDeletedActions(entitiesService, actionsByStatusMap.get(OctaneStatus.DELETED), workspaceId, customLogger);
    // handle updated actions- update units in octane
    dispatchUpdatedActions(entitiesService, actionsByStatusMap.get(OctaneStatus.MODIFIED), autoDiscoveredFolder, workspaceId, customLogger);
}
Also used : Entity(com.hp.octane.integrations.dto.entities.Entity)

Example 32 with Entity

use of com.hp.octane.integrations.dto.entities.Entity in project octane-ci-java-sdk by MicroFocus.

the class UftDiscoveryResultDispatcherImpl method updateTests.

private boolean updateTests(EntitiesService entitiesService, Collection<AutomatedTest> tests, String workspaceId, String scmRepositoryId, String testRunnerId) {
    Entity testRunner = SdkStringUtils.isNotEmpty(testRunnerId) ? dtoFactory.newDTO(Entity.class).setType(EntityConstants.Executors.ENTITY_NAME).setId(testRunnerId) : null;
    try {
        // CONVERT TO DTO
        List<Entity> testsForUpdate = new ArrayList<>();
        for (AutomatedTest test : tests) {
            Entity octaneTest = dtoFactory.newDTO(Entity.class).setType(EntityConstants.AutomatedTest.ENTITY_NAME).setId(test.getId()).setField(EntityConstants.AutomatedTest.EXECUTABLE_FIELD, test.getExecutable());
            if (test.getDescription() != null) {
                octaneTest.setField(EntityConstants.AutomatedTest.DESCRIPTION_FIELD, test.getDescription());
            }
            if (test.getIsMoved()) {
                octaneTest.setName(test.getName());
                octaneTest.setField(EntityConstants.AutomatedTest.PACKAGE_FIELD, test.getPackage());
            }
            if (test.isMissingScmRepository()) {
                Entity scmRepository = dtoFactory.newDTO(Entity.class).setType(EntityConstants.ScmRepository.ENTITY_NAME).setId(scmRepositoryId);
                octaneTest.setField(EntityConstants.ScmResourceFile.SCM_REPOSITORY_FIELD, scmRepository);
            }
            if (test.isMissingTestRunner() && testRunner != null) {
                octaneTest.setField(EntityConstants.AutomatedTest.TEST_RUNNER_FIELD, testRunner);
            }
            testsForUpdate.add(octaneTest);
        }
        // PUT
        if (!testsForUpdate.isEmpty()) {
            for (int i = 0; i < tests.size(); i += POST_BULK_SIZE) {
                List<Entity> subList = testsForUpdate.subList(i, Math.min(i + POST_BULK_SIZE, tests.size()));
                entitiesService.updateEntities(Long.parseLong(workspaceId), EntityConstants.AutomatedTest.COLLECTION_NAME, subList);
            }
        }
        return true;
    } catch (Exception e) {
        logger.error("Failed to update tests : " + e.getMessage());
        return false;
    }
}
Also used : Entity(com.hp.octane.integrations.dto.entities.Entity) OctaneBulkException(com.hp.octane.integrations.exceptions.OctaneBulkException)

Example 33 with Entity

use of com.hp.octane.integrations.dto.entities.Entity in project octane-ci-java-sdk by MicroFocus.

the class UftDiscoveryResultPreparerImpl method getTestsFromServer.

private Map<String, Entity> getTestsFromServer(EntitiesService entitiesService, long workspaceId, long scmRepositoryId, boolean belongToScmRepository, Collection<String> allTestNames, Collection<String> additionalFieldsToFetch) {
    List<String> conditions = new ArrayList<>();
    if (allTestNames != null && !allTestNames.isEmpty()) {
        String byNameCondition = QueryHelper.conditionIn(EntityConstants.AutomatedTest.NAME_FIELD, allTestNames, false);
        // Here we limit nameCondition by 3K, if it exceed, we will fetch all tests
        if (byNameCondition.length() < QUERY_CONDITION_SIZE_THRESHOLD) {
            conditions.add(byNameCondition);
        }
    }
    if (belongToScmRepository) {
        conditions.add(QueryHelper.conditionRef(EntityConstants.AutomatedTest.SCM_REPOSITORY_FIELD, scmRepositoryId));
    } else {
        conditions.add(QueryHelper.conditionRef(EntityConstants.AutomatedTest.TESTING_TOOL_TYPE_FIELD, "id", "list_node.testing_tool_type.uft"));
        conditions.add(QueryHelper.conditionNot(QueryHelper.conditionRef(EntityConstants.AutomatedTest.SCM_REPOSITORY_FIELD, scmRepositoryId)));
    }
    List<String> fields = new ArrayList<>(Arrays.asList(EntityConstants.AutomatedTest.ID_FIELD, EntityConstants.AutomatedTest.NAME_FIELD, EntityConstants.AutomatedTest.PACKAGE_FIELD, EntityConstants.AutomatedTest.EXECUTABLE_FIELD, EntityConstants.AutomatedTest.DESCRIPTION_FIELD));
    if (additionalFieldsToFetch != null && !additionalFieldsToFetch.isEmpty()) {
        fields.addAll(additionalFieldsToFetch);
    }
    List<Entity> octaneTests = entitiesService.getEntities(workspaceId, EntityConstants.AutomatedTest.COLLECTION_NAME, conditions, fields);
    Map<String, Entity> octaneTestsMapByKey = new HashMap<>();
    for (Entity octaneTest : octaneTests) {
        String key = createKey(octaneTest.getStringValue(EntityConstants.AutomatedTest.PACKAGE_FIELD), octaneTest.getName());
        octaneTestsMapByKey.put(key, octaneTest);
    }
    return octaneTestsMapByKey;
}
Also used : Entity(com.hp.octane.integrations.dto.entities.Entity)

Example 34 with Entity

use of com.hp.octane.integrations.dto.entities.Entity in project octane-ci-java-sdk by MicroFocus.

the class UftDiscoveryResultPreparerImpl method getDataTablesFromServer.

private Map<String, Entity> getDataTablesFromServer(EntitiesService entitiesService, long workspaceId, long scmRepositoryId, Set<String> allNames) {
    List<String> conditions = new ArrayList<>();
    if (allNames != null && !allNames.isEmpty()) {
        String byPathCondition = QueryHelper.conditionIn(EntityConstants.ScmResourceFile.NAME_FIELD, allNames, false);
        // Here we limit nameCondition by 3K, if it exceed, we will fetch all
        if (byPathCondition.length() < QUERY_CONDITION_SIZE_THRESHOLD) {
            conditions.add(byPathCondition);
        }
    }
    String conditionByScmRepository = QueryHelper.conditionRef(EntityConstants.ScmResourceFile.SCM_REPOSITORY_FIELD, scmRepositoryId);
    conditions.add(conditionByScmRepository);
    List<String> dataTablesFields = Arrays.asList(EntityConstants.ScmResourceFile.ID_FIELD, EntityConstants.ScmResourceFile.NAME_FIELD, EntityConstants.ScmResourceFile.RELATIVE_PATH_FIELD);
    List<Entity> octaneDataTables = entitiesService.getEntities(workspaceId, EntityConstants.ScmResourceFile.COLLECTION_NAME, conditions, dataTablesFields);
    Map<String, Entity> octaneDataTablesMap = new HashMap<>();
    for (Entity dataTable : octaneDataTables) {
        octaneDataTablesMap.put(dataTable.getStringValue(EntityConstants.ScmResourceFile.RELATIVE_PATH_FIELD), dataTable);
    }
    return octaneDataTablesMap;
}
Also used : Entity(com.hp.octane.integrations.dto.entities.Entity)

Aggregations

Entity (com.hp.octane.integrations.dto.entities.Entity)34 EntitiesService (com.hp.octane.integrations.services.entities.EntitiesService)6 EntityConstants (com.hp.octane.integrations.dto.entities.EntityConstants)5 OctaneBulkException (com.hp.octane.integrations.exceptions.OctaneBulkException)5 QueryHelper (com.hp.octane.integrations.services.entities.QueryHelper)5 SdkStringUtils (com.hp.octane.integrations.utils.SdkStringUtils)5 java.util (java.util)5 Function (java.util.function.Function)5 Collectors (java.util.stream.Collectors)5 LogManager (org.apache.logging.log4j.LogManager)5 Logger (org.apache.logging.log4j.Logger)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 RestService (com.hp.octane.integrations.services.rest.RestService)4 IOException (java.io.IOException)4 OctaneSDK (com.hp.octane.integrations.OctaneSDK)3 DTOFactory (com.hp.octane.integrations.dto.DTOFactory)3 HttpMethod (com.hp.octane.integrations.dto.connectivity.HttpMethod)3 OctaneRequest (com.hp.octane.integrations.dto.connectivity.OctaneRequest)3 OctaneResponse (com.hp.octane.integrations.dto.connectivity.OctaneResponse)3 TestToRunData (com.hp.octane.integrations.executor.TestToRunData)3