Search in sources :

Example 81 with SneakyThrows

use of lombok.SneakyThrows in project UVMS-ActivityModule-APP by UnionVMS.

the class FishingTripDaoTest method testGetFishingTripIdsForMatchingFilterCriteria_allCommonFilters.

@Test
@SneakyThrows
public void testGetFishingTripIdsForMatchingFilterCriteria_allCommonFilters() throws Exception {
    dbSetupTracker.skipNextLaunch();
    Map<SearchFilter, String> searchCriteriaMap = new HashMap<>();
    searchCriteriaMap.put(SearchFilter.ACTIVITY_TYPE, "DEPARTURE");
    searchCriteriaMap.put(SearchFilter.SOURCE, "FLUX");
    searchCriteriaMap.put(SearchFilter.OWNER, "OWNER1");
    searchCriteriaMap.put(SearchFilter.FROM, "OWNER1");
    searchCriteriaMap.put(SearchFilter.PERIOD_START, "2012-05-27T07:47:31");
    searchCriteriaMap.put(SearchFilter.PERIOD_END, "2018-05-27T07:47:31");
    searchCriteriaMap.put(SearchFilter.REPORT_TYPE, "DECLARATION");
    searchCriteriaMap.put(SearchFilter.AREAS, "J");
    searchCriteriaMap.put(SearchFilter.GEAR, "GEAR_TYPE");
    searchCriteriaMap.put(SearchFilter.SPECIES, "BFT");
    searchCriteriaMap.put(SearchFilter.QUANTITY_MIN, "0");
    searchCriteriaMap.put(SearchFilter.QUANTITY_MAX, "50");
    searchCriteriaMap.put(SearchFilter.MASTER, "MARK");
    Map<SearchFilter, List<String>> searchCriteriaMapMultiVal = new HashMap<>();
    List<String> purposeCodeValues = new ArrayList<>();
    purposeCodeValues.add("9");
    purposeCodeValues.add("1");
    purposeCodeValues.add("5");
    purposeCodeValues.add("3");
    FishingActivityQuery query = new FishingActivityQuery();
    query.setSearchCriteriaMap(searchCriteriaMap);
    query.setSearchCriteriaMapMultipleValues(searchCriteriaMapMultiVal);
    searchCriteriaMapMultiVal.put(SearchFilter.PURPOSE, purposeCodeValues);
    Set<FishingTripId> fishingTripIdSet = dao.getFishingTripIdsForMatchingFilterCriteria(query);
    FishingTripId fishingTripId = new FishingTripId("NOR-TRP-20160517234053706", "EU_TRIP_ID");
    assertEquals(true, fishingTripIdSet.contains(fishingTripId));
    assertNotNull(fishingTripIdSet);
}
Also used : FishingActivityQuery(eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SearchFilter(eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter) ArrayList(java.util.ArrayList) List(java.util.List) FishingTripId(eu.europa.ec.fisheries.ers.service.search.FishingTripId) Test(org.junit.Test) SneakyThrows(lombok.SneakyThrows)

Example 82 with SneakyThrows

use of lombok.SneakyThrows in project UVMS-ActivityModule-APP by UnionVMS.

the class ActivityConfigServiceBean method saveUserConfig.

@Override
@SneakyThrows
public /**
 * {@inheritDoc}
 */
String saveUserConfig(ActivityConfigDTO updatedConfig, String userConfig) throws ServiceException {
    ActivityConfigDTO usmUserConfig = getConfiguration(userConfig);
    ActivityConfigDTO mergedConfig = PreferenceConfigMapper.INSTANCE.mergeUserPreference(usmUserConfig, updatedConfig);
    return getJson(mergedConfig);
}
Also used : ActivityConfigDTO(eu.europa.ec.fisheries.ers.service.dto.config.ActivityConfigDTO) SneakyThrows(lombok.SneakyThrows)

Example 83 with SneakyThrows

use of lombok.SneakyThrows in project UVMS-ActivityModule-APP by UnionVMS.

the class JacksonSubclassSerializerTest method testSerializing.

@SneakyThrows
@Test
public void testSerializing() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
    FishingActivityQuery fishQuery = new FishingActivityQuery();
    Map<SearchFilter, String> map = new HashMap<>();
    String val = "someVal";
    map.put(SearchFilter.VESSEL, val);
    fishQuery.setSearchCriteriaMap(map);
    String s = null;
    try {
        s = mapper.writeValueAsString(fishQuery);
    } catch (JsonProcessingException e) {
        e.printStackTrace();
    }
    System.out.println(s);
}
Also used : FishingActivityQuery(eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery) HashMap(java.util.HashMap) SearchFilter(eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) SneakyThrows(lombok.SneakyThrows)

Example 84 with SneakyThrows

use of lombok.SneakyThrows in project UVMS-ExchangeModule-APP by UnionVMS.

the class ExchangeLogModelTest method testDataEnrichment.

@Test
@SneakyThrows
public void testDataEnrichment() {
    Mockito.when(logDao.getExchangeLogListSearchCount(Mockito.anyString(), Mockito.anyList())).thenReturn(100L);
    Mockito.when(logDao.getExchangeLogListPaginated(Mockito.any(Integer.class), Mockito.any(Integer.class), Mockito.anyString(), Mockito.anyList())).thenReturn(logs);
    Mockito.when(logDao.getExchangeLogByRangeOfRefGuids(Mockito.anyList())).thenReturn(refLogs);
    ExchangeListQuery query = new ExchangeListQuery();
    ExchangeListPagination pagin = new ExchangeListPagination();
    ExchangeListCriteria exchCrit = new ExchangeListCriteria();
    query.setPagination(pagin);
    pagin.setListSize(10);
    query.setExchangeSearchCriteria(exchCrit);
    ListResponseDto exchangeLogListByQuery = exchangeLogModel.getExchangeLogListByQuery(query);
    List<ExchangeLogType> exchangeLogList = exchangeLogListByQuery.getExchangeLogList();
    ExchangeLogType exchangeLogType1 = exchangeLogList.get(0);
    ExchangeLogType exchangeLogType2 = exchangeLogList.get(1);
    assertTrue(exchangeLogType1.getRelatedLogData().isEmpty());
    assertTrue(!exchangeLogType2.getRelatedLogData().isEmpty());
    System.out.println("Done");
}
Also used : ExchangeListCriteria(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeListCriteria) ExchangeLogType(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogType) ExchangeListQuery(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeListQuery) ExchangeListPagination(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeListPagination) ListResponseDto(eu.europa.ec.fisheries.uvms.exchange.model.dto.ListResponseDto) Test(org.junit.Test) SneakyThrows(lombok.SneakyThrows)

Example 85 with SneakyThrows

use of lombok.SneakyThrows in project bookkeeper by apache.

the class ZKMetadataDriverBase method initialize.

@SneakyThrows(InterruptedException.class)
protected void initialize(AbstractConfiguration<?> conf, StatsLogger statsLogger, RetryPolicy zkRetryPolicy, Optional<Object> optionalCtx) throws MetadataException {
    this.conf = conf;
    this.acls = ZkUtils.getACLs(conf);
    if (optionalCtx.isPresent() && optionalCtx.get() instanceof ZooKeeper) {
        this.ledgersRootPath = conf.getZkLedgersRootPath();
        log.info("Initialize zookeeper metadata driver with external zookeeper client : ledgersRootPath = {}.", ledgersRootPath);
        // if an external zookeeper is added, use the zookeeper instance
        this.zk = (ZooKeeper) (optionalCtx.get());
        this.ownZKHandle = false;
    } else {
        final String metadataServiceUriStr;
        try {
            metadataServiceUriStr = conf.getMetadataServiceUri();
        } catch (ConfigurationException e) {
            log.error("Failed to retrieve metadata service uri from configuration", e);
            throw new MetadataException(Code.INVALID_METADATA_SERVICE_URI, e);
        }
        URI metadataServiceUri = URI.create(metadataServiceUriStr);
        // get the initialize root path
        this.ledgersRootPath = metadataServiceUri.getPath();
        final String bookieRegistrationPath = ledgersRootPath + "/" + AVAILABLE_NODE;
        final String bookieReadonlyRegistrationPath = bookieRegistrationPath + "/" + READONLY;
        // construct the zookeeper
        final String zkServers = getZKServersFromServiceUri(metadataServiceUri);
        log.info("Initialize zookeeper metadata driver at metadata service uri {} :" + " zkServers = {}, ledgersRootPath = {}.", metadataServiceUriStr, zkServers, ledgersRootPath);
        try {
            this.zk = ZooKeeperClient.newBuilder().connectString(zkServers).sessionTimeoutMs(conf.getZkTimeout()).operationRetryPolicy(zkRetryPolicy).requestRateLimit(conf.getZkRequestRateLimit()).statsLogger(statsLogger).build();
            if (null == zk.exists(bookieReadonlyRegistrationPath, false)) {
                try {
                    zk.create(bookieReadonlyRegistrationPath, EMPTY_BYTE_ARRAY, acls, CreateMode.PERSISTENT);
                } catch (KeeperException.NodeExistsException e) {
                // this node is just now created by someone.
                } catch (KeeperException.NoNodeException e) {
                // the cluster hasn't been initialized
                }
            }
        } catch (IOException | KeeperException e) {
            log.error("Failed to create zookeeper client to {}", zkServers, e);
            MetadataException me = new MetadataException(Code.METADATA_SERVICE_ERROR, "Failed to create zookeeper client to " + zkServers, e);
            me.fillInStackTrace();
            throw me;
        }
        this.ownZKHandle = true;
    }
    // once created the zookeeper client, create the layout manager and registration client
    this.layoutManager = new ZkLayoutManager(zk, ledgersRootPath, acls);
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) ConfigurationException(org.apache.commons.configuration.ConfigurationException) IOException(java.io.IOException) URI(java.net.URI) MetadataException(org.apache.bookkeeper.meta.exceptions.MetadataException) KeeperException(org.apache.zookeeper.KeeperException) ZkLayoutManager(org.apache.bookkeeper.meta.ZkLayoutManager) SneakyThrows(lombok.SneakyThrows)

Aggregations

SneakyThrows (lombok.SneakyThrows)706 lombok.val (lombok.val)314 Test (org.junit.Test)91 ArrayList (java.util.ArrayList)75 HashMap (java.util.HashMap)63 List (java.util.List)53 Cleanup (lombok.Cleanup)38 Map (java.util.Map)35 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)34 Collectors (java.util.stream.Collectors)34 LinkedHashMap (java.util.LinkedHashMap)30 File (java.io.File)28 Path (java.nio.file.Path)28 IOException (java.io.IOException)26 InputStream (java.io.InputStream)24 Slf4j (lombok.extern.slf4j.Slf4j)24 URL (java.net.URL)22 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)22 Collection (java.util.Collection)18 FishingActivityQuery (eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery)17