Search in sources :

Example 1 with EntitiesService

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

the class MbtDiscoveryResultDispatcherImpl method postUnits.

private boolean postUnits(EntitiesService entitiesService, List<UftTestAction> actions, Map<String, Entity> foldersMap, long workspaceId) {
    if (!actions.isEmpty()) {
        logger.info("dispatching {} new units", actions.size());
        // add external parameter entities list to be filled by each action creation
        List<Entity> parameterToAdd = new ArrayList<>();
        // add units
        List<Entity> unitsToAdd = actions.stream().map(action -> createUnitEntity(action, foldersMap, parameterToAdd)).collect(Collectors.toList());
        Map<String, Entity> unitEntities = entitiesService.postEntities(workspaceId, EntityConstants.MbtUnit.COLLECTION_NAME, unitsToAdd, Collections.singletonList(EntityConstants.MbtUnit.REPOSITORY_PATH_FIELD)).stream().collect(Collectors.toMap(entity -> entity.getField(EntityConstants.MbtUnit.REPOSITORY_PATH_FIELD).toString(), Function.identity()));
        logger.info("actual new units {} added", unitEntities.size());
        // replace parent unit entities for parameters in order to save their relations
        logger.info("dispatching {} new unit parameters", parameterToAdd.size());
        parameterToAdd.forEach(parameter -> {
            Entity parentUnit = (Entity) parameter.getField(EntityConstants.MbtUnitParameter.MODEL_ITEM);
            Entity newParentUnit = unitEntities.get(parentUnit.getField(EntityConstants.MbtUnit.REPOSITORY_PATH_FIELD).toString());
            parameter.setField(EntityConstants.MbtUnitParameter.MODEL_ITEM, createModelItemEntity(newParentUnit));
        });
        // add parameters
        List<Entity> unitParameterEntities = entitiesService.postEntities(workspaceId, EntityConstants.MbtUnitParameter.COLLECTION_NAME, parameterToAdd);
        logger.info("actual new unit parameters {} added", unitParameterEntities.size());
    }
    return true;
}
Also used : EntitiesService(com.hp.octane.integrations.services.entities.EntitiesService) EntityConstants(com.hp.octane.integrations.dto.entities.EntityConstants) java.util(java.util) Logger(org.apache.logging.log4j.Logger) Entity(com.hp.octane.integrations.dto.entities.Entity) com.hp.octane.integrations.uft.items(com.hp.octane.integrations.uft.items) SdkStringUtils(com.hp.octane.integrations.utils.SdkStringUtils) QueryHelper(com.hp.octane.integrations.services.entities.QueryHelper) LogManager(org.apache.logging.log4j.LogManager) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) CollectionUtils(org.apache.commons.collections4.CollectionUtils) Entity(com.hp.octane.integrations.dto.entities.Entity)

Example 2 with EntitiesService

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

the class OctaneSDK method testOctaneConfigurationAndFetchAvailableWorkspaces.

/**
 * This method allows to test Octane configuration prior to creating full functioning Octane client (use case - test connection in UI)
 * In case of failed configuration , IllegalArgumentException is thrown
 *
 * @param octaneServerUrl base Octane server URL
 * @param sharedSpaceId   shared space ID
 * @param client          client / api key
 * @param secret          secret / api secret
 * @param pluginServicesClass class that extends CIPluginServices
 * @return   List of available workspaces
 * @throws IOException in case of basic connectivity failure
 */
public static List<Entity> testOctaneConfigurationAndFetchAvailableWorkspaces(String octaneServerUrl, String sharedSpaceId, String client, String secret, Class<? extends CIPluginServices> pluginServicesClass) throws IOException {
    // instance ID is a MUST parameter but not needed for configuration validation, therefore RANDOM value provided
    OctaneConfiguration configuration = OctaneConfiguration.create(UUID.randomUUID().toString(), octaneServerUrl, sharedSpaceId);
    configuration.setSecret(secret);
    configuration.setClient(client);
    if (pluginServicesClass == null) {
        throw new IllegalArgumentException("plugin services provider is invalid");
    }
    CIPluginServices pluginServices;
    try {
        pluginServices = pluginServicesClass.newInstance();
    } catch (InstantiationException | IllegalAccessException e) {
        throw new IllegalArgumentException("failed to instantiate plugin services '" + pluginServicesClass.getSimpleName() + "'", e);
    }
    SDKServicesConfigurer configurer = new SDKServicesConfigurer(configuration, pluginServices);
    RestService restService = RestService.newInstance(configurer);
    ConfigurationService configurationService = ConfigurationService.newInstance(configurer, restService);
    OctaneConnectivityStatus octaneConnectivityStatus = configurationService.validateConfigurationAndGetConnectivityStatus();
    if (!CIPluginSDKUtils.isSdkSupported(octaneConnectivityStatus)) {
        throw new OctaneConnectivityException(0, OctaneConnectivityException.UNSUPPORTED_SDK_VERSION_KEY, OctaneConnectivityException.UNSUPPORTED_SDK_VERSION_MESSAGE);
    }
    try {
        EntitiesService entitiesService = EntitiesService.newInstance(configurer, restService);
        List<Entity> workspaces = entitiesService.getEntities(null, /*no workspace*/
        EntityConstants.Workspaces.COLLECTION_NAME, null, /*no conditions*/
        Arrays.asList(EntityConstants.Base.NAME_FIELD));
        return workspaces;
    } catch (Exception e) {
        logger.error(configuration.getLocationForLog() + "Failed to fetch workspaces in testOctaneConfigurationAndFetchAvailableWorkspaces : " + e.getMessage());
        return null;
    }
}
Also used : OctaneConnectivityException(com.hp.octane.integrations.exceptions.OctaneConnectivityException) Entity(com.hp.octane.integrations.dto.entities.Entity) IOException(java.io.IOException) OctaneConnectivityException(com.hp.octane.integrations.exceptions.OctaneConnectivityException) OctaneConnectivityStatus(com.hp.octane.integrations.dto.general.OctaneConnectivityStatus) ConfigurationService(com.hp.octane.integrations.services.configuration.ConfigurationService) EntitiesService(com.hp.octane.integrations.services.entities.EntitiesService) RestService(com.hp.octane.integrations.services.rest.RestService)

Aggregations

Entity (com.hp.octane.integrations.dto.entities.Entity)2 EntitiesService (com.hp.octane.integrations.services.entities.EntitiesService)2 EntityConstants (com.hp.octane.integrations.dto.entities.EntityConstants)1 OctaneConnectivityStatus (com.hp.octane.integrations.dto.general.OctaneConnectivityStatus)1 OctaneConnectivityException (com.hp.octane.integrations.exceptions.OctaneConnectivityException)1 ConfigurationService (com.hp.octane.integrations.services.configuration.ConfigurationService)1 QueryHelper (com.hp.octane.integrations.services.entities.QueryHelper)1 RestService (com.hp.octane.integrations.services.rest.RestService)1 com.hp.octane.integrations.uft.items (com.hp.octane.integrations.uft.items)1 SdkStringUtils (com.hp.octane.integrations.utils.SdkStringUtils)1 IOException (java.io.IOException)1 java.util (java.util)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 CollectionUtils (org.apache.commons.collections4.CollectionUtils)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1