Search in sources :

Example 1 with LinkStoreRequestUrlsEntity

use of org.openkilda.store.linkstore.dao.entity.LinkStoreRequestUrlsEntity in project open-kilda by telstra.

the class StoreService method saveOrUpdateLinkStoreConfig.

/**
 * Save or update link store config.
 *
 * @param linkStoreConfigDto the link store config dto
 *
 * @return the link store config dto
 */
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public LinkStoreConfigDto saveOrUpdateLinkStoreConfig(final LinkStoreConfigDto linkStoreConfigDto) {
    LOGGER.info("Save or update link store configuration");
    saveOrUpdateStoreTypeEntity(StoreType.LINK_STORE.getCode());
    List<LinkStoreRequestUrlsEntity> linkStoreRequestUrlsEntitiesList = new ArrayList<LinkStoreRequestUrlsEntity>();
    List<LinkStoreRequestUrlsEntity> linkStoreRequestUrlsEntities = linkStoreRequestUrlsRepository.findAll();
    for (Entry<String, UrlDto> urlEntrySet : linkStoreConfigDto.getUrls().entrySet()) {
        if (linkStoreRequestUrlsEntities != null) {
            LinkStoreRequestUrlsEntity linkStoreRequestUrlsEntity = null;
            for (LinkStoreRequestUrlsEntity linkStoreRequestUrlsEntityObj : linkStoreRequestUrlsEntities) {
                if (linkStoreRequestUrlsEntityObj.getUrlEntity().getName().equalsIgnoreCase(urlEntrySet.getValue().getName())) {
                    linkStoreRequestUrlsEntity = linkStoreRequestUrlsEntityObj;
                    break;
                }
            }
            if (linkStoreRequestUrlsEntity == null) {
                linkStoreRequestUrlsEntity = new LinkStoreRequestUrlsEntity();
            }
            linkStoreRequestUrlsEntity.setUrlEntity(UrlConverter.toUrlEntity(urlEntrySet.getKey(), urlEntrySet.getValue(), linkStoreRequestUrlsEntity.getUrlEntity()));
            linkStoreRequestUrlsEntitiesList.add(linkStoreRequestUrlsEntity);
        }
    }
    linkStoreRequestUrlsEntitiesList = linkStoreRequestUrlsRepository.save(linkStoreRequestUrlsEntitiesList);
    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) ArrayList(java.util.ArrayList) LinkStoreRequestUrlsEntity(org.openkilda.store.linkstore.dao.entity.LinkStoreRequestUrlsEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with LinkStoreRequestUrlsEntity

use of org.openkilda.store.linkstore.dao.entity.LinkStoreRequestUrlsEntity 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)

Example 3 with LinkStoreRequestUrlsEntity

use of org.openkilda.store.linkstore.dao.entity.LinkStoreRequestUrlsEntity in project open-kilda by telstra.

the class StoreService method getUrl.

/**
 * Gets the url.
 *
 * @param storeType the store type
 *
 * @param url the url
 *
 * @return the url
 */
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public UrlDto getUrl(final StoreType storeType, final Url url) {
    LOGGER.info("Get urls for store type");
    UrlDto urlDto = null;
    if (storeType == StoreType.LINK_STORE) {
        LinkStoreRequestUrlsEntity urlsEntity = linkStoreRequestUrlsRepository.findByUrlEntity_name(url.getName());
        urlDto = UrlConverter.toUrlDto(urlsEntity.getUrlEntity());
    }
    if (storeType == StoreType.SWITCH_STORE) {
        SwitchStoreRequestUrlsEntity urlsEntity = switchStoreRequestUrlsRepository.findByUrlEntity_name(url.getName());
        urlDto = UrlConverter.toUrlDto(urlsEntity.getUrlEntity());
    }
    return urlDto;
}
Also used : UrlDto(org.openkilda.store.model.UrlDto) LinkStoreRequestUrlsEntity(org.openkilda.store.linkstore.dao.entity.LinkStoreRequestUrlsEntity) SwitchStoreRequestUrlsEntity(org.openkilda.store.switchstore.dao.entity.SwitchStoreRequestUrlsEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

LinkStoreRequestUrlsEntity (org.openkilda.store.linkstore.dao.entity.LinkStoreRequestUrlsEntity)3 UrlDto (org.openkilda.store.model.UrlDto)3 Transactional (org.springframework.transaction.annotation.Transactional)3 HashMap (java.util.HashMap)2 ArrayList (java.util.ArrayList)1 LinkStoreConfigDto (org.openkilda.store.model.LinkStoreConfigDto)1 SwitchStoreRequestUrlsEntity (org.openkilda.store.switchstore.dao.entity.SwitchStoreRequestUrlsEntity)1