Search in sources :

Example 11 with UrlDto

use of org.openkilda.store.model.UrlDto in project open-kilda by telstra.

the class LinkStoreConfigValidator method validate.

/**
 * Validate.
 *
 * @param linkStoreConfigDto the link store config dto
 */
public void validate(final LinkStoreConfigDto linkStoreConfigDto) {
    List<OauthConfigEntity> oauthConfigEntityList = oauthConfigRepository.findByAuthType_authTypeId(AuthType.OAUTH_TWO.getAuthTypeEntity().getAuthTypeId());
    if (CollectionUtil.isEmpty(oauthConfigEntityList)) {
        LOGGER.warn(messageUtil.getStoreMustConfigured());
        throw new RequestValidationException(messageUtil.getStoreMustConfigured());
    }
    List<String> urls = StoreUrl.getUrlName(StoreType.LINK_STORE.getCode());
    for (Entry<String, UrlDto> urlEntrySet : linkStoreConfigDto.getUrls().entrySet()) {
        if (!urls.contains(urlEntrySet.getKey())) {
            LOGGER.warn("Validation fail for link store configuration. Error: " + messageUtil.getAttributeNotvalid(urlEntrySet.getKey()));
            throw new RequestValidationException(messageUtil.getAttributeNotvalid(urlEntrySet.getKey()));
        } else if (ValidatorUtil.isNull(urlEntrySet.getValue().getUrl())) {
            LOGGER.warn("Validation fail for link store configuration. Error: " + messageUtil.getAttributeNotNull("url of " + urlEntrySet.getKey()));
            throw new RequestValidationException(messageUtil.getAttributeNotNull(urlEntrySet.getKey()));
        } else if (ValidatorUtil.isNull(urlEntrySet.getValue().getMethodType())) {
            LOGGER.warn("Validation fail for link store configuration. Error: " + messageUtil.getAttributeNotNull("method-type of " + urlEntrySet.getKey()));
            throw new RequestValidationException(messageUtil.getAttributeNotNull("method-type of " + urlEntrySet.getKey()));
        }
    }
}
Also used : OauthConfigEntity(org.openkilda.store.auth.dao.entity.OauthConfigEntity) UrlDto(org.openkilda.store.model.UrlDto) RequestValidationException(org.usermanagement.exception.RequestValidationException)

Example 12 with UrlDto

use of org.openkilda.store.model.UrlDto in project open-kilda by telstra.

the class SwitchStoreConfigValidator method validate.

/**
 * Validate.
 *
 * @param switchStoreConfigDto the link store config dto
 */
public void validate(final SwitchStoreConfigDto switchStoreConfigDto) {
    List<OauthConfigEntity> oauthConfigEntityList = oauthConfigRepository.findByAuthType_authTypeId(AuthType.OAUTH_TWO.getAuthTypeEntity().getAuthTypeId());
    if (CollectionUtil.isEmpty(oauthConfigEntityList)) {
        LOGGER.warn(messageUtil.getStoreMustConfigured());
        throw new RequestValidationException(messageUtil.getStoreMustConfigured());
    }
    List<String> urls = StoreUrl.getUrlName(StoreType.SWITCH_STORE.getCode());
    for (Entry<String, UrlDto> urlEntrySet : switchStoreConfigDto.getUrls().entrySet()) {
        if (!urls.contains(urlEntrySet.getKey())) {
            LOGGER.warn("Validation fail for switch store configuration. Error: " + messageUtil.getAttributeNotvalid(urlEntrySet.getKey()));
            throw new RequestValidationException(messageUtil.getAttributeNotvalid(urlEntrySet.getKey()));
        } else if (ValidatorUtil.isNull(urlEntrySet.getValue().getUrl())) {
            LOGGER.warn("Validation fail for switch store configuration. Error: " + messageUtil.getAttributeNotNull("url of " + urlEntrySet.getKey()));
            throw new RequestValidationException(messageUtil.getAttributeNotNull(urlEntrySet.getKey()));
        } else if (ValidatorUtil.isNull(urlEntrySet.getValue().getMethodType())) {
            LOGGER.warn("Validation fail for switch store configuration. Error: " + messageUtil.getAttributeNotNull("method-type of " + urlEntrySet.getKey()));
            throw new RequestValidationException(messageUtil.getAttributeNotNull("method-type of " + urlEntrySet.getKey()));
        }
    }
}
Also used : OauthConfigEntity(org.openkilda.store.auth.dao.entity.OauthConfigEntity) UrlDto(org.openkilda.store.model.UrlDto) RequestValidationException(org.usermanagement.exception.RequestValidationException)

Example 13 with UrlDto

use of org.openkilda.store.model.UrlDto in project open-kilda by telstra.

the class FlowStoreService method getFlowById.

/**
 * Gets the flow by id.
 *
 * @param flowId the flow id
 * @return the flow by id
 */
public InventoryFlow getFlowById(final String flowId) {
    try {
        UrlDto urlDto = storeService.getUrl(StoreType.LINK_STORE, Url.GET_LINK);
        Map<String, String> params = new HashMap<String, String>();
        params.put(RequestParams.LINK_ID.getName(), flowId);
        urlDto.setParams(params);
        AuthConfigDto authDto = authService.getAuth(StoreType.LINK_STORE);
        IAuthService authService = IAuthService.getService(authDto.getAuthType());
        return authService.getResponse(urlDto, authDto, InventoryFlow.class);
    } catch (Exception e) {
        LOGGER.error("Error occurred while retriving flow by id: " + flowId, e);
        throw new StoreIntegrationException(e);
    }
}
Also used : UrlDto(org.openkilda.store.model.UrlDto) HashMap(java.util.HashMap) IAuthService(org.openkilda.integration.auth.service.IAuthService) StoreIntegrationException(org.openkilda.integration.exception.StoreIntegrationException) StoreIntegrationException(org.openkilda.integration.exception.StoreIntegrationException) AuthConfigDto(org.openkilda.store.model.AuthConfigDto)

Example 14 with UrlDto

use of org.openkilda.store.model.UrlDto in project open-kilda by telstra.

the class SwitchStoreService method getPortFlows.

/**
 * Gets the customer flows.
 *
 * @return the customer with flows
 */
public List<Customer> getPortFlows(String switchId, String port) {
    try {
        UrlDto urlDto = storeService.getUrl(StoreType.SWITCH_STORE, Url.GET_SWITCH_PORT_FLOWS);
        Map<String, String> params = new HashMap<String, String>();
        params.put(RequestParams.SWITCH_ID.getName(), switchId);
        params.put(RequestParams.PORT_NUMBER.getName(), port);
        urlDto.setParams(params);
        AuthConfigDto authDto = authService.getAuth(StoreType.SWITCH_STORE);
        IAuthService authService = IAuthService.getService(authDto.getAuthType());
        return authService.getResponseList(urlDto, authDto, Customer.class);
    } catch (Exception e) {
        LOGGER.error("Error occurred while retriving switch port flows. Switch Id: " + switchId + ", Port: " + port, e);
        throw new StoreIntegrationException(e);
    }
}
Also used : UrlDto(org.openkilda.store.model.UrlDto) HashMap(java.util.HashMap) IAuthService(org.openkilda.integration.auth.service.IAuthService) StoreIntegrationException(org.openkilda.integration.exception.StoreIntegrationException) StoreIntegrationException(org.openkilda.integration.exception.StoreIntegrationException) AuthConfigDto(org.openkilda.store.model.AuthConfigDto)

Example 15 with UrlDto

use of org.openkilda.store.model.UrlDto in project open-kilda by telstra.

the class StoreService method getLinkStoreConfig.

/**
 * Gets the link store config.
 *
 * @return the link store config
 */
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public LinkStoreConfigDto getLinkStoreConfig() {
    LOGGER.info("Get link store configuration");
    LinkStoreConfigDto linkStoreConfigDto = new LinkStoreConfigDto();
    List<LinkStoreRequestUrlsEntity> linkStoreRequestUrlsEntitiesList = linkStoreRequestUrlsRepository.findAll();
    Map<String, UrlDto> urls = new HashMap<String, UrlDto>();
    for (LinkStoreRequestUrlsEntity linkStoreRequestUrlsEntity : linkStoreRequestUrlsEntitiesList) {
        urls.put(linkStoreRequestUrlsEntity.getUrlEntity().getName(), UrlConverter.toUrlDto(linkStoreRequestUrlsEntity.getUrlEntity()));
    }
    linkStoreConfigDto.setUrls(urls);
    return linkStoreConfigDto;
}
Also used : UrlDto(org.openkilda.store.model.UrlDto) HashMap(java.util.HashMap) LinkStoreRequestUrlsEntity(org.openkilda.store.linkstore.dao.entity.LinkStoreRequestUrlsEntity) LinkStoreConfigDto(org.openkilda.store.model.LinkStoreConfigDto) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

UrlDto (org.openkilda.store.model.UrlDto)17 HashMap (java.util.HashMap)11 IAuthService (org.openkilda.integration.auth.service.IAuthService)9 StoreIntegrationException (org.openkilda.integration.exception.StoreIntegrationException)9 AuthConfigDto (org.openkilda.store.model.AuthConfigDto)9 Transactional (org.springframework.transaction.annotation.Transactional)5 LinkStoreRequestUrlsEntity (org.openkilda.store.linkstore.dao.entity.LinkStoreRequestUrlsEntity)3 SwitchStoreRequestUrlsEntity (org.openkilda.store.switchstore.dao.entity.SwitchStoreRequestUrlsEntity)3 ArrayList (java.util.ArrayList)2 OauthConfigEntity (org.openkilda.store.auth.dao.entity.OauthConfigEntity)2 RequestValidationException (org.usermanagement.exception.RequestValidationException)2 LinkStoreConfigDto (org.openkilda.store.model.LinkStoreConfigDto)1 SwitchStoreConfigDto (org.openkilda.store.model.SwitchStoreConfigDto)1