target
stringlengths
20
113k
src_fm
stringlengths
11
86.3k
src_fm_fc
stringlengths
21
86.4k
src_fm_fc_co
stringlengths
30
86.4k
src_fm_fc_ms
stringlengths
42
86.8k
src_fm_fc_ms_ff
stringlengths
43
86.8k
@Test public void shouldGetPartitionAddress() { assertThat(NamingUtils.getPartitionAddress("testAddress", 0)).isEqualTo("testAddress-0"); }
public static String getPartitionAddress(String address, int partition) { Objects.requireNonNull(address); return String.format("%s-%d", address, partition); }
NamingUtils { public static String getPartitionAddress(String address, int partition) { Objects.requireNonNull(address); return String.format("%s-%d", address, partition); } }
NamingUtils { public static String getPartitionAddress(String address, int partition) { Objects.requireNonNull(address); return String.format("%s-%d", address, partition); } }
NamingUtils { public static String getPartitionAddress(String address, int partition) { Objects.requireNonNull(address); return String.format("%s-%d", address, partition); } static String getPartitionAddress(String address, int partition); static String getQueueName(String address, String group); static String getAnonymousGroupName(); }
NamingUtils { public static String getPartitionAddress(String address, int partition) { Objects.requireNonNull(address); return String.format("%s-%d", address, partition); } static String getPartitionAddress(String address, int partition); static String getQueueName(String address, String group); static String getAnonymousGroupName(); }
@Test public void shouldGetNameForPartition() { String name = "test-name"; ArtemisProducerDestination destination = new ArtemisProducerDestination(name); assertThat(destination.getNameForPartition(0)).isEqualTo(getPartitionAddress(name, 0)); }
@Override public String getNameForPartition(int i) { return getPartitionAddress(name, i); }
ArtemisProducerDestination implements ProducerDestination { @Override public String getNameForPartition(int i) { return getPartitionAddress(name, i); } }
ArtemisProducerDestination implements ProducerDestination { @Override public String getNameForPartition(int i) { return getPartitionAddress(name, i); } ArtemisProducerDestination(String name); }
ArtemisProducerDestination implements ProducerDestination { @Override public String getNameForPartition(int i) { return getPartitionAddress(name, i); } ArtemisProducerDestination(String name); @Override String getName(); @Override String getNameForPartition(int i); @Override String toString(); }
ArtemisProducerDestination implements ProducerDestination { @Override public String getNameForPartition(int i) { return getPartitionAddress(name, i); } ArtemisProducerDestination(String name); @Override String getName(); @Override String getNameForPartition(int i); @Override String toString(); }
@Test public void shouldGetName() { String name = "test-name"; ArtemisConsumerDestination destination = new ArtemisConsumerDestination(name); assertThat(destination.getName()).isEqualTo(name); }
@Override public String getName() { return name; }
ArtemisConsumerDestination implements ConsumerDestination { @Override public String getName() { return name; } }
ArtemisConsumerDestination implements ConsumerDestination { @Override public String getName() { return name; } ArtemisConsumerDestination(String name); }
ArtemisConsumerDestination implements ConsumerDestination { @Override public String getName() { return name; } ArtemisConsumerDestination(String name); @Override String getName(); @Override String toString(); }
ArtemisConsumerDestination implements ConsumerDestination { @Override public String getName() { return name; } ArtemisConsumerDestination(String name); @Override String getName(); @Override String toString(); }
@Test public void shouldCreateAddress() throws Exception { ArtemisBrokerManager manager = new ArtemisBrokerManager(mockServerLocator, null, null); manager.createAddress(address.toString(), artemisCommonProperties); verify(mockServerLocator).createSessionFactory(); verify(mockClientSessionFactory).createSession(); verify(mockClientSession).start(); verify(mockClientSession).createAddress(address, MULTICAST, true); verify(mockClientSession).stop(); verify(mockClientSession, times(0)).queueQuery(any(SimpleString.class)); verify(mockClientSession, times(0)).createMessage(anyBoolean()); }
public void createAddress(String name, ArtemisCommonProperties properties) { logger.debug("Creating address '{}'", name); SimpleString nameString = SimpleString.toSimpleString(name); try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { session.start(); if (!session.addressQuery(nameString).isExists()) { session.createAddress(nameString, RoutingType.MULTICAST, true); if (properties.isModifyAddressSettings()) { configureAddress(session, name, properties); } } else { logger.debug("Address '{}' already exists, ignoring", name); } session.stop(); } catch (Exception e) { throw new ProvisioningException(String.format("Failed to create address '%s'", name), e); } }
ArtemisBrokerManager { public void createAddress(String name, ArtemisCommonProperties properties) { logger.debug("Creating address '{}'", name); SimpleString nameString = SimpleString.toSimpleString(name); try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { session.start(); if (!session.addressQuery(nameString).isExists()) { session.createAddress(nameString, RoutingType.MULTICAST, true); if (properties.isModifyAddressSettings()) { configureAddress(session, name, properties); } } else { logger.debug("Address '{}' already exists, ignoring", name); } session.stop(); } catch (Exception e) { throw new ProvisioningException(String.format("Failed to create address '%s'", name), e); } } }
ArtemisBrokerManager { public void createAddress(String name, ArtemisCommonProperties properties) { logger.debug("Creating address '{}'", name); SimpleString nameString = SimpleString.toSimpleString(name); try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { session.start(); if (!session.addressQuery(nameString).isExists()) { session.createAddress(nameString, RoutingType.MULTICAST, true); if (properties.isModifyAddressSettings()) { configureAddress(session, name, properties); } } else { logger.debug("Address '{}' already exists, ignoring", name); } session.stop(); } catch (Exception e) { throw new ProvisioningException(String.format("Failed to create address '%s'", name), e); } } ArtemisBrokerManager(ServerLocator serverLocator, String username, String password); }
ArtemisBrokerManager { public void createAddress(String name, ArtemisCommonProperties properties) { logger.debug("Creating address '{}'", name); SimpleString nameString = SimpleString.toSimpleString(name); try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { session.start(); if (!session.addressQuery(nameString).isExists()) { session.createAddress(nameString, RoutingType.MULTICAST, true); if (properties.isModifyAddressSettings()) { configureAddress(session, name, properties); } } else { logger.debug("Address '{}' already exists, ignoring", name); } session.stop(); } catch (Exception e) { throw new ProvisioningException(String.format("Failed to create address '%s'", name), e); } } ArtemisBrokerManager(ServerLocator serverLocator, String username, String password); void createAddress(String name, ArtemisCommonProperties properties); void createQueue(String address, String name); }
ArtemisBrokerManager { public void createAddress(String name, ArtemisCommonProperties properties) { logger.debug("Creating address '{}'", name); SimpleString nameString = SimpleString.toSimpleString(name); try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { session.start(); if (!session.addressQuery(nameString).isExists()) { session.createAddress(nameString, RoutingType.MULTICAST, true); if (properties.isModifyAddressSettings()) { configureAddress(session, name, properties); } } else { logger.debug("Address '{}' already exists, ignoring", name); } session.stop(); } catch (Exception e) { throw new ProvisioningException(String.format("Failed to create address '%s'", name), e); } } ArtemisBrokerManager(ServerLocator serverLocator, String username, String password); void createAddress(String name, ArtemisCommonProperties properties); void createQueue(String address, String name); }
@Test public void shouldCreateAddressWithCredentials() throws Exception { given(mockServerLocator.isPreAcknowledge()).willReturn(true); given(mockServerLocator.getAckBatchSize()).willReturn(1); ArtemisBrokerManager manager = new ArtemisBrokerManager(mockServerLocator, "user", "pass"); manager.createAddress(address.toString(), artemisCommonProperties); verify(mockServerLocator).createSessionFactory(); verify(mockClientSessionFactory).createSession("user", "pass", true, false, false, true, 1); verify(mockClientSession).start(); verify(mockClientSession).createAddress(address, MULTICAST, true); verify(mockClientSession).stop(); verify(mockClientSession, times(0)).queueQuery(any(SimpleString.class)); verify(mockClientSession, times(0)).createMessage(anyBoolean()); }
public void createAddress(String name, ArtemisCommonProperties properties) { logger.debug("Creating address '{}'", name); SimpleString nameString = SimpleString.toSimpleString(name); try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { session.start(); if (!session.addressQuery(nameString).isExists()) { session.createAddress(nameString, RoutingType.MULTICAST, true); if (properties.isModifyAddressSettings()) { configureAddress(session, name, properties); } } else { logger.debug("Address '{}' already exists, ignoring", name); } session.stop(); } catch (Exception e) { throw new ProvisioningException(String.format("Failed to create address '%s'", name), e); } }
ArtemisBrokerManager { public void createAddress(String name, ArtemisCommonProperties properties) { logger.debug("Creating address '{}'", name); SimpleString nameString = SimpleString.toSimpleString(name); try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { session.start(); if (!session.addressQuery(nameString).isExists()) { session.createAddress(nameString, RoutingType.MULTICAST, true); if (properties.isModifyAddressSettings()) { configureAddress(session, name, properties); } } else { logger.debug("Address '{}' already exists, ignoring", name); } session.stop(); } catch (Exception e) { throw new ProvisioningException(String.format("Failed to create address '%s'", name), e); } } }
ArtemisBrokerManager { public void createAddress(String name, ArtemisCommonProperties properties) { logger.debug("Creating address '{}'", name); SimpleString nameString = SimpleString.toSimpleString(name); try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { session.start(); if (!session.addressQuery(nameString).isExists()) { session.createAddress(nameString, RoutingType.MULTICAST, true); if (properties.isModifyAddressSettings()) { configureAddress(session, name, properties); } } else { logger.debug("Address '{}' already exists, ignoring", name); } session.stop(); } catch (Exception e) { throw new ProvisioningException(String.format("Failed to create address '%s'", name), e); } } ArtemisBrokerManager(ServerLocator serverLocator, String username, String password); }
ArtemisBrokerManager { public void createAddress(String name, ArtemisCommonProperties properties) { logger.debug("Creating address '{}'", name); SimpleString nameString = SimpleString.toSimpleString(name); try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { session.start(); if (!session.addressQuery(nameString).isExists()) { session.createAddress(nameString, RoutingType.MULTICAST, true); if (properties.isModifyAddressSettings()) { configureAddress(session, name, properties); } } else { logger.debug("Address '{}' already exists, ignoring", name); } session.stop(); } catch (Exception e) { throw new ProvisioningException(String.format("Failed to create address '%s'", name), e); } } ArtemisBrokerManager(ServerLocator serverLocator, String username, String password); void createAddress(String name, ArtemisCommonProperties properties); void createQueue(String address, String name); }
ArtemisBrokerManager { public void createAddress(String name, ArtemisCommonProperties properties) { logger.debug("Creating address '{}'", name); SimpleString nameString = SimpleString.toSimpleString(name); try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { session.start(); if (!session.addressQuery(nameString).isExists()) { session.createAddress(nameString, RoutingType.MULTICAST, true); if (properties.isModifyAddressSettings()) { configureAddress(session, name, properties); } } else { logger.debug("Address '{}' already exists, ignoring", name); } session.stop(); } catch (Exception e) { throw new ProvisioningException(String.format("Failed to create address '%s'", name), e); } } ArtemisBrokerManager(ServerLocator serverLocator, String username, String password); void createAddress(String name, ArtemisCommonProperties properties); void createQueue(String address, String name); }
@Test public void shouldNotCreateAddressIfOneExists() throws Exception { given(mockAddressQuery.isExists()).willReturn(true); ArtemisBrokerManager manager = new ArtemisBrokerManager(mockServerLocator, null, null); manager.createAddress(address.toString(), artemisCommonProperties); verify(mockServerLocator).createSessionFactory(); verify(mockClientSessionFactory).createSession(); verify(mockClientSession).start(); verify(mockClientSession).stop(); verify(mockClientSession, times(0)).createAddress(any(), any(RoutingType.class), anyBoolean()); verify(mockClientSession, times(0)).queueQuery(any(SimpleString.class)); verify(mockClientSession, times(0)).createMessage(anyBoolean()); }
public void createAddress(String name, ArtemisCommonProperties properties) { logger.debug("Creating address '{}'", name); SimpleString nameString = SimpleString.toSimpleString(name); try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { session.start(); if (!session.addressQuery(nameString).isExists()) { session.createAddress(nameString, RoutingType.MULTICAST, true); if (properties.isModifyAddressSettings()) { configureAddress(session, name, properties); } } else { logger.debug("Address '{}' already exists, ignoring", name); } session.stop(); } catch (Exception e) { throw new ProvisioningException(String.format("Failed to create address '%s'", name), e); } }
ArtemisBrokerManager { public void createAddress(String name, ArtemisCommonProperties properties) { logger.debug("Creating address '{}'", name); SimpleString nameString = SimpleString.toSimpleString(name); try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { session.start(); if (!session.addressQuery(nameString).isExists()) { session.createAddress(nameString, RoutingType.MULTICAST, true); if (properties.isModifyAddressSettings()) { configureAddress(session, name, properties); } } else { logger.debug("Address '{}' already exists, ignoring", name); } session.stop(); } catch (Exception e) { throw new ProvisioningException(String.format("Failed to create address '%s'", name), e); } } }
ArtemisBrokerManager { public void createAddress(String name, ArtemisCommonProperties properties) { logger.debug("Creating address '{}'", name); SimpleString nameString = SimpleString.toSimpleString(name); try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { session.start(); if (!session.addressQuery(nameString).isExists()) { session.createAddress(nameString, RoutingType.MULTICAST, true); if (properties.isModifyAddressSettings()) { configureAddress(session, name, properties); } } else { logger.debug("Address '{}' already exists, ignoring", name); } session.stop(); } catch (Exception e) { throw new ProvisioningException(String.format("Failed to create address '%s'", name), e); } } ArtemisBrokerManager(ServerLocator serverLocator, String username, String password); }
ArtemisBrokerManager { public void createAddress(String name, ArtemisCommonProperties properties) { logger.debug("Creating address '{}'", name); SimpleString nameString = SimpleString.toSimpleString(name); try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { session.start(); if (!session.addressQuery(nameString).isExists()) { session.createAddress(nameString, RoutingType.MULTICAST, true); if (properties.isModifyAddressSettings()) { configureAddress(session, name, properties); } } else { logger.debug("Address '{}' already exists, ignoring", name); } session.stop(); } catch (Exception e) { throw new ProvisioningException(String.format("Failed to create address '%s'", name), e); } } ArtemisBrokerManager(ServerLocator serverLocator, String username, String password); void createAddress(String name, ArtemisCommonProperties properties); void createQueue(String address, String name); }
ArtemisBrokerManager { public void createAddress(String name, ArtemisCommonProperties properties) { logger.debug("Creating address '{}'", name); SimpleString nameString = SimpleString.toSimpleString(name); try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { session.start(); if (!session.addressQuery(nameString).isExists()) { session.createAddress(nameString, RoutingType.MULTICAST, true); if (properties.isModifyAddressSettings()) { configureAddress(session, name, properties); } } else { logger.debug("Address '{}' already exists, ignoring", name); } session.stop(); } catch (Exception e) { throw new ProvisioningException(String.format("Failed to create address '%s'", name), e); } } ArtemisBrokerManager(ServerLocator serverLocator, String username, String password); void createAddress(String name, ArtemisCommonProperties properties); void createQueue(String address, String name); }
@Test public void shouldFailToCreateAddress() throws Exception { given(mockServerLocator.createSessionFactory()).willThrow(new RuntimeException("test")); ArtemisBrokerManager manager = new ArtemisBrokerManager(mockServerLocator, null, null); try { manager.createAddress(address.toString(), artemisCommonProperties); fail("Provisioning exception was expected"); } catch (ProvisioningException e) { String message = String.format("Failed to create address '%s'", address); assertThat(e.getMessage()).contains(message); } }
public void createAddress(String name, ArtemisCommonProperties properties) { logger.debug("Creating address '{}'", name); SimpleString nameString = SimpleString.toSimpleString(name); try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { session.start(); if (!session.addressQuery(nameString).isExists()) { session.createAddress(nameString, RoutingType.MULTICAST, true); if (properties.isModifyAddressSettings()) { configureAddress(session, name, properties); } } else { logger.debug("Address '{}' already exists, ignoring", name); } session.stop(); } catch (Exception e) { throw new ProvisioningException(String.format("Failed to create address '%s'", name), e); } }
ArtemisBrokerManager { public void createAddress(String name, ArtemisCommonProperties properties) { logger.debug("Creating address '{}'", name); SimpleString nameString = SimpleString.toSimpleString(name); try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { session.start(); if (!session.addressQuery(nameString).isExists()) { session.createAddress(nameString, RoutingType.MULTICAST, true); if (properties.isModifyAddressSettings()) { configureAddress(session, name, properties); } } else { logger.debug("Address '{}' already exists, ignoring", name); } session.stop(); } catch (Exception e) { throw new ProvisioningException(String.format("Failed to create address '%s'", name), e); } } }
ArtemisBrokerManager { public void createAddress(String name, ArtemisCommonProperties properties) { logger.debug("Creating address '{}'", name); SimpleString nameString = SimpleString.toSimpleString(name); try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { session.start(); if (!session.addressQuery(nameString).isExists()) { session.createAddress(nameString, RoutingType.MULTICAST, true); if (properties.isModifyAddressSettings()) { configureAddress(session, name, properties); } } else { logger.debug("Address '{}' already exists, ignoring", name); } session.stop(); } catch (Exception e) { throw new ProvisioningException(String.format("Failed to create address '%s'", name), e); } } ArtemisBrokerManager(ServerLocator serverLocator, String username, String password); }
ArtemisBrokerManager { public void createAddress(String name, ArtemisCommonProperties properties) { logger.debug("Creating address '{}'", name); SimpleString nameString = SimpleString.toSimpleString(name); try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { session.start(); if (!session.addressQuery(nameString).isExists()) { session.createAddress(nameString, RoutingType.MULTICAST, true); if (properties.isModifyAddressSettings()) { configureAddress(session, name, properties); } } else { logger.debug("Address '{}' already exists, ignoring", name); } session.stop(); } catch (Exception e) { throw new ProvisioningException(String.format("Failed to create address '%s'", name), e); } } ArtemisBrokerManager(ServerLocator serverLocator, String username, String password); void createAddress(String name, ArtemisCommonProperties properties); void createQueue(String address, String name); }
ArtemisBrokerManager { public void createAddress(String name, ArtemisCommonProperties properties) { logger.debug("Creating address '{}'", name); SimpleString nameString = SimpleString.toSimpleString(name); try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { session.start(); if (!session.addressQuery(nameString).isExists()) { session.createAddress(nameString, RoutingType.MULTICAST, true); if (properties.isModifyAddressSettings()) { configureAddress(session, name, properties); } } else { logger.debug("Address '{}' already exists, ignoring", name); } session.stop(); } catch (Exception e) { throw new ProvisioningException(String.format("Failed to create address '%s'", name), e); } } ArtemisBrokerManager(ServerLocator serverLocator, String username, String password); void createAddress(String name, ArtemisCommonProperties properties); void createQueue(String address, String name); }
@Test public void shouldCreateQueue() throws Exception { ArtemisBrokerManager manager = new ArtemisBrokerManager(mockServerLocator, null, null); manager.createQueue(address.toString(), queue.toString()); verify(mockServerLocator).createSessionFactory(); verify(mockClientSessionFactory).createSession(); verify(mockClientSession).createSharedQueue(address, MULTICAST, queue, true); }
public void createQueue(String address, String name) { try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { createQueueInternal(session, address, name); } catch (ProvisioningException e) { throw e; } catch (Exception e) { throw new ProvisioningException( String.format("Failed to create queue '%s' with address '%s'", name, address), e); } }
ArtemisBrokerManager { public void createQueue(String address, String name) { try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { createQueueInternal(session, address, name); } catch (ProvisioningException e) { throw e; } catch (Exception e) { throw new ProvisioningException( String.format("Failed to create queue '%s' with address '%s'", name, address), e); } } }
ArtemisBrokerManager { public void createQueue(String address, String name) { try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { createQueueInternal(session, address, name); } catch (ProvisioningException e) { throw e; } catch (Exception e) { throw new ProvisioningException( String.format("Failed to create queue '%s' with address '%s'", name, address), e); } } ArtemisBrokerManager(ServerLocator serverLocator, String username, String password); }
ArtemisBrokerManager { public void createQueue(String address, String name) { try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { createQueueInternal(session, address, name); } catch (ProvisioningException e) { throw e; } catch (Exception e) { throw new ProvisioningException( String.format("Failed to create queue '%s' with address '%s'", name, address), e); } } ArtemisBrokerManager(ServerLocator serverLocator, String username, String password); void createAddress(String name, ArtemisCommonProperties properties); void createQueue(String address, String name); }
ArtemisBrokerManager { public void createQueue(String address, String name) { try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { createQueueInternal(session, address, name); } catch (ProvisioningException e) { throw e; } catch (Exception e) { throw new ProvisioningException( String.format("Failed to create queue '%s' with address '%s'", name, address), e); } } ArtemisBrokerManager(ServerLocator serverLocator, String username, String password); void createAddress(String name, ArtemisCommonProperties properties); void createQueue(String address, String name); }
@Test public void shouldCreateQueueWithCredentials() throws Exception { given(mockServerLocator.isPreAcknowledge()).willReturn(true); given(mockServerLocator.getAckBatchSize()).willReturn(1); ArtemisBrokerManager manager = new ArtemisBrokerManager(mockServerLocator, "user", "pass"); manager.createQueue(address.toString(), queue.toString()); verify(mockServerLocator).createSessionFactory(); verify(mockClientSessionFactory).createSession("user", "pass", true, false, false, true, 1); verify(mockClientSession).createSharedQueue(address, MULTICAST, queue, true); }
public void createQueue(String address, String name) { try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { createQueueInternal(session, address, name); } catch (ProvisioningException e) { throw e; } catch (Exception e) { throw new ProvisioningException( String.format("Failed to create queue '%s' with address '%s'", name, address), e); } }
ArtemisBrokerManager { public void createQueue(String address, String name) { try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { createQueueInternal(session, address, name); } catch (ProvisioningException e) { throw e; } catch (Exception e) { throw new ProvisioningException( String.format("Failed to create queue '%s' with address '%s'", name, address), e); } } }
ArtemisBrokerManager { public void createQueue(String address, String name) { try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { createQueueInternal(session, address, name); } catch (ProvisioningException e) { throw e; } catch (Exception e) { throw new ProvisioningException( String.format("Failed to create queue '%s' with address '%s'", name, address), e); } } ArtemisBrokerManager(ServerLocator serverLocator, String username, String password); }
ArtemisBrokerManager { public void createQueue(String address, String name) { try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { createQueueInternal(session, address, name); } catch (ProvisioningException e) { throw e; } catch (Exception e) { throw new ProvisioningException( String.format("Failed to create queue '%s' with address '%s'", name, address), e); } } ArtemisBrokerManager(ServerLocator serverLocator, String username, String password); void createAddress(String name, ArtemisCommonProperties properties); void createQueue(String address, String name); }
ArtemisBrokerManager { public void createQueue(String address, String name) { try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { createQueueInternal(session, address, name); } catch (ProvisioningException e) { throw e; } catch (Exception e) { throw new ProvisioningException( String.format("Failed to create queue '%s' with address '%s'", name, address), e); } } ArtemisBrokerManager(ServerLocator serverLocator, String username, String password); void createAddress(String name, ArtemisCommonProperties properties); void createQueue(String address, String name); }
@Test public void shouldNotCreateQueueIfOneAlreadyExists() throws Exception { given(mockQueueQuery.getAddress()).willReturn(address); given(mockQueueQuery.isExists()).willReturn(true); ArtemisBrokerManager manager = new ArtemisBrokerManager(mockServerLocator, null, null); manager.createQueue(address.toString(), queue.toString()); verify(mockServerLocator).createSessionFactory(); verify(mockClientSessionFactory).createSession(); verify(mockClientSession, times(0)).createSharedQueue(any(), any(RoutingType.class), any(), anyBoolean()); }
public void createQueue(String address, String name) { try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { createQueueInternal(session, address, name); } catch (ProvisioningException e) { throw e; } catch (Exception e) { throw new ProvisioningException( String.format("Failed to create queue '%s' with address '%s'", name, address), e); } }
ArtemisBrokerManager { public void createQueue(String address, String name) { try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { createQueueInternal(session, address, name); } catch (ProvisioningException e) { throw e; } catch (Exception e) { throw new ProvisioningException( String.format("Failed to create queue '%s' with address '%s'", name, address), e); } } }
ArtemisBrokerManager { public void createQueue(String address, String name) { try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { createQueueInternal(session, address, name); } catch (ProvisioningException e) { throw e; } catch (Exception e) { throw new ProvisioningException( String.format("Failed to create queue '%s' with address '%s'", name, address), e); } } ArtemisBrokerManager(ServerLocator serverLocator, String username, String password); }
ArtemisBrokerManager { public void createQueue(String address, String name) { try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { createQueueInternal(session, address, name); } catch (ProvisioningException e) { throw e; } catch (Exception e) { throw new ProvisioningException( String.format("Failed to create queue '%s' with address '%s'", name, address), e); } } ArtemisBrokerManager(ServerLocator serverLocator, String username, String password); void createAddress(String name, ArtemisCommonProperties properties); void createQueue(String address, String name); }
ArtemisBrokerManager { public void createQueue(String address, String name) { try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { createQueueInternal(session, address, name); } catch (ProvisioningException e) { throw e; } catch (Exception e) { throw new ProvisioningException( String.format("Failed to create queue '%s' with address '%s'", name, address), e); } } ArtemisBrokerManager(ServerLocator serverLocator, String username, String password); void createAddress(String name, ArtemisCommonProperties properties); void createQueue(String address, String name); }
@Test public void shouldFailToCreateQueue() throws Exception { given(mockServerLocator.createSessionFactory()).willThrow(new RuntimeException("test")); ArtemisBrokerManager manager = new ArtemisBrokerManager(mockServerLocator, null, null); try { manager.createQueue(address.toString(), queue.toString()); fail("Provisioning exception was expected"); } catch (ProvisioningException e) { String message = String.format("Failed to create queue '%s' with address '%s'", queue, address); assertThat(e.getMessage()).contains(message); } }
public void createQueue(String address, String name) { try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { createQueueInternal(session, address, name); } catch (ProvisioningException e) { throw e; } catch (Exception e) { throw new ProvisioningException( String.format("Failed to create queue '%s' with address '%s'", name, address), e); } }
ArtemisBrokerManager { public void createQueue(String address, String name) { try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { createQueueInternal(session, address, name); } catch (ProvisioningException e) { throw e; } catch (Exception e) { throw new ProvisioningException( String.format("Failed to create queue '%s' with address '%s'", name, address), e); } } }
ArtemisBrokerManager { public void createQueue(String address, String name) { try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { createQueueInternal(session, address, name); } catch (ProvisioningException e) { throw e; } catch (Exception e) { throw new ProvisioningException( String.format("Failed to create queue '%s' with address '%s'", name, address), e); } } ArtemisBrokerManager(ServerLocator serverLocator, String username, String password); }
ArtemisBrokerManager { public void createQueue(String address, String name) { try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { createQueueInternal(session, address, name); } catch (ProvisioningException e) { throw e; } catch (Exception e) { throw new ProvisioningException( String.format("Failed to create queue '%s' with address '%s'", name, address), e); } } ArtemisBrokerManager(ServerLocator serverLocator, String username, String password); void createAddress(String name, ArtemisCommonProperties properties); void createQueue(String address, String name); }
ArtemisBrokerManager { public void createQueue(String address, String name) { try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { createQueueInternal(session, address, name); } catch (ProvisioningException e) { throw e; } catch (Exception e) { throw new ProvisioningException( String.format("Failed to create queue '%s' with address '%s'", name, address), e); } } ArtemisBrokerManager(ServerLocator serverLocator, String username, String password); void createAddress(String name, ArtemisCommonProperties properties); void createQueue(String address, String name); }
@Test(expected = NullPointerException.class) public void shouldNotAcceptNullAddressToGetPartitionAddress() { NamingUtils.getPartitionAddress(null, 0); }
public static String getPartitionAddress(String address, int partition) { Objects.requireNonNull(address); return String.format("%s-%d", address, partition); }
NamingUtils { public static String getPartitionAddress(String address, int partition) { Objects.requireNonNull(address); return String.format("%s-%d", address, partition); } }
NamingUtils { public static String getPartitionAddress(String address, int partition) { Objects.requireNonNull(address); return String.format("%s-%d", address, partition); } }
NamingUtils { public static String getPartitionAddress(String address, int partition) { Objects.requireNonNull(address); return String.format("%s-%d", address, partition); } static String getPartitionAddress(String address, int partition); static String getQueueName(String address, String group); static String getAnonymousGroupName(); }
NamingUtils { public static String getPartitionAddress(String address, int partition) { Objects.requireNonNull(address); return String.format("%s-%d", address, partition); } static String getPartitionAddress(String address, int partition); static String getQueueName(String address, String group); static String getAnonymousGroupName(); }
@Test public void shouldFailToCreateQueueIfOneAlreadyExistsUnderAnotherAddress() { SimpleString anotherAddress = toSimpleString("another-address-name"); given(mockQueueQuery.getAddress()).willReturn(anotherAddress); given(mockQueueQuery.isExists()).willReturn(true); ArtemisBrokerManager manager = new ArtemisBrokerManager(mockServerLocator, null, null); try { manager.createQueue(address.toString(), queue.toString()); fail("Provisioning exception was expected"); } catch (ProvisioningException e) { String message = String.format( "Failed to create queue '%s' with address '%s'. Queue already exists under another address '%s'", queue, address, anotherAddress); assertThat(e.getMessage()).contains(message); } }
public void createQueue(String address, String name) { try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { createQueueInternal(session, address, name); } catch (ProvisioningException e) { throw e; } catch (Exception e) { throw new ProvisioningException( String.format("Failed to create queue '%s' with address '%s'", name, address), e); } }
ArtemisBrokerManager { public void createQueue(String address, String name) { try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { createQueueInternal(session, address, name); } catch (ProvisioningException e) { throw e; } catch (Exception e) { throw new ProvisioningException( String.format("Failed to create queue '%s' with address '%s'", name, address), e); } } }
ArtemisBrokerManager { public void createQueue(String address, String name) { try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { createQueueInternal(session, address, name); } catch (ProvisioningException e) { throw e; } catch (Exception e) { throw new ProvisioningException( String.format("Failed to create queue '%s' with address '%s'", name, address), e); } } ArtemisBrokerManager(ServerLocator serverLocator, String username, String password); }
ArtemisBrokerManager { public void createQueue(String address, String name) { try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { createQueueInternal(session, address, name); } catch (ProvisioningException e) { throw e; } catch (Exception e) { throw new ProvisioningException( String.format("Failed to create queue '%s' with address '%s'", name, address), e); } } ArtemisBrokerManager(ServerLocator serverLocator, String username, String password); void createAddress(String name, ArtemisCommonProperties properties); void createQueue(String address, String name); }
ArtemisBrokerManager { public void createQueue(String address, String name) { try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { createQueueInternal(session, address, name); } catch (ProvisioningException e) { throw e; } catch (Exception e) { throw new ProvisioningException( String.format("Failed to create queue '%s' with address '%s'", name, address), e); } } ArtemisBrokerManager(ServerLocator serverLocator, String username, String password); void createAddress(String name, ArtemisCommonProperties properties); void createQueue(String address, String name); }
@Test public void shouldProvisionUnpartitionedProducer() { ProducerDestination destination = provider.provisionProducerDestination(address, mockProducerProperties); assertThat(destination).isInstanceOf(ArtemisProducerDestination.class); assertThat(destination.getName()).isEqualTo(address); verify(mockArtemisBrokerManager).createAddress(address, mockArtemisProducerProperties); verify(mockArtemisBrokerManager, times(0)).createQueue(anyString(), anyString()); }
@Override public ProducerDestination provisionProducerDestination(String address, ExtendedProducerProperties<ArtemisProducerProperties> properties) throws ProvisioningException { if (properties.isPartitioned()) { return provisionPartitionedProducerDestination(address, properties); } return provisionUnpartitionedProducerDestination(address, properties); }
ArtemisProvisioningProvider implements ProvisioningProvider< ExtendedConsumerProperties<ArtemisConsumerProperties>, ExtendedProducerProperties<ArtemisProducerProperties>> { @Override public ProducerDestination provisionProducerDestination(String address, ExtendedProducerProperties<ArtemisProducerProperties> properties) throws ProvisioningException { if (properties.isPartitioned()) { return provisionPartitionedProducerDestination(address, properties); } return provisionUnpartitionedProducerDestination(address, properties); } }
ArtemisProvisioningProvider implements ProvisioningProvider< ExtendedConsumerProperties<ArtemisConsumerProperties>, ExtendedProducerProperties<ArtemisProducerProperties>> { @Override public ProducerDestination provisionProducerDestination(String address, ExtendedProducerProperties<ArtemisProducerProperties> properties) throws ProvisioningException { if (properties.isPartitioned()) { return provisionPartitionedProducerDestination(address, properties); } return provisionUnpartitionedProducerDestination(address, properties); } ArtemisProvisioningProvider(ArtemisBrokerManager artemisBrokerManager); }
ArtemisProvisioningProvider implements ProvisioningProvider< ExtendedConsumerProperties<ArtemisConsumerProperties>, ExtendedProducerProperties<ArtemisProducerProperties>> { @Override public ProducerDestination provisionProducerDestination(String address, ExtendedProducerProperties<ArtemisProducerProperties> properties) throws ProvisioningException { if (properties.isPartitioned()) { return provisionPartitionedProducerDestination(address, properties); } return provisionUnpartitionedProducerDestination(address, properties); } ArtemisProvisioningProvider(ArtemisBrokerManager artemisBrokerManager); @Override ProducerDestination provisionProducerDestination(String address, ExtendedProducerProperties<ArtemisProducerProperties> properties); @Override ConsumerDestination provisionConsumerDestination(String address, String group, ExtendedConsumerProperties<ArtemisConsumerProperties> properties); }
ArtemisProvisioningProvider implements ProvisioningProvider< ExtendedConsumerProperties<ArtemisConsumerProperties>, ExtendedProducerProperties<ArtemisProducerProperties>> { @Override public ProducerDestination provisionProducerDestination(String address, ExtendedProducerProperties<ArtemisProducerProperties> properties) throws ProvisioningException { if (properties.isPartitioned()) { return provisionPartitionedProducerDestination(address, properties); } return provisionUnpartitionedProducerDestination(address, properties); } ArtemisProvisioningProvider(ArtemisBrokerManager artemisBrokerManager); @Override ProducerDestination provisionProducerDestination(String address, ExtendedProducerProperties<ArtemisProducerProperties> properties); @Override ConsumerDestination provisionConsumerDestination(String address, String group, ExtendedConsumerProperties<ArtemisConsumerProperties> properties); }
@Test public void shouldProvisionUnpartitionedProducerWithRequiredGroups() { given(mockProducerProperties.getRequiredGroups()).willReturn(groups); ProducerDestination destination = provider.provisionProducerDestination(address, mockProducerProperties); assertThat(destination).isInstanceOf(ArtemisProducerDestination.class); assertThat(destination.getName()).isEqualTo(address); verify(mockArtemisBrokerManager).createAddress(address, mockArtemisProducerProperties); verify(mockArtemisBrokerManager).createQueue(address, getQueueName(address, groups[0])); verify(mockArtemisBrokerManager).createQueue(address, getQueueName(address, groups[1])); }
@Override public ProducerDestination provisionProducerDestination(String address, ExtendedProducerProperties<ArtemisProducerProperties> properties) throws ProvisioningException { if (properties.isPartitioned()) { return provisionPartitionedProducerDestination(address, properties); } return provisionUnpartitionedProducerDestination(address, properties); }
ArtemisProvisioningProvider implements ProvisioningProvider< ExtendedConsumerProperties<ArtemisConsumerProperties>, ExtendedProducerProperties<ArtemisProducerProperties>> { @Override public ProducerDestination provisionProducerDestination(String address, ExtendedProducerProperties<ArtemisProducerProperties> properties) throws ProvisioningException { if (properties.isPartitioned()) { return provisionPartitionedProducerDestination(address, properties); } return provisionUnpartitionedProducerDestination(address, properties); } }
ArtemisProvisioningProvider implements ProvisioningProvider< ExtendedConsumerProperties<ArtemisConsumerProperties>, ExtendedProducerProperties<ArtemisProducerProperties>> { @Override public ProducerDestination provisionProducerDestination(String address, ExtendedProducerProperties<ArtemisProducerProperties> properties) throws ProvisioningException { if (properties.isPartitioned()) { return provisionPartitionedProducerDestination(address, properties); } return provisionUnpartitionedProducerDestination(address, properties); } ArtemisProvisioningProvider(ArtemisBrokerManager artemisBrokerManager); }
ArtemisProvisioningProvider implements ProvisioningProvider< ExtendedConsumerProperties<ArtemisConsumerProperties>, ExtendedProducerProperties<ArtemisProducerProperties>> { @Override public ProducerDestination provisionProducerDestination(String address, ExtendedProducerProperties<ArtemisProducerProperties> properties) throws ProvisioningException { if (properties.isPartitioned()) { return provisionPartitionedProducerDestination(address, properties); } return provisionUnpartitionedProducerDestination(address, properties); } ArtemisProvisioningProvider(ArtemisBrokerManager artemisBrokerManager); @Override ProducerDestination provisionProducerDestination(String address, ExtendedProducerProperties<ArtemisProducerProperties> properties); @Override ConsumerDestination provisionConsumerDestination(String address, String group, ExtendedConsumerProperties<ArtemisConsumerProperties> properties); }
ArtemisProvisioningProvider implements ProvisioningProvider< ExtendedConsumerProperties<ArtemisConsumerProperties>, ExtendedProducerProperties<ArtemisProducerProperties>> { @Override public ProducerDestination provisionProducerDestination(String address, ExtendedProducerProperties<ArtemisProducerProperties> properties) throws ProvisioningException { if (properties.isPartitioned()) { return provisionPartitionedProducerDestination(address, properties); } return provisionUnpartitionedProducerDestination(address, properties); } ArtemisProvisioningProvider(ArtemisBrokerManager artemisBrokerManager); @Override ProducerDestination provisionProducerDestination(String address, ExtendedProducerProperties<ArtemisProducerProperties> properties); @Override ConsumerDestination provisionConsumerDestination(String address, String group, ExtendedConsumerProperties<ArtemisConsumerProperties> properties); }
@Test public void shouldProvisionPartitionedProducer() { String partitionedAddress0 = String.format("%s-0", address); String partitionedAddress1 = String.format("%s-1", address); given(mockProducerProperties.isPartitioned()).willReturn(true); given(mockProducerProperties.getPartitionCount()).willReturn(2); ProducerDestination destination = provider.provisionProducerDestination(address, mockProducerProperties); assertThat(destination).isInstanceOf(ArtemisProducerDestination.class); assertThat(destination.getNameForPartition(0)).isEqualTo(partitionedAddress0); assertThat(destination.getNameForPartition(1)).isEqualTo(partitionedAddress1); verify(mockArtemisBrokerManager).createAddress(partitionedAddress0, mockArtemisProducerProperties); verify(mockArtemisBrokerManager).createAddress(partitionedAddress1, mockArtemisProducerProperties); verify(mockArtemisBrokerManager, times(0)).createQueue(anyString(), anyString()); }
@Override public ProducerDestination provisionProducerDestination(String address, ExtendedProducerProperties<ArtemisProducerProperties> properties) throws ProvisioningException { if (properties.isPartitioned()) { return provisionPartitionedProducerDestination(address, properties); } return provisionUnpartitionedProducerDestination(address, properties); }
ArtemisProvisioningProvider implements ProvisioningProvider< ExtendedConsumerProperties<ArtemisConsumerProperties>, ExtendedProducerProperties<ArtemisProducerProperties>> { @Override public ProducerDestination provisionProducerDestination(String address, ExtendedProducerProperties<ArtemisProducerProperties> properties) throws ProvisioningException { if (properties.isPartitioned()) { return provisionPartitionedProducerDestination(address, properties); } return provisionUnpartitionedProducerDestination(address, properties); } }
ArtemisProvisioningProvider implements ProvisioningProvider< ExtendedConsumerProperties<ArtemisConsumerProperties>, ExtendedProducerProperties<ArtemisProducerProperties>> { @Override public ProducerDestination provisionProducerDestination(String address, ExtendedProducerProperties<ArtemisProducerProperties> properties) throws ProvisioningException { if (properties.isPartitioned()) { return provisionPartitionedProducerDestination(address, properties); } return provisionUnpartitionedProducerDestination(address, properties); } ArtemisProvisioningProvider(ArtemisBrokerManager artemisBrokerManager); }
ArtemisProvisioningProvider implements ProvisioningProvider< ExtendedConsumerProperties<ArtemisConsumerProperties>, ExtendedProducerProperties<ArtemisProducerProperties>> { @Override public ProducerDestination provisionProducerDestination(String address, ExtendedProducerProperties<ArtemisProducerProperties> properties) throws ProvisioningException { if (properties.isPartitioned()) { return provisionPartitionedProducerDestination(address, properties); } return provisionUnpartitionedProducerDestination(address, properties); } ArtemisProvisioningProvider(ArtemisBrokerManager artemisBrokerManager); @Override ProducerDestination provisionProducerDestination(String address, ExtendedProducerProperties<ArtemisProducerProperties> properties); @Override ConsumerDestination provisionConsumerDestination(String address, String group, ExtendedConsumerProperties<ArtemisConsumerProperties> properties); }
ArtemisProvisioningProvider implements ProvisioningProvider< ExtendedConsumerProperties<ArtemisConsumerProperties>, ExtendedProducerProperties<ArtemisProducerProperties>> { @Override public ProducerDestination provisionProducerDestination(String address, ExtendedProducerProperties<ArtemisProducerProperties> properties) throws ProvisioningException { if (properties.isPartitioned()) { return provisionPartitionedProducerDestination(address, properties); } return provisionUnpartitionedProducerDestination(address, properties); } ArtemisProvisioningProvider(ArtemisBrokerManager artemisBrokerManager); @Override ProducerDestination provisionProducerDestination(String address, ExtendedProducerProperties<ArtemisProducerProperties> properties); @Override ConsumerDestination provisionConsumerDestination(String address, String group, ExtendedConsumerProperties<ArtemisConsumerProperties> properties); }
@Test public void shouldProvisionPartitionedProducerWithRequiredGroups() { String partitionedAddress0 = String.format("%s-0", address); String partitionedAddress1 = String.format("%s-1", address); given(mockProducerProperties.getRequiredGroups()).willReturn(groups); given(mockProducerProperties.isPartitioned()).willReturn(true); given(mockProducerProperties.getPartitionCount()).willReturn(2); ProducerDestination destination = provider.provisionProducerDestination(address, mockProducerProperties); assertThat(destination).isInstanceOf(ArtemisProducerDestination.class); assertThat(destination.getNameForPartition(0)).isEqualTo(partitionedAddress0); assertThat(destination.getNameForPartition(1)).isEqualTo(partitionedAddress1); verify(mockArtemisBrokerManager).createAddress(partitionedAddress0, mockArtemisProducerProperties); verify(mockArtemisBrokerManager).createAddress(partitionedAddress1, mockArtemisProducerProperties); verify(mockArtemisBrokerManager).createQueue(partitionedAddress0, getQueueName(partitionedAddress0, groups[0])); verify(mockArtemisBrokerManager).createQueue(partitionedAddress0, getQueueName(partitionedAddress0, groups[1])); verify(mockArtemisBrokerManager).createQueue(partitionedAddress1, getQueueName(partitionedAddress1, groups[0])); verify(mockArtemisBrokerManager).createQueue(partitionedAddress1, getQueueName(partitionedAddress1, groups[1])); }
@Override public ProducerDestination provisionProducerDestination(String address, ExtendedProducerProperties<ArtemisProducerProperties> properties) throws ProvisioningException { if (properties.isPartitioned()) { return provisionPartitionedProducerDestination(address, properties); } return provisionUnpartitionedProducerDestination(address, properties); }
ArtemisProvisioningProvider implements ProvisioningProvider< ExtendedConsumerProperties<ArtemisConsumerProperties>, ExtendedProducerProperties<ArtemisProducerProperties>> { @Override public ProducerDestination provisionProducerDestination(String address, ExtendedProducerProperties<ArtemisProducerProperties> properties) throws ProvisioningException { if (properties.isPartitioned()) { return provisionPartitionedProducerDestination(address, properties); } return provisionUnpartitionedProducerDestination(address, properties); } }
ArtemisProvisioningProvider implements ProvisioningProvider< ExtendedConsumerProperties<ArtemisConsumerProperties>, ExtendedProducerProperties<ArtemisProducerProperties>> { @Override public ProducerDestination provisionProducerDestination(String address, ExtendedProducerProperties<ArtemisProducerProperties> properties) throws ProvisioningException { if (properties.isPartitioned()) { return provisionPartitionedProducerDestination(address, properties); } return provisionUnpartitionedProducerDestination(address, properties); } ArtemisProvisioningProvider(ArtemisBrokerManager artemisBrokerManager); }
ArtemisProvisioningProvider implements ProvisioningProvider< ExtendedConsumerProperties<ArtemisConsumerProperties>, ExtendedProducerProperties<ArtemisProducerProperties>> { @Override public ProducerDestination provisionProducerDestination(String address, ExtendedProducerProperties<ArtemisProducerProperties> properties) throws ProvisioningException { if (properties.isPartitioned()) { return provisionPartitionedProducerDestination(address, properties); } return provisionUnpartitionedProducerDestination(address, properties); } ArtemisProvisioningProvider(ArtemisBrokerManager artemisBrokerManager); @Override ProducerDestination provisionProducerDestination(String address, ExtendedProducerProperties<ArtemisProducerProperties> properties); @Override ConsumerDestination provisionConsumerDestination(String address, String group, ExtendedConsumerProperties<ArtemisConsumerProperties> properties); }
ArtemisProvisioningProvider implements ProvisioningProvider< ExtendedConsumerProperties<ArtemisConsumerProperties>, ExtendedProducerProperties<ArtemisProducerProperties>> { @Override public ProducerDestination provisionProducerDestination(String address, ExtendedProducerProperties<ArtemisProducerProperties> properties) throws ProvisioningException { if (properties.isPartitioned()) { return provisionPartitionedProducerDestination(address, properties); } return provisionUnpartitionedProducerDestination(address, properties); } ArtemisProvisioningProvider(ArtemisBrokerManager artemisBrokerManager); @Override ProducerDestination provisionProducerDestination(String address, ExtendedProducerProperties<ArtemisProducerProperties> properties); @Override ConsumerDestination provisionConsumerDestination(String address, String group, ExtendedConsumerProperties<ArtemisConsumerProperties> properties); }
@Test public void shouldProvisionUnpartitionedConsumer() { ConsumerDestination destination = provider.provisionConsumerDestination(address, null, mockConsumerProperties); assertThat(destination).isInstanceOf(ArtemisConsumerDestination.class); assertThat(destination.getName()).isEqualTo(address); verify(mockArtemisBrokerManager).createAddress(address, mockArtemisConsumerProperties); }
@Override public ConsumerDestination provisionConsumerDestination(String address, String group, ExtendedConsumerProperties<ArtemisConsumerProperties> properties) throws ProvisioningException { ArtemisConsumerDestination destination; if (properties.isPartitioned()) { logger.debug("Provisioning partitioned consumer destination with address '{}' and instance index '{}'", address, properties.getInstanceIndex()); destination = new ArtemisConsumerDestination(getPartitionAddress(address, properties.getInstanceIndex())); } else { logger.debug("Provisioning unpartitioned consumer destination with address '{}'", address); destination = new ArtemisConsumerDestination(address); } artemisBrokerManager.createAddress(destination.getName(), properties.getExtension()); return destination; }
ArtemisProvisioningProvider implements ProvisioningProvider< ExtendedConsumerProperties<ArtemisConsumerProperties>, ExtendedProducerProperties<ArtemisProducerProperties>> { @Override public ConsumerDestination provisionConsumerDestination(String address, String group, ExtendedConsumerProperties<ArtemisConsumerProperties> properties) throws ProvisioningException { ArtemisConsumerDestination destination; if (properties.isPartitioned()) { logger.debug("Provisioning partitioned consumer destination with address '{}' and instance index '{}'", address, properties.getInstanceIndex()); destination = new ArtemisConsumerDestination(getPartitionAddress(address, properties.getInstanceIndex())); } else { logger.debug("Provisioning unpartitioned consumer destination with address '{}'", address); destination = new ArtemisConsumerDestination(address); } artemisBrokerManager.createAddress(destination.getName(), properties.getExtension()); return destination; } }
ArtemisProvisioningProvider implements ProvisioningProvider< ExtendedConsumerProperties<ArtemisConsumerProperties>, ExtendedProducerProperties<ArtemisProducerProperties>> { @Override public ConsumerDestination provisionConsumerDestination(String address, String group, ExtendedConsumerProperties<ArtemisConsumerProperties> properties) throws ProvisioningException { ArtemisConsumerDestination destination; if (properties.isPartitioned()) { logger.debug("Provisioning partitioned consumer destination with address '{}' and instance index '{}'", address, properties.getInstanceIndex()); destination = new ArtemisConsumerDestination(getPartitionAddress(address, properties.getInstanceIndex())); } else { logger.debug("Provisioning unpartitioned consumer destination with address '{}'", address); destination = new ArtemisConsumerDestination(address); } artemisBrokerManager.createAddress(destination.getName(), properties.getExtension()); return destination; } ArtemisProvisioningProvider(ArtemisBrokerManager artemisBrokerManager); }
ArtemisProvisioningProvider implements ProvisioningProvider< ExtendedConsumerProperties<ArtemisConsumerProperties>, ExtendedProducerProperties<ArtemisProducerProperties>> { @Override public ConsumerDestination provisionConsumerDestination(String address, String group, ExtendedConsumerProperties<ArtemisConsumerProperties> properties) throws ProvisioningException { ArtemisConsumerDestination destination; if (properties.isPartitioned()) { logger.debug("Provisioning partitioned consumer destination with address '{}' and instance index '{}'", address, properties.getInstanceIndex()); destination = new ArtemisConsumerDestination(getPartitionAddress(address, properties.getInstanceIndex())); } else { logger.debug("Provisioning unpartitioned consumer destination with address '{}'", address); destination = new ArtemisConsumerDestination(address); } artemisBrokerManager.createAddress(destination.getName(), properties.getExtension()); return destination; } ArtemisProvisioningProvider(ArtemisBrokerManager artemisBrokerManager); @Override ProducerDestination provisionProducerDestination(String address, ExtendedProducerProperties<ArtemisProducerProperties> properties); @Override ConsumerDestination provisionConsumerDestination(String address, String group, ExtendedConsumerProperties<ArtemisConsumerProperties> properties); }
ArtemisProvisioningProvider implements ProvisioningProvider< ExtendedConsumerProperties<ArtemisConsumerProperties>, ExtendedProducerProperties<ArtemisProducerProperties>> { @Override public ConsumerDestination provisionConsumerDestination(String address, String group, ExtendedConsumerProperties<ArtemisConsumerProperties> properties) throws ProvisioningException { ArtemisConsumerDestination destination; if (properties.isPartitioned()) { logger.debug("Provisioning partitioned consumer destination with address '{}' and instance index '{}'", address, properties.getInstanceIndex()); destination = new ArtemisConsumerDestination(getPartitionAddress(address, properties.getInstanceIndex())); } else { logger.debug("Provisioning unpartitioned consumer destination with address '{}'", address); destination = new ArtemisConsumerDestination(address); } artemisBrokerManager.createAddress(destination.getName(), properties.getExtension()); return destination; } ArtemisProvisioningProvider(ArtemisBrokerManager artemisBrokerManager); @Override ProducerDestination provisionProducerDestination(String address, ExtendedProducerProperties<ArtemisProducerProperties> properties); @Override ConsumerDestination provisionConsumerDestination(String address, String group, ExtendedConsumerProperties<ArtemisConsumerProperties> properties); }
@Test public void shouldProvisionPartitionedConsumer() { given(mockConsumerProperties.isPartitioned()).willReturn(true); given(mockConsumerProperties.getInstanceIndex()).willReturn(0); ConsumerDestination destination = provider.provisionConsumerDestination(address, null, mockConsumerProperties); String partitionedAddress = String.format("%s-0", address); assertThat(destination).isInstanceOf(ArtemisConsumerDestination.class); assertThat(destination.getName()).isEqualTo(partitionedAddress); verify(mockArtemisBrokerManager).createAddress(partitionedAddress, mockArtemisConsumerProperties); }
@Override public ConsumerDestination provisionConsumerDestination(String address, String group, ExtendedConsumerProperties<ArtemisConsumerProperties> properties) throws ProvisioningException { ArtemisConsumerDestination destination; if (properties.isPartitioned()) { logger.debug("Provisioning partitioned consumer destination with address '{}' and instance index '{}'", address, properties.getInstanceIndex()); destination = new ArtemisConsumerDestination(getPartitionAddress(address, properties.getInstanceIndex())); } else { logger.debug("Provisioning unpartitioned consumer destination with address '{}'", address); destination = new ArtemisConsumerDestination(address); } artemisBrokerManager.createAddress(destination.getName(), properties.getExtension()); return destination; }
ArtemisProvisioningProvider implements ProvisioningProvider< ExtendedConsumerProperties<ArtemisConsumerProperties>, ExtendedProducerProperties<ArtemisProducerProperties>> { @Override public ConsumerDestination provisionConsumerDestination(String address, String group, ExtendedConsumerProperties<ArtemisConsumerProperties> properties) throws ProvisioningException { ArtemisConsumerDestination destination; if (properties.isPartitioned()) { logger.debug("Provisioning partitioned consumer destination with address '{}' and instance index '{}'", address, properties.getInstanceIndex()); destination = new ArtemisConsumerDestination(getPartitionAddress(address, properties.getInstanceIndex())); } else { logger.debug("Provisioning unpartitioned consumer destination with address '{}'", address); destination = new ArtemisConsumerDestination(address); } artemisBrokerManager.createAddress(destination.getName(), properties.getExtension()); return destination; } }
ArtemisProvisioningProvider implements ProvisioningProvider< ExtendedConsumerProperties<ArtemisConsumerProperties>, ExtendedProducerProperties<ArtemisProducerProperties>> { @Override public ConsumerDestination provisionConsumerDestination(String address, String group, ExtendedConsumerProperties<ArtemisConsumerProperties> properties) throws ProvisioningException { ArtemisConsumerDestination destination; if (properties.isPartitioned()) { logger.debug("Provisioning partitioned consumer destination with address '{}' and instance index '{}'", address, properties.getInstanceIndex()); destination = new ArtemisConsumerDestination(getPartitionAddress(address, properties.getInstanceIndex())); } else { logger.debug("Provisioning unpartitioned consumer destination with address '{}'", address); destination = new ArtemisConsumerDestination(address); } artemisBrokerManager.createAddress(destination.getName(), properties.getExtension()); return destination; } ArtemisProvisioningProvider(ArtemisBrokerManager artemisBrokerManager); }
ArtemisProvisioningProvider implements ProvisioningProvider< ExtendedConsumerProperties<ArtemisConsumerProperties>, ExtendedProducerProperties<ArtemisProducerProperties>> { @Override public ConsumerDestination provisionConsumerDestination(String address, String group, ExtendedConsumerProperties<ArtemisConsumerProperties> properties) throws ProvisioningException { ArtemisConsumerDestination destination; if (properties.isPartitioned()) { logger.debug("Provisioning partitioned consumer destination with address '{}' and instance index '{}'", address, properties.getInstanceIndex()); destination = new ArtemisConsumerDestination(getPartitionAddress(address, properties.getInstanceIndex())); } else { logger.debug("Provisioning unpartitioned consumer destination with address '{}'", address); destination = new ArtemisConsumerDestination(address); } artemisBrokerManager.createAddress(destination.getName(), properties.getExtension()); return destination; } ArtemisProvisioningProvider(ArtemisBrokerManager artemisBrokerManager); @Override ProducerDestination provisionProducerDestination(String address, ExtendedProducerProperties<ArtemisProducerProperties> properties); @Override ConsumerDestination provisionConsumerDestination(String address, String group, ExtendedConsumerProperties<ArtemisConsumerProperties> properties); }
ArtemisProvisioningProvider implements ProvisioningProvider< ExtendedConsumerProperties<ArtemisConsumerProperties>, ExtendedProducerProperties<ArtemisProducerProperties>> { @Override public ConsumerDestination provisionConsumerDestination(String address, String group, ExtendedConsumerProperties<ArtemisConsumerProperties> properties) throws ProvisioningException { ArtemisConsumerDestination destination; if (properties.isPartitioned()) { logger.debug("Provisioning partitioned consumer destination with address '{}' and instance index '{}'", address, properties.getInstanceIndex()); destination = new ArtemisConsumerDestination(getPartitionAddress(address, properties.getInstanceIndex())); } else { logger.debug("Provisioning unpartitioned consumer destination with address '{}'", address); destination = new ArtemisConsumerDestination(address); } artemisBrokerManager.createAddress(destination.getName(), properties.getExtension()); return destination; } ArtemisProvisioningProvider(ArtemisBrokerManager artemisBrokerManager); @Override ProducerDestination provisionProducerDestination(String address, ExtendedProducerProperties<ArtemisProducerProperties> properties); @Override ConsumerDestination provisionConsumerDestination(String address, String group, ExtendedConsumerProperties<ArtemisConsumerProperties> properties); }
@Test public void shouldGetListenerContainer() { ListenerContainerFactory factory = new ListenerContainerFactory(mockConnectionFactory); AbstractMessageListenerContainer container = factory.getListenerContainer("testTopic", "testSubscription"); assertThat(container.getConnectionFactory()).isEqualTo(mockConnectionFactory); assertThat(container.getDestinationName()).isEqualTo("testTopic"); assertThat(container.isPubSubDomain()).isTrue(); assertThat(container.getSubscriptionName()).isEqualTo("testSubscription"); assertThat(container.isSessionTransacted()).isTrue(); assertThat(container.isSubscriptionDurable()).isTrue(); assertThat(container.isSubscriptionShared()).isTrue(); }
public AbstractMessageListenerContainer getListenerContainer(String topic, String subscriptionName) { DefaultMessageListenerContainer listenerContainer = new DefaultMessageListenerContainer(); listenerContainer.setConnectionFactory(connectionFactory); listenerContainer.setPubSubDomain(true); listenerContainer.setDestinationName(topic); listenerContainer.setSubscriptionName(subscriptionName); listenerContainer.setSessionTransacted(true); listenerContainer.setSubscriptionDurable(true); listenerContainer.setSubscriptionShared(true); return listenerContainer; }
ListenerContainerFactory { public AbstractMessageListenerContainer getListenerContainer(String topic, String subscriptionName) { DefaultMessageListenerContainer listenerContainer = new DefaultMessageListenerContainer(); listenerContainer.setConnectionFactory(connectionFactory); listenerContainer.setPubSubDomain(true); listenerContainer.setDestinationName(topic); listenerContainer.setSubscriptionName(subscriptionName); listenerContainer.setSessionTransacted(true); listenerContainer.setSubscriptionDurable(true); listenerContainer.setSubscriptionShared(true); return listenerContainer; } }
ListenerContainerFactory { public AbstractMessageListenerContainer getListenerContainer(String topic, String subscriptionName) { DefaultMessageListenerContainer listenerContainer = new DefaultMessageListenerContainer(); listenerContainer.setConnectionFactory(connectionFactory); listenerContainer.setPubSubDomain(true); listenerContainer.setDestinationName(topic); listenerContainer.setSubscriptionName(subscriptionName); listenerContainer.setSessionTransacted(true); listenerContainer.setSubscriptionDurable(true); listenerContainer.setSubscriptionShared(true); return listenerContainer; } ListenerContainerFactory(ConnectionFactory connectionFactory); }
ListenerContainerFactory { public AbstractMessageListenerContainer getListenerContainer(String topic, String subscriptionName) { DefaultMessageListenerContainer listenerContainer = new DefaultMessageListenerContainer(); listenerContainer.setConnectionFactory(connectionFactory); listenerContainer.setPubSubDomain(true); listenerContainer.setDestinationName(topic); listenerContainer.setSubscriptionName(subscriptionName); listenerContainer.setSessionTransacted(true); listenerContainer.setSubscriptionDurable(true); listenerContainer.setSubscriptionShared(true); return listenerContainer; } ListenerContainerFactory(ConnectionFactory connectionFactory); AbstractMessageListenerContainer getListenerContainer(String topic, String subscriptionName); }
ListenerContainerFactory { public AbstractMessageListenerContainer getListenerContainer(String topic, String subscriptionName) { DefaultMessageListenerContainer listenerContainer = new DefaultMessageListenerContainer(); listenerContainer.setConnectionFactory(connectionFactory); listenerContainer.setPubSubDomain(true); listenerContainer.setDestinationName(topic); listenerContainer.setSubscriptionName(subscriptionName); listenerContainer.setSessionTransacted(true); listenerContainer.setSubscriptionDurable(true); listenerContainer.setSubscriptionShared(true); return listenerContainer; } ListenerContainerFactory(ConnectionFactory connectionFactory); AbstractMessageListenerContainer getListenerContainer(String topic, String subscriptionName); }
@Test public void shouldGetQueueName() { assertThat(NamingUtils.getQueueName("testAddress", "testGroup")).isEqualTo("testAddress-testGroup"); }
public static String getQueueName(String address, String group) { Objects.requireNonNull(address); Objects.requireNonNull(group); return String.format("%s-%s", address, group); }
NamingUtils { public static String getQueueName(String address, String group) { Objects.requireNonNull(address); Objects.requireNonNull(group); return String.format("%s-%s", address, group); } }
NamingUtils { public static String getQueueName(String address, String group) { Objects.requireNonNull(address); Objects.requireNonNull(group); return String.format("%s-%s", address, group); } }
NamingUtils { public static String getQueueName(String address, String group) { Objects.requireNonNull(address); Objects.requireNonNull(group); return String.format("%s-%s", address, group); } static String getPartitionAddress(String address, int partition); static String getQueueName(String address, String group); static String getAnonymousGroupName(); }
NamingUtils { public static String getQueueName(String address, String group) { Objects.requireNonNull(address); Objects.requireNonNull(group); return String.format("%s-%s", address, group); } static String getPartitionAddress(String address, int partition); static String getQueueName(String address, String group); static String getAnonymousGroupName(); }
@Test(expected = NullPointerException.class) public void shouldNotAcceptNullAddressToGetQueueName() { NamingUtils.getQueueName(null, "testGroup"); }
public static String getQueueName(String address, String group) { Objects.requireNonNull(address); Objects.requireNonNull(group); return String.format("%s-%s", address, group); }
NamingUtils { public static String getQueueName(String address, String group) { Objects.requireNonNull(address); Objects.requireNonNull(group); return String.format("%s-%s", address, group); } }
NamingUtils { public static String getQueueName(String address, String group) { Objects.requireNonNull(address); Objects.requireNonNull(group); return String.format("%s-%s", address, group); } }
NamingUtils { public static String getQueueName(String address, String group) { Objects.requireNonNull(address); Objects.requireNonNull(group); return String.format("%s-%s", address, group); } static String getPartitionAddress(String address, int partition); static String getQueueName(String address, String group); static String getAnonymousGroupName(); }
NamingUtils { public static String getQueueName(String address, String group) { Objects.requireNonNull(address); Objects.requireNonNull(group); return String.format("%s-%s", address, group); } static String getPartitionAddress(String address, int partition); static String getQueueName(String address, String group); static String getAnonymousGroupName(); }
@Test(expected = NullPointerException.class) public void shouldNotAcceptNullGroupToGetQueueName() { NamingUtils.getQueueName("testAddress", null); }
public static String getQueueName(String address, String group) { Objects.requireNonNull(address); Objects.requireNonNull(group); return String.format("%s-%s", address, group); }
NamingUtils { public static String getQueueName(String address, String group) { Objects.requireNonNull(address); Objects.requireNonNull(group); return String.format("%s-%s", address, group); } }
NamingUtils { public static String getQueueName(String address, String group) { Objects.requireNonNull(address); Objects.requireNonNull(group); return String.format("%s-%s", address, group); } }
NamingUtils { public static String getQueueName(String address, String group) { Objects.requireNonNull(address); Objects.requireNonNull(group); return String.format("%s-%s", address, group); } static String getPartitionAddress(String address, int partition); static String getQueueName(String address, String group); static String getAnonymousGroupName(); }
NamingUtils { public static String getQueueName(String address, String group) { Objects.requireNonNull(address); Objects.requireNonNull(group); return String.format("%s-%s", address, group); } static String getPartitionAddress(String address, int partition); static String getQueueName(String address, String group); static String getAnonymousGroupName(); }
@Test public void shouldGetAnonymousQueueName() { assertThat(NamingUtils.getAnonymousGroupName()).hasSize(32) .startsWith("anonymous-"); }
public static String getAnonymousGroupName() { UUID uuid = UUID.randomUUID(); ByteBuffer buffer = ByteBuffer.wrap(new byte[16]); buffer.putLong(uuid.getMostSignificantBits()) .putLong(uuid.getLeastSignificantBits()); return "anonymous-" + Base64Utils.encodeToUrlSafeString(buffer.array()) .replaceAll("=", ""); }
NamingUtils { public static String getAnonymousGroupName() { UUID uuid = UUID.randomUUID(); ByteBuffer buffer = ByteBuffer.wrap(new byte[16]); buffer.putLong(uuid.getMostSignificantBits()) .putLong(uuid.getLeastSignificantBits()); return "anonymous-" + Base64Utils.encodeToUrlSafeString(buffer.array()) .replaceAll("=", ""); } }
NamingUtils { public static String getAnonymousGroupName() { UUID uuid = UUID.randomUUID(); ByteBuffer buffer = ByteBuffer.wrap(new byte[16]); buffer.putLong(uuid.getMostSignificantBits()) .putLong(uuid.getLeastSignificantBits()); return "anonymous-" + Base64Utils.encodeToUrlSafeString(buffer.array()) .replaceAll("=", ""); } }
NamingUtils { public static String getAnonymousGroupName() { UUID uuid = UUID.randomUUID(); ByteBuffer buffer = ByteBuffer.wrap(new byte[16]); buffer.putLong(uuid.getMostSignificantBits()) .putLong(uuid.getLeastSignificantBits()); return "anonymous-" + Base64Utils.encodeToUrlSafeString(buffer.array()) .replaceAll("=", ""); } static String getPartitionAddress(String address, int partition); static String getQueueName(String address, String group); static String getAnonymousGroupName(); }
NamingUtils { public static String getAnonymousGroupName() { UUID uuid = UUID.randomUUID(); ByteBuffer buffer = ByteBuffer.wrap(new byte[16]); buffer.putLong(uuid.getMostSignificantBits()) .putLong(uuid.getLeastSignificantBits()); return "anonymous-" + Base64Utils.encodeToUrlSafeString(buffer.array()) .replaceAll("=", ""); } static String getPartitionAddress(String address, int partition); static String getQueueName(String address, String group); static String getAnonymousGroupName(); }
@Test public void shouldCreateProducerMessageHandler() { MessageHandler handler = binder.createProducerMessageHandler(null, null, null); assertThat(handler).isInstanceOf(JmsSendingMessageHandler.class); }
@Override protected MessageHandler createProducerMessageHandler(ProducerDestination destination, ExtendedProducerProperties<ArtemisProducerProperties> properties, MessageChannel errorChannel) { logger.debug("Creating producer message handler for '" + destination + "'"); JmsSendingMessageHandler handler = Jms.outboundAdapter(connectionFactory) .destination(message -> getMessageDestination(message, destination)) .configureJmsTemplate(templateSpec -> templateSpec.pubSubDomain(true)) .get(); handler.setApplicationContext(getApplicationContext()); handler.setBeanFactory(getBeanFactory()); return handler; }
ArtemisMessageChannelBinder extends AbstractMessageChannelBinder<ExtendedConsumerProperties<ArtemisConsumerProperties>, ExtendedProducerProperties<ArtemisProducerProperties>, ArtemisProvisioningProvider> implements ExtendedPropertiesBinder<MessageChannel, ArtemisConsumerProperties, ArtemisProducerProperties> { @Override protected MessageHandler createProducerMessageHandler(ProducerDestination destination, ExtendedProducerProperties<ArtemisProducerProperties> properties, MessageChannel errorChannel) { logger.debug("Creating producer message handler for '" + destination + "'"); JmsSendingMessageHandler handler = Jms.outboundAdapter(connectionFactory) .destination(message -> getMessageDestination(message, destination)) .configureJmsTemplate(templateSpec -> templateSpec.pubSubDomain(true)) .get(); handler.setApplicationContext(getApplicationContext()); handler.setBeanFactory(getBeanFactory()); return handler; } }
ArtemisMessageChannelBinder extends AbstractMessageChannelBinder<ExtendedConsumerProperties<ArtemisConsumerProperties>, ExtendedProducerProperties<ArtemisProducerProperties>, ArtemisProvisioningProvider> implements ExtendedPropertiesBinder<MessageChannel, ArtemisConsumerProperties, ArtemisProducerProperties> { @Override protected MessageHandler createProducerMessageHandler(ProducerDestination destination, ExtendedProducerProperties<ArtemisProducerProperties> properties, MessageChannel errorChannel) { logger.debug("Creating producer message handler for '" + destination + "'"); JmsSendingMessageHandler handler = Jms.outboundAdapter(connectionFactory) .destination(message -> getMessageDestination(message, destination)) .configureJmsTemplate(templateSpec -> templateSpec.pubSubDomain(true)) .get(); handler.setApplicationContext(getApplicationContext()); handler.setBeanFactory(getBeanFactory()); return handler; } ArtemisMessageChannelBinder(ArtemisProvisioningProvider provisioningProvider, ConnectionFactory connectionFactory, ArtemisExtendedBindingProperties bindingProperties); }
ArtemisMessageChannelBinder extends AbstractMessageChannelBinder<ExtendedConsumerProperties<ArtemisConsumerProperties>, ExtendedProducerProperties<ArtemisProducerProperties>, ArtemisProvisioningProvider> implements ExtendedPropertiesBinder<MessageChannel, ArtemisConsumerProperties, ArtemisProducerProperties> { @Override protected MessageHandler createProducerMessageHandler(ProducerDestination destination, ExtendedProducerProperties<ArtemisProducerProperties> properties, MessageChannel errorChannel) { logger.debug("Creating producer message handler for '" + destination + "'"); JmsSendingMessageHandler handler = Jms.outboundAdapter(connectionFactory) .destination(message -> getMessageDestination(message, destination)) .configureJmsTemplate(templateSpec -> templateSpec.pubSubDomain(true)) .get(); handler.setApplicationContext(getApplicationContext()); handler.setBeanFactory(getBeanFactory()); return handler; } ArtemisMessageChannelBinder(ArtemisProvisioningProvider provisioningProvider, ConnectionFactory connectionFactory, ArtemisExtendedBindingProperties bindingProperties); @Override ArtemisConsumerProperties getExtendedConsumerProperties(String channelName); @Override ArtemisProducerProperties getExtendedProducerProperties(String channelName); @Override String getDefaultsPrefix(); @Override Class<? extends BinderSpecificPropertiesProvider> getExtendedPropertiesEntryClass(); }
ArtemisMessageChannelBinder extends AbstractMessageChannelBinder<ExtendedConsumerProperties<ArtemisConsumerProperties>, ExtendedProducerProperties<ArtemisProducerProperties>, ArtemisProvisioningProvider> implements ExtendedPropertiesBinder<MessageChannel, ArtemisConsumerProperties, ArtemisProducerProperties> { @Override protected MessageHandler createProducerMessageHandler(ProducerDestination destination, ExtendedProducerProperties<ArtemisProducerProperties> properties, MessageChannel errorChannel) { logger.debug("Creating producer message handler for '" + destination + "'"); JmsSendingMessageHandler handler = Jms.outboundAdapter(connectionFactory) .destination(message -> getMessageDestination(message, destination)) .configureJmsTemplate(templateSpec -> templateSpec.pubSubDomain(true)) .get(); handler.setApplicationContext(getApplicationContext()); handler.setBeanFactory(getBeanFactory()); return handler; } ArtemisMessageChannelBinder(ArtemisProvisioningProvider provisioningProvider, ConnectionFactory connectionFactory, ArtemisExtendedBindingProperties bindingProperties); @Override ArtemisConsumerProperties getExtendedConsumerProperties(String channelName); @Override ArtemisProducerProperties getExtendedProducerProperties(String channelName); @Override String getDefaultsPrefix(); @Override Class<? extends BinderSpecificPropertiesProvider> getExtendedPropertiesEntryClass(); }
@Test public void shouldCreateRegularConsumerEndpoint() { given(mockConsumerProperties.getMaxAttempts()).willReturn(1); ArtemisConsumerDestination destination = new ArtemisConsumerDestination("test-destination"); MessageProducer producer = binder.createConsumerEndpoint(destination, "test-group", mockConsumerProperties); assertThat(producer).isInstanceOf(JmsMessageDrivenEndpoint.class); JmsMessageDrivenEndpoint endpoint = (JmsMessageDrivenEndpoint) producer; assertThat(endpoint.getListener()).isNotInstanceOf(RetryableChannelPublishingJmsMessageListener.class); }
@Override protected MessageProducer createConsumerEndpoint(ConsumerDestination destination, String group, ExtendedConsumerProperties<ArtemisConsumerProperties> properties) { logger.debug("Creating consumer endpoint for '{" + destination + "}' with a group '{" + group + "}'"); if (!StringUtils.hasText(group)) { group = getAnonymousGroupName(); } String subscriptionName = getQueueName(destination.getName(), group); ListenerContainerFactory listenerContainerFactory = new ListenerContainerFactory(connectionFactory); AbstractMessageListenerContainer listenerContainer = listenerContainerFactory .getListenerContainer(destination.getName(), subscriptionName); if (properties.getMaxAttempts() == 1) { return Jms.messageDrivenChannelAdapter(listenerContainer).get(); } RetryTemplate retryTemplate = buildRetryTemplate(properties); ErrorInfrastructure errorInfrastructure = registerErrorInfrastructure(destination, group, properties); RetryableChannelPublishingJmsMessageListener listener = new RetryableChannelPublishingJmsMessageListener(retryTemplate, errorInfrastructure.getRecoverer()); listener.setExpectReply(false); return new JmsMessageDrivenEndpoint(listenerContainer, listener); }
ArtemisMessageChannelBinder extends AbstractMessageChannelBinder<ExtendedConsumerProperties<ArtemisConsumerProperties>, ExtendedProducerProperties<ArtemisProducerProperties>, ArtemisProvisioningProvider> implements ExtendedPropertiesBinder<MessageChannel, ArtemisConsumerProperties, ArtemisProducerProperties> { @Override protected MessageProducer createConsumerEndpoint(ConsumerDestination destination, String group, ExtendedConsumerProperties<ArtemisConsumerProperties> properties) { logger.debug("Creating consumer endpoint for '{" + destination + "}' with a group '{" + group + "}'"); if (!StringUtils.hasText(group)) { group = getAnonymousGroupName(); } String subscriptionName = getQueueName(destination.getName(), group); ListenerContainerFactory listenerContainerFactory = new ListenerContainerFactory(connectionFactory); AbstractMessageListenerContainer listenerContainer = listenerContainerFactory .getListenerContainer(destination.getName(), subscriptionName); if (properties.getMaxAttempts() == 1) { return Jms.messageDrivenChannelAdapter(listenerContainer).get(); } RetryTemplate retryTemplate = buildRetryTemplate(properties); ErrorInfrastructure errorInfrastructure = registerErrorInfrastructure(destination, group, properties); RetryableChannelPublishingJmsMessageListener listener = new RetryableChannelPublishingJmsMessageListener(retryTemplate, errorInfrastructure.getRecoverer()); listener.setExpectReply(false); return new JmsMessageDrivenEndpoint(listenerContainer, listener); } }
ArtemisMessageChannelBinder extends AbstractMessageChannelBinder<ExtendedConsumerProperties<ArtemisConsumerProperties>, ExtendedProducerProperties<ArtemisProducerProperties>, ArtemisProvisioningProvider> implements ExtendedPropertiesBinder<MessageChannel, ArtemisConsumerProperties, ArtemisProducerProperties> { @Override protected MessageProducer createConsumerEndpoint(ConsumerDestination destination, String group, ExtendedConsumerProperties<ArtemisConsumerProperties> properties) { logger.debug("Creating consumer endpoint for '{" + destination + "}' with a group '{" + group + "}'"); if (!StringUtils.hasText(group)) { group = getAnonymousGroupName(); } String subscriptionName = getQueueName(destination.getName(), group); ListenerContainerFactory listenerContainerFactory = new ListenerContainerFactory(connectionFactory); AbstractMessageListenerContainer listenerContainer = listenerContainerFactory .getListenerContainer(destination.getName(), subscriptionName); if (properties.getMaxAttempts() == 1) { return Jms.messageDrivenChannelAdapter(listenerContainer).get(); } RetryTemplate retryTemplate = buildRetryTemplate(properties); ErrorInfrastructure errorInfrastructure = registerErrorInfrastructure(destination, group, properties); RetryableChannelPublishingJmsMessageListener listener = new RetryableChannelPublishingJmsMessageListener(retryTemplate, errorInfrastructure.getRecoverer()); listener.setExpectReply(false); return new JmsMessageDrivenEndpoint(listenerContainer, listener); } ArtemisMessageChannelBinder(ArtemisProvisioningProvider provisioningProvider, ConnectionFactory connectionFactory, ArtemisExtendedBindingProperties bindingProperties); }
ArtemisMessageChannelBinder extends AbstractMessageChannelBinder<ExtendedConsumerProperties<ArtemisConsumerProperties>, ExtendedProducerProperties<ArtemisProducerProperties>, ArtemisProvisioningProvider> implements ExtendedPropertiesBinder<MessageChannel, ArtemisConsumerProperties, ArtemisProducerProperties> { @Override protected MessageProducer createConsumerEndpoint(ConsumerDestination destination, String group, ExtendedConsumerProperties<ArtemisConsumerProperties> properties) { logger.debug("Creating consumer endpoint for '{" + destination + "}' with a group '{" + group + "}'"); if (!StringUtils.hasText(group)) { group = getAnonymousGroupName(); } String subscriptionName = getQueueName(destination.getName(), group); ListenerContainerFactory listenerContainerFactory = new ListenerContainerFactory(connectionFactory); AbstractMessageListenerContainer listenerContainer = listenerContainerFactory .getListenerContainer(destination.getName(), subscriptionName); if (properties.getMaxAttempts() == 1) { return Jms.messageDrivenChannelAdapter(listenerContainer).get(); } RetryTemplate retryTemplate = buildRetryTemplate(properties); ErrorInfrastructure errorInfrastructure = registerErrorInfrastructure(destination, group, properties); RetryableChannelPublishingJmsMessageListener listener = new RetryableChannelPublishingJmsMessageListener(retryTemplate, errorInfrastructure.getRecoverer()); listener.setExpectReply(false); return new JmsMessageDrivenEndpoint(listenerContainer, listener); } ArtemisMessageChannelBinder(ArtemisProvisioningProvider provisioningProvider, ConnectionFactory connectionFactory, ArtemisExtendedBindingProperties bindingProperties); @Override ArtemisConsumerProperties getExtendedConsumerProperties(String channelName); @Override ArtemisProducerProperties getExtendedProducerProperties(String channelName); @Override String getDefaultsPrefix(); @Override Class<? extends BinderSpecificPropertiesProvider> getExtendedPropertiesEntryClass(); }
ArtemisMessageChannelBinder extends AbstractMessageChannelBinder<ExtendedConsumerProperties<ArtemisConsumerProperties>, ExtendedProducerProperties<ArtemisProducerProperties>, ArtemisProvisioningProvider> implements ExtendedPropertiesBinder<MessageChannel, ArtemisConsumerProperties, ArtemisProducerProperties> { @Override protected MessageProducer createConsumerEndpoint(ConsumerDestination destination, String group, ExtendedConsumerProperties<ArtemisConsumerProperties> properties) { logger.debug("Creating consumer endpoint for '{" + destination + "}' with a group '{" + group + "}'"); if (!StringUtils.hasText(group)) { group = getAnonymousGroupName(); } String subscriptionName = getQueueName(destination.getName(), group); ListenerContainerFactory listenerContainerFactory = new ListenerContainerFactory(connectionFactory); AbstractMessageListenerContainer listenerContainer = listenerContainerFactory .getListenerContainer(destination.getName(), subscriptionName); if (properties.getMaxAttempts() == 1) { return Jms.messageDrivenChannelAdapter(listenerContainer).get(); } RetryTemplate retryTemplate = buildRetryTemplate(properties); ErrorInfrastructure errorInfrastructure = registerErrorInfrastructure(destination, group, properties); RetryableChannelPublishingJmsMessageListener listener = new RetryableChannelPublishingJmsMessageListener(retryTemplate, errorInfrastructure.getRecoverer()); listener.setExpectReply(false); return new JmsMessageDrivenEndpoint(listenerContainer, listener); } ArtemisMessageChannelBinder(ArtemisProvisioningProvider provisioningProvider, ConnectionFactory connectionFactory, ArtemisExtendedBindingProperties bindingProperties); @Override ArtemisConsumerProperties getExtendedConsumerProperties(String channelName); @Override ArtemisProducerProperties getExtendedProducerProperties(String channelName); @Override String getDefaultsPrefix(); @Override Class<? extends BinderSpecificPropertiesProvider> getExtendedPropertiesEntryClass(); }
@Test public void shouldCreateRetryableConsumerEndpoint() { given(mockConsumerProperties.getMaxAttempts()).willReturn(2); ArtemisConsumerDestination destination = new ArtemisConsumerDestination("test-destination"); MessageProducer producer = binder.createConsumerEndpoint(destination, "test-group", mockConsumerProperties); assertThat(producer).isInstanceOf(JmsMessageDrivenEndpoint.class); ChannelPublishingJmsMessageListener listener = ((JmsMessageDrivenEndpoint) producer).getListener(); assertThat(listener).isInstanceOf(RetryableChannelPublishingJmsMessageListener.class); assertThat(listener.getComponentType()).isEqualTo("jms:message-driven-channel-adapter"); }
@Override protected MessageProducer createConsumerEndpoint(ConsumerDestination destination, String group, ExtendedConsumerProperties<ArtemisConsumerProperties> properties) { logger.debug("Creating consumer endpoint for '{" + destination + "}' with a group '{" + group + "}'"); if (!StringUtils.hasText(group)) { group = getAnonymousGroupName(); } String subscriptionName = getQueueName(destination.getName(), group); ListenerContainerFactory listenerContainerFactory = new ListenerContainerFactory(connectionFactory); AbstractMessageListenerContainer listenerContainer = listenerContainerFactory .getListenerContainer(destination.getName(), subscriptionName); if (properties.getMaxAttempts() == 1) { return Jms.messageDrivenChannelAdapter(listenerContainer).get(); } RetryTemplate retryTemplate = buildRetryTemplate(properties); ErrorInfrastructure errorInfrastructure = registerErrorInfrastructure(destination, group, properties); RetryableChannelPublishingJmsMessageListener listener = new RetryableChannelPublishingJmsMessageListener(retryTemplate, errorInfrastructure.getRecoverer()); listener.setExpectReply(false); return new JmsMessageDrivenEndpoint(listenerContainer, listener); }
ArtemisMessageChannelBinder extends AbstractMessageChannelBinder<ExtendedConsumerProperties<ArtemisConsumerProperties>, ExtendedProducerProperties<ArtemisProducerProperties>, ArtemisProvisioningProvider> implements ExtendedPropertiesBinder<MessageChannel, ArtemisConsumerProperties, ArtemisProducerProperties> { @Override protected MessageProducer createConsumerEndpoint(ConsumerDestination destination, String group, ExtendedConsumerProperties<ArtemisConsumerProperties> properties) { logger.debug("Creating consumer endpoint for '{" + destination + "}' with a group '{" + group + "}'"); if (!StringUtils.hasText(group)) { group = getAnonymousGroupName(); } String subscriptionName = getQueueName(destination.getName(), group); ListenerContainerFactory listenerContainerFactory = new ListenerContainerFactory(connectionFactory); AbstractMessageListenerContainer listenerContainer = listenerContainerFactory .getListenerContainer(destination.getName(), subscriptionName); if (properties.getMaxAttempts() == 1) { return Jms.messageDrivenChannelAdapter(listenerContainer).get(); } RetryTemplate retryTemplate = buildRetryTemplate(properties); ErrorInfrastructure errorInfrastructure = registerErrorInfrastructure(destination, group, properties); RetryableChannelPublishingJmsMessageListener listener = new RetryableChannelPublishingJmsMessageListener(retryTemplate, errorInfrastructure.getRecoverer()); listener.setExpectReply(false); return new JmsMessageDrivenEndpoint(listenerContainer, listener); } }
ArtemisMessageChannelBinder extends AbstractMessageChannelBinder<ExtendedConsumerProperties<ArtemisConsumerProperties>, ExtendedProducerProperties<ArtemisProducerProperties>, ArtemisProvisioningProvider> implements ExtendedPropertiesBinder<MessageChannel, ArtemisConsumerProperties, ArtemisProducerProperties> { @Override protected MessageProducer createConsumerEndpoint(ConsumerDestination destination, String group, ExtendedConsumerProperties<ArtemisConsumerProperties> properties) { logger.debug("Creating consumer endpoint for '{" + destination + "}' with a group '{" + group + "}'"); if (!StringUtils.hasText(group)) { group = getAnonymousGroupName(); } String subscriptionName = getQueueName(destination.getName(), group); ListenerContainerFactory listenerContainerFactory = new ListenerContainerFactory(connectionFactory); AbstractMessageListenerContainer listenerContainer = listenerContainerFactory .getListenerContainer(destination.getName(), subscriptionName); if (properties.getMaxAttempts() == 1) { return Jms.messageDrivenChannelAdapter(listenerContainer).get(); } RetryTemplate retryTemplate = buildRetryTemplate(properties); ErrorInfrastructure errorInfrastructure = registerErrorInfrastructure(destination, group, properties); RetryableChannelPublishingJmsMessageListener listener = new RetryableChannelPublishingJmsMessageListener(retryTemplate, errorInfrastructure.getRecoverer()); listener.setExpectReply(false); return new JmsMessageDrivenEndpoint(listenerContainer, listener); } ArtemisMessageChannelBinder(ArtemisProvisioningProvider provisioningProvider, ConnectionFactory connectionFactory, ArtemisExtendedBindingProperties bindingProperties); }
ArtemisMessageChannelBinder extends AbstractMessageChannelBinder<ExtendedConsumerProperties<ArtemisConsumerProperties>, ExtendedProducerProperties<ArtemisProducerProperties>, ArtemisProvisioningProvider> implements ExtendedPropertiesBinder<MessageChannel, ArtemisConsumerProperties, ArtemisProducerProperties> { @Override protected MessageProducer createConsumerEndpoint(ConsumerDestination destination, String group, ExtendedConsumerProperties<ArtemisConsumerProperties> properties) { logger.debug("Creating consumer endpoint for '{" + destination + "}' with a group '{" + group + "}'"); if (!StringUtils.hasText(group)) { group = getAnonymousGroupName(); } String subscriptionName = getQueueName(destination.getName(), group); ListenerContainerFactory listenerContainerFactory = new ListenerContainerFactory(connectionFactory); AbstractMessageListenerContainer listenerContainer = listenerContainerFactory .getListenerContainer(destination.getName(), subscriptionName); if (properties.getMaxAttempts() == 1) { return Jms.messageDrivenChannelAdapter(listenerContainer).get(); } RetryTemplate retryTemplate = buildRetryTemplate(properties); ErrorInfrastructure errorInfrastructure = registerErrorInfrastructure(destination, group, properties); RetryableChannelPublishingJmsMessageListener listener = new RetryableChannelPublishingJmsMessageListener(retryTemplate, errorInfrastructure.getRecoverer()); listener.setExpectReply(false); return new JmsMessageDrivenEndpoint(listenerContainer, listener); } ArtemisMessageChannelBinder(ArtemisProvisioningProvider provisioningProvider, ConnectionFactory connectionFactory, ArtemisExtendedBindingProperties bindingProperties); @Override ArtemisConsumerProperties getExtendedConsumerProperties(String channelName); @Override ArtemisProducerProperties getExtendedProducerProperties(String channelName); @Override String getDefaultsPrefix(); @Override Class<? extends BinderSpecificPropertiesProvider> getExtendedPropertiesEntryClass(); }
ArtemisMessageChannelBinder extends AbstractMessageChannelBinder<ExtendedConsumerProperties<ArtemisConsumerProperties>, ExtendedProducerProperties<ArtemisProducerProperties>, ArtemisProvisioningProvider> implements ExtendedPropertiesBinder<MessageChannel, ArtemisConsumerProperties, ArtemisProducerProperties> { @Override protected MessageProducer createConsumerEndpoint(ConsumerDestination destination, String group, ExtendedConsumerProperties<ArtemisConsumerProperties> properties) { logger.debug("Creating consumer endpoint for '{" + destination + "}' with a group '{" + group + "}'"); if (!StringUtils.hasText(group)) { group = getAnonymousGroupName(); } String subscriptionName = getQueueName(destination.getName(), group); ListenerContainerFactory listenerContainerFactory = new ListenerContainerFactory(connectionFactory); AbstractMessageListenerContainer listenerContainer = listenerContainerFactory .getListenerContainer(destination.getName(), subscriptionName); if (properties.getMaxAttempts() == 1) { return Jms.messageDrivenChannelAdapter(listenerContainer).get(); } RetryTemplate retryTemplate = buildRetryTemplate(properties); ErrorInfrastructure errorInfrastructure = registerErrorInfrastructure(destination, group, properties); RetryableChannelPublishingJmsMessageListener listener = new RetryableChannelPublishingJmsMessageListener(retryTemplate, errorInfrastructure.getRecoverer()); listener.setExpectReply(false); return new JmsMessageDrivenEndpoint(listenerContainer, listener); } ArtemisMessageChannelBinder(ArtemisProvisioningProvider provisioningProvider, ConnectionFactory connectionFactory, ArtemisExtendedBindingProperties bindingProperties); @Override ArtemisConsumerProperties getExtendedConsumerProperties(String channelName); @Override ArtemisProducerProperties getExtendedProducerProperties(String channelName); @Override String getDefaultsPrefix(); @Override Class<? extends BinderSpecificPropertiesProvider> getExtendedPropertiesEntryClass(); }
@Test public void shouldGetName() { String name = "test-name"; ArtemisProducerDestination destination = new ArtemisProducerDestination(name); assertThat(destination.getName()).isEqualTo(name); }
@Override public String getName() { return name; }
ArtemisProducerDestination implements ProducerDestination { @Override public String getName() { return name; } }
ArtemisProducerDestination implements ProducerDestination { @Override public String getName() { return name; } ArtemisProducerDestination(String name); }
ArtemisProducerDestination implements ProducerDestination { @Override public String getName() { return name; } ArtemisProducerDestination(String name); @Override String getName(); @Override String getNameForPartition(int i); @Override String toString(); }
ArtemisProducerDestination implements ProducerDestination { @Override public String getName() { return name; } ArtemisProducerDestination(String name); @Override String getName(); @Override String getNameForPartition(int i); @Override String toString(); }
@Test public void readLabelsFromFile1() throws Exception { Scorer.readLabelsFromFile(getFileFromResources("test-gold1.txt")); }
public static Map<String, Integer> readLabelsFromFile(File file) throws IOException { FileInputStream inputStream = new FileInputStream(file); List<String> lines = IOUtils.readLines(inputStream, UTF8); IOUtils.closeQuietly(inputStream); Map<String, Integer> result = new TreeMap<>(); for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); if (!line.trim().isEmpty() && !line.trim().startsWith("#")) { String[] split = line.split("\\s+"); if (split.length != 2) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected two whitespace-delimited entries but got '" + line + "' (file " + file.getAbsolutePath() + ")"); } String id = split[0].trim(); int value; try { value = Integer.valueOf(split[1]); } catch (NumberFormatException e) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected an integer but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } if (!(value == 0 || value == 1)) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected 0 or 1 but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } result.put(id, value); } } return result; }
Scorer { public static Map<String, Integer> readLabelsFromFile(File file) throws IOException { FileInputStream inputStream = new FileInputStream(file); List<String> lines = IOUtils.readLines(inputStream, UTF8); IOUtils.closeQuietly(inputStream); Map<String, Integer> result = new TreeMap<>(); for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); if (!line.trim().isEmpty() && !line.trim().startsWith("#")) { String[] split = line.split("\\s+"); if (split.length != 2) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected two whitespace-delimited entries but got '" + line + "' (file " + file.getAbsolutePath() + ")"); } String id = split[0].trim(); int value; try { value = Integer.valueOf(split[1]); } catch (NumberFormatException e) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected an integer but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } if (!(value == 0 || value == 1)) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected 0 or 1 but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } result.put(id, value); } } return result; } }
Scorer { public static Map<String, Integer> readLabelsFromFile(File file) throws IOException { FileInputStream inputStream = new FileInputStream(file); List<String> lines = IOUtils.readLines(inputStream, UTF8); IOUtils.closeQuietly(inputStream); Map<String, Integer> result = new TreeMap<>(); for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); if (!line.trim().isEmpty() && !line.trim().startsWith("#")) { String[] split = line.split("\\s+"); if (split.length != 2) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected two whitespace-delimited entries but got '" + line + "' (file " + file.getAbsolutePath() + ")"); } String id = split[0].trim(); int value; try { value = Integer.valueOf(split[1]); } catch (NumberFormatException e) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected an integer but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } if (!(value == 0 || value == 1)) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected 0 or 1 but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } result.put(id, value); } } return result; } }
Scorer { public static Map<String, Integer> readLabelsFromFile(File file) throws IOException { FileInputStream inputStream = new FileInputStream(file); List<String> lines = IOUtils.readLines(inputStream, UTF8); IOUtils.closeQuietly(inputStream); Map<String, Integer> result = new TreeMap<>(); for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); if (!line.trim().isEmpty() && !line.trim().startsWith("#")) { String[] split = line.split("\\s+"); if (split.length != 2) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected two whitespace-delimited entries but got '" + line + "' (file " + file.getAbsolutePath() + ")"); } String id = split[0].trim(); int value; try { value = Integer.valueOf(split[1]); } catch (NumberFormatException e) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected an integer but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } if (!(value == 0 || value == 1)) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected 0 or 1 but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } result.put(id, value); } } return result; } static Map<String, Integer> readLabelsFromFile(File file); static double computeAccuracy(Map<String, Integer> gold, Map<String, Integer> predictions); static void main(String[] args); }
Scorer { public static Map<String, Integer> readLabelsFromFile(File file) throws IOException { FileInputStream inputStream = new FileInputStream(file); List<String> lines = IOUtils.readLines(inputStream, UTF8); IOUtils.closeQuietly(inputStream); Map<String, Integer> result = new TreeMap<>(); for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); if (!line.trim().isEmpty() && !line.trim().startsWith("#")) { String[] split = line.split("\\s+"); if (split.length != 2) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected two whitespace-delimited entries but got '" + line + "' (file " + file.getAbsolutePath() + ")"); } String id = split[0].trim(); int value; try { value = Integer.valueOf(split[1]); } catch (NumberFormatException e) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected an integer but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } if (!(value == 0 || value == 1)) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected 0 or 1 but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } result.put(id, value); } } return result; } static Map<String, Integer> readLabelsFromFile(File file); static double computeAccuracy(Map<String, Integer> gold, Map<String, Integer> predictions); static void main(String[] args); }
@Test public void readLabelsFromFile2() throws Exception { Scorer.readLabelsFromFile(getFileFromResources("test-gold2.txt")); }
public static Map<String, Integer> readLabelsFromFile(File file) throws IOException { FileInputStream inputStream = new FileInputStream(file); List<String> lines = IOUtils.readLines(inputStream, UTF8); IOUtils.closeQuietly(inputStream); Map<String, Integer> result = new TreeMap<>(); for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); if (!line.trim().isEmpty() && !line.trim().startsWith("#")) { String[] split = line.split("\\s+"); if (split.length != 2) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected two whitespace-delimited entries but got '" + line + "' (file " + file.getAbsolutePath() + ")"); } String id = split[0].trim(); int value; try { value = Integer.valueOf(split[1]); } catch (NumberFormatException e) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected an integer but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } if (!(value == 0 || value == 1)) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected 0 or 1 but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } result.put(id, value); } } return result; }
Scorer { public static Map<String, Integer> readLabelsFromFile(File file) throws IOException { FileInputStream inputStream = new FileInputStream(file); List<String> lines = IOUtils.readLines(inputStream, UTF8); IOUtils.closeQuietly(inputStream); Map<String, Integer> result = new TreeMap<>(); for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); if (!line.trim().isEmpty() && !line.trim().startsWith("#")) { String[] split = line.split("\\s+"); if (split.length != 2) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected two whitespace-delimited entries but got '" + line + "' (file " + file.getAbsolutePath() + ")"); } String id = split[0].trim(); int value; try { value = Integer.valueOf(split[1]); } catch (NumberFormatException e) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected an integer but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } if (!(value == 0 || value == 1)) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected 0 or 1 but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } result.put(id, value); } } return result; } }
Scorer { public static Map<String, Integer> readLabelsFromFile(File file) throws IOException { FileInputStream inputStream = new FileInputStream(file); List<String> lines = IOUtils.readLines(inputStream, UTF8); IOUtils.closeQuietly(inputStream); Map<String, Integer> result = new TreeMap<>(); for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); if (!line.trim().isEmpty() && !line.trim().startsWith("#")) { String[] split = line.split("\\s+"); if (split.length != 2) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected two whitespace-delimited entries but got '" + line + "' (file " + file.getAbsolutePath() + ")"); } String id = split[0].trim(); int value; try { value = Integer.valueOf(split[1]); } catch (NumberFormatException e) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected an integer but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } if (!(value == 0 || value == 1)) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected 0 or 1 but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } result.put(id, value); } } return result; } }
Scorer { public static Map<String, Integer> readLabelsFromFile(File file) throws IOException { FileInputStream inputStream = new FileInputStream(file); List<String> lines = IOUtils.readLines(inputStream, UTF8); IOUtils.closeQuietly(inputStream); Map<String, Integer> result = new TreeMap<>(); for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); if (!line.trim().isEmpty() && !line.trim().startsWith("#")) { String[] split = line.split("\\s+"); if (split.length != 2) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected two whitespace-delimited entries but got '" + line + "' (file " + file.getAbsolutePath() + ")"); } String id = split[0].trim(); int value; try { value = Integer.valueOf(split[1]); } catch (NumberFormatException e) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected an integer but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } if (!(value == 0 || value == 1)) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected 0 or 1 but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } result.put(id, value); } } return result; } static Map<String, Integer> readLabelsFromFile(File file); static double computeAccuracy(Map<String, Integer> gold, Map<String, Integer> predictions); static void main(String[] args); }
Scorer { public static Map<String, Integer> readLabelsFromFile(File file) throws IOException { FileInputStream inputStream = new FileInputStream(file); List<String> lines = IOUtils.readLines(inputStream, UTF8); IOUtils.closeQuietly(inputStream); Map<String, Integer> result = new TreeMap<>(); for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); if (!line.trim().isEmpty() && !line.trim().startsWith("#")) { String[] split = line.split("\\s+"); if (split.length != 2) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected two whitespace-delimited entries but got '" + line + "' (file " + file.getAbsolutePath() + ")"); } String id = split[0].trim(); int value; try { value = Integer.valueOf(split[1]); } catch (NumberFormatException e) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected an integer but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } if (!(value == 0 || value == 1)) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected 0 or 1 but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } result.put(id, value); } } return result; } static Map<String, Integer> readLabelsFromFile(File file); static double computeAccuracy(Map<String, Integer> gold, Map<String, Integer> predictions); static void main(String[] args); }
@Test(expected = IllegalArgumentException.class) public void readLabelsFromFileWrong1() throws Exception { Scorer.readLabelsFromFile(getFileFromResources("test-wrong1.txt")); }
public static Map<String, Integer> readLabelsFromFile(File file) throws IOException { FileInputStream inputStream = new FileInputStream(file); List<String> lines = IOUtils.readLines(inputStream, UTF8); IOUtils.closeQuietly(inputStream); Map<String, Integer> result = new TreeMap<>(); for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); if (!line.trim().isEmpty() && !line.trim().startsWith("#")) { String[] split = line.split("\\s+"); if (split.length != 2) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected two whitespace-delimited entries but got '" + line + "' (file " + file.getAbsolutePath() + ")"); } String id = split[0].trim(); int value; try { value = Integer.valueOf(split[1]); } catch (NumberFormatException e) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected an integer but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } if (!(value == 0 || value == 1)) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected 0 or 1 but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } result.put(id, value); } } return result; }
Scorer { public static Map<String, Integer> readLabelsFromFile(File file) throws IOException { FileInputStream inputStream = new FileInputStream(file); List<String> lines = IOUtils.readLines(inputStream, UTF8); IOUtils.closeQuietly(inputStream); Map<String, Integer> result = new TreeMap<>(); for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); if (!line.trim().isEmpty() && !line.trim().startsWith("#")) { String[] split = line.split("\\s+"); if (split.length != 2) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected two whitespace-delimited entries but got '" + line + "' (file " + file.getAbsolutePath() + ")"); } String id = split[0].trim(); int value; try { value = Integer.valueOf(split[1]); } catch (NumberFormatException e) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected an integer but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } if (!(value == 0 || value == 1)) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected 0 or 1 but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } result.put(id, value); } } return result; } }
Scorer { public static Map<String, Integer> readLabelsFromFile(File file) throws IOException { FileInputStream inputStream = new FileInputStream(file); List<String> lines = IOUtils.readLines(inputStream, UTF8); IOUtils.closeQuietly(inputStream); Map<String, Integer> result = new TreeMap<>(); for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); if (!line.trim().isEmpty() && !line.trim().startsWith("#")) { String[] split = line.split("\\s+"); if (split.length != 2) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected two whitespace-delimited entries but got '" + line + "' (file " + file.getAbsolutePath() + ")"); } String id = split[0].trim(); int value; try { value = Integer.valueOf(split[1]); } catch (NumberFormatException e) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected an integer but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } if (!(value == 0 || value == 1)) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected 0 or 1 but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } result.put(id, value); } } return result; } }
Scorer { public static Map<String, Integer> readLabelsFromFile(File file) throws IOException { FileInputStream inputStream = new FileInputStream(file); List<String> lines = IOUtils.readLines(inputStream, UTF8); IOUtils.closeQuietly(inputStream); Map<String, Integer> result = new TreeMap<>(); for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); if (!line.trim().isEmpty() && !line.trim().startsWith("#")) { String[] split = line.split("\\s+"); if (split.length != 2) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected two whitespace-delimited entries but got '" + line + "' (file " + file.getAbsolutePath() + ")"); } String id = split[0].trim(); int value; try { value = Integer.valueOf(split[1]); } catch (NumberFormatException e) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected an integer but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } if (!(value == 0 || value == 1)) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected 0 or 1 but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } result.put(id, value); } } return result; } static Map<String, Integer> readLabelsFromFile(File file); static double computeAccuracy(Map<String, Integer> gold, Map<String, Integer> predictions); static void main(String[] args); }
Scorer { public static Map<String, Integer> readLabelsFromFile(File file) throws IOException { FileInputStream inputStream = new FileInputStream(file); List<String> lines = IOUtils.readLines(inputStream, UTF8); IOUtils.closeQuietly(inputStream); Map<String, Integer> result = new TreeMap<>(); for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); if (!line.trim().isEmpty() && !line.trim().startsWith("#")) { String[] split = line.split("\\s+"); if (split.length != 2) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected two whitespace-delimited entries but got '" + line + "' (file " + file.getAbsolutePath() + ")"); } String id = split[0].trim(); int value; try { value = Integer.valueOf(split[1]); } catch (NumberFormatException e) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected an integer but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } if (!(value == 0 || value == 1)) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected 0 or 1 but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } result.put(id, value); } } return result; } static Map<String, Integer> readLabelsFromFile(File file); static double computeAccuracy(Map<String, Integer> gold, Map<String, Integer> predictions); static void main(String[] args); }
@Test(expected = IllegalArgumentException.class) public void readLabelsFromFileWrong2() throws Exception { Scorer.readLabelsFromFile(getFileFromResources("test-wrong2.txt")); }
public static Map<String, Integer> readLabelsFromFile(File file) throws IOException { FileInputStream inputStream = new FileInputStream(file); List<String> lines = IOUtils.readLines(inputStream, UTF8); IOUtils.closeQuietly(inputStream); Map<String, Integer> result = new TreeMap<>(); for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); if (!line.trim().isEmpty() && !line.trim().startsWith("#")) { String[] split = line.split("\\s+"); if (split.length != 2) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected two whitespace-delimited entries but got '" + line + "' (file " + file.getAbsolutePath() + ")"); } String id = split[0].trim(); int value; try { value = Integer.valueOf(split[1]); } catch (NumberFormatException e) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected an integer but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } if (!(value == 0 || value == 1)) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected 0 or 1 but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } result.put(id, value); } } return result; }
Scorer { public static Map<String, Integer> readLabelsFromFile(File file) throws IOException { FileInputStream inputStream = new FileInputStream(file); List<String> lines = IOUtils.readLines(inputStream, UTF8); IOUtils.closeQuietly(inputStream); Map<String, Integer> result = new TreeMap<>(); for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); if (!line.trim().isEmpty() && !line.trim().startsWith("#")) { String[] split = line.split("\\s+"); if (split.length != 2) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected two whitespace-delimited entries but got '" + line + "' (file " + file.getAbsolutePath() + ")"); } String id = split[0].trim(); int value; try { value = Integer.valueOf(split[1]); } catch (NumberFormatException e) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected an integer but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } if (!(value == 0 || value == 1)) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected 0 or 1 but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } result.put(id, value); } } return result; } }
Scorer { public static Map<String, Integer> readLabelsFromFile(File file) throws IOException { FileInputStream inputStream = new FileInputStream(file); List<String> lines = IOUtils.readLines(inputStream, UTF8); IOUtils.closeQuietly(inputStream); Map<String, Integer> result = new TreeMap<>(); for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); if (!line.trim().isEmpty() && !line.trim().startsWith("#")) { String[] split = line.split("\\s+"); if (split.length != 2) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected two whitespace-delimited entries but got '" + line + "' (file " + file.getAbsolutePath() + ")"); } String id = split[0].trim(); int value; try { value = Integer.valueOf(split[1]); } catch (NumberFormatException e) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected an integer but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } if (!(value == 0 || value == 1)) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected 0 or 1 but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } result.put(id, value); } } return result; } }
Scorer { public static Map<String, Integer> readLabelsFromFile(File file) throws IOException { FileInputStream inputStream = new FileInputStream(file); List<String> lines = IOUtils.readLines(inputStream, UTF8); IOUtils.closeQuietly(inputStream); Map<String, Integer> result = new TreeMap<>(); for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); if (!line.trim().isEmpty() && !line.trim().startsWith("#")) { String[] split = line.split("\\s+"); if (split.length != 2) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected two whitespace-delimited entries but got '" + line + "' (file " + file.getAbsolutePath() + ")"); } String id = split[0].trim(); int value; try { value = Integer.valueOf(split[1]); } catch (NumberFormatException e) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected an integer but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } if (!(value == 0 || value == 1)) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected 0 or 1 but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } result.put(id, value); } } return result; } static Map<String, Integer> readLabelsFromFile(File file); static double computeAccuracy(Map<String, Integer> gold, Map<String, Integer> predictions); static void main(String[] args); }
Scorer { public static Map<String, Integer> readLabelsFromFile(File file) throws IOException { FileInputStream inputStream = new FileInputStream(file); List<String> lines = IOUtils.readLines(inputStream, UTF8); IOUtils.closeQuietly(inputStream); Map<String, Integer> result = new TreeMap<>(); for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); if (!line.trim().isEmpty() && !line.trim().startsWith("#")) { String[] split = line.split("\\s+"); if (split.length != 2) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected two whitespace-delimited entries but got '" + line + "' (file " + file.getAbsolutePath() + ")"); } String id = split[0].trim(); int value; try { value = Integer.valueOf(split[1]); } catch (NumberFormatException e) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected an integer but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } if (!(value == 0 || value == 1)) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected 0 or 1 but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } result.put(id, value); } } return result; } static Map<String, Integer> readLabelsFromFile(File file); static double computeAccuracy(Map<String, Integer> gold, Map<String, Integer> predictions); static void main(String[] args); }
@Test(expected = IllegalArgumentException.class) public void readLabelsFromFileWrong3() throws Exception { Scorer.readLabelsFromFile(getFileFromResources("test-wrong3.txt")); }
public static Map<String, Integer> readLabelsFromFile(File file) throws IOException { FileInputStream inputStream = new FileInputStream(file); List<String> lines = IOUtils.readLines(inputStream, UTF8); IOUtils.closeQuietly(inputStream); Map<String, Integer> result = new TreeMap<>(); for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); if (!line.trim().isEmpty() && !line.trim().startsWith("#")) { String[] split = line.split("\\s+"); if (split.length != 2) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected two whitespace-delimited entries but got '" + line + "' (file " + file.getAbsolutePath() + ")"); } String id = split[0].trim(); int value; try { value = Integer.valueOf(split[1]); } catch (NumberFormatException e) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected an integer but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } if (!(value == 0 || value == 1)) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected 0 or 1 but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } result.put(id, value); } } return result; }
Scorer { public static Map<String, Integer> readLabelsFromFile(File file) throws IOException { FileInputStream inputStream = new FileInputStream(file); List<String> lines = IOUtils.readLines(inputStream, UTF8); IOUtils.closeQuietly(inputStream); Map<String, Integer> result = new TreeMap<>(); for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); if (!line.trim().isEmpty() && !line.trim().startsWith("#")) { String[] split = line.split("\\s+"); if (split.length != 2) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected two whitespace-delimited entries but got '" + line + "' (file " + file.getAbsolutePath() + ")"); } String id = split[0].trim(); int value; try { value = Integer.valueOf(split[1]); } catch (NumberFormatException e) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected an integer but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } if (!(value == 0 || value == 1)) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected 0 or 1 but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } result.put(id, value); } } return result; } }
Scorer { public static Map<String, Integer> readLabelsFromFile(File file) throws IOException { FileInputStream inputStream = new FileInputStream(file); List<String> lines = IOUtils.readLines(inputStream, UTF8); IOUtils.closeQuietly(inputStream); Map<String, Integer> result = new TreeMap<>(); for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); if (!line.trim().isEmpty() && !line.trim().startsWith("#")) { String[] split = line.split("\\s+"); if (split.length != 2) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected two whitespace-delimited entries but got '" + line + "' (file " + file.getAbsolutePath() + ")"); } String id = split[0].trim(); int value; try { value = Integer.valueOf(split[1]); } catch (NumberFormatException e) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected an integer but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } if (!(value == 0 || value == 1)) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected 0 or 1 but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } result.put(id, value); } } return result; } }
Scorer { public static Map<String, Integer> readLabelsFromFile(File file) throws IOException { FileInputStream inputStream = new FileInputStream(file); List<String> lines = IOUtils.readLines(inputStream, UTF8); IOUtils.closeQuietly(inputStream); Map<String, Integer> result = new TreeMap<>(); for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); if (!line.trim().isEmpty() && !line.trim().startsWith("#")) { String[] split = line.split("\\s+"); if (split.length != 2) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected two whitespace-delimited entries but got '" + line + "' (file " + file.getAbsolutePath() + ")"); } String id = split[0].trim(); int value; try { value = Integer.valueOf(split[1]); } catch (NumberFormatException e) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected an integer but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } if (!(value == 0 || value == 1)) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected 0 or 1 but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } result.put(id, value); } } return result; } static Map<String, Integer> readLabelsFromFile(File file); static double computeAccuracy(Map<String, Integer> gold, Map<String, Integer> predictions); static void main(String[] args); }
Scorer { public static Map<String, Integer> readLabelsFromFile(File file) throws IOException { FileInputStream inputStream = new FileInputStream(file); List<String> lines = IOUtils.readLines(inputStream, UTF8); IOUtils.closeQuietly(inputStream); Map<String, Integer> result = new TreeMap<>(); for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); if (!line.trim().isEmpty() && !line.trim().startsWith("#")) { String[] split = line.split("\\s+"); if (split.length != 2) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected two whitespace-delimited entries but got '" + line + "' (file " + file.getAbsolutePath() + ")"); } String id = split[0].trim(); int value; try { value = Integer.valueOf(split[1]); } catch (NumberFormatException e) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected an integer but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } if (!(value == 0 || value == 1)) { throw new IllegalArgumentException("Error on line " + (i + 1) + ", expected 0 or 1 but got '" + split[1] + "' (file " + file.getAbsolutePath() + ")"); } result.put(id, value); } } return result; } static Map<String, Integer> readLabelsFromFile(File file); static double computeAccuracy(Map<String, Integer> gold, Map<String, Integer> predictions); static void main(String[] args); }
@Test public void computeAccuracy() throws Exception { Map<String, Integer> gold = Scorer .readLabelsFromFile(getFileFromResources("test-gold1.txt")); Map<String, Integer> predictions1 = Scorer .readLabelsFromFile(getFileFromResources("test-predictions1.txt")); assertEquals(0.6, Scorer.computeAccuracy(gold, predictions1), 0.01); Map<String, Integer> predictions2 = Scorer .readLabelsFromFile(getFileFromResources("test-predictions2.txt")); assertEquals(1.0, Scorer.computeAccuracy(gold, predictions2), 0.01); Map<String, Integer> predictions3 = Scorer .readLabelsFromFile(getFileFromResources("test-predictions3.txt")); assertEquals(0.0, Scorer.computeAccuracy(gold, predictions3), 0.01); }
public static double computeAccuracy(Map<String, Integer> gold, Map<String, Integer> predictions) throws IllegalArgumentException { if (gold == null) { throw new IllegalArgumentException("Parameter 'gold' is null"); } if (predictions == null) { throw new IllegalArgumentException("Parameter 'predictions' is null"); } if (gold.isEmpty()) { throw new IllegalArgumentException("Parameter 'gold' is an empty map"); } if (predictions.isEmpty()) { throw new IllegalArgumentException("Parameter 'predictions' is an empty map"); } if (!(gold.keySet().containsAll(predictions.keySet()) && predictions.keySet() .containsAll(gold.keySet()))) { throw new IllegalArgumentException( "Gold set and predictions contain different instance IDs"); } Set<String> correctPredictions = new TreeSet<>(); Set<String> wrongPredictions = new TreeSet<>(); for (String id : gold.keySet()) { int goldLabel = gold.get(id); int predictedLabel = predictions.get(id); if (goldLabel == predictedLabel) { correctPredictions.add(id); } else { wrongPredictions.add(id); } } return ((double) correctPredictions.size()) / ((double) correctPredictions.size() + wrongPredictions.size()); }
Scorer { public static double computeAccuracy(Map<String, Integer> gold, Map<String, Integer> predictions) throws IllegalArgumentException { if (gold == null) { throw new IllegalArgumentException("Parameter 'gold' is null"); } if (predictions == null) { throw new IllegalArgumentException("Parameter 'predictions' is null"); } if (gold.isEmpty()) { throw new IllegalArgumentException("Parameter 'gold' is an empty map"); } if (predictions.isEmpty()) { throw new IllegalArgumentException("Parameter 'predictions' is an empty map"); } if (!(gold.keySet().containsAll(predictions.keySet()) && predictions.keySet() .containsAll(gold.keySet()))) { throw new IllegalArgumentException( "Gold set and predictions contain different instance IDs"); } Set<String> correctPredictions = new TreeSet<>(); Set<String> wrongPredictions = new TreeSet<>(); for (String id : gold.keySet()) { int goldLabel = gold.get(id); int predictedLabel = predictions.get(id); if (goldLabel == predictedLabel) { correctPredictions.add(id); } else { wrongPredictions.add(id); } } return ((double) correctPredictions.size()) / ((double) correctPredictions.size() + wrongPredictions.size()); } }
Scorer { public static double computeAccuracy(Map<String, Integer> gold, Map<String, Integer> predictions) throws IllegalArgumentException { if (gold == null) { throw new IllegalArgumentException("Parameter 'gold' is null"); } if (predictions == null) { throw new IllegalArgumentException("Parameter 'predictions' is null"); } if (gold.isEmpty()) { throw new IllegalArgumentException("Parameter 'gold' is an empty map"); } if (predictions.isEmpty()) { throw new IllegalArgumentException("Parameter 'predictions' is an empty map"); } if (!(gold.keySet().containsAll(predictions.keySet()) && predictions.keySet() .containsAll(gold.keySet()))) { throw new IllegalArgumentException( "Gold set and predictions contain different instance IDs"); } Set<String> correctPredictions = new TreeSet<>(); Set<String> wrongPredictions = new TreeSet<>(); for (String id : gold.keySet()) { int goldLabel = gold.get(id); int predictedLabel = predictions.get(id); if (goldLabel == predictedLabel) { correctPredictions.add(id); } else { wrongPredictions.add(id); } } return ((double) correctPredictions.size()) / ((double) correctPredictions.size() + wrongPredictions.size()); } }
Scorer { public static double computeAccuracy(Map<String, Integer> gold, Map<String, Integer> predictions) throws IllegalArgumentException { if (gold == null) { throw new IllegalArgumentException("Parameter 'gold' is null"); } if (predictions == null) { throw new IllegalArgumentException("Parameter 'predictions' is null"); } if (gold.isEmpty()) { throw new IllegalArgumentException("Parameter 'gold' is an empty map"); } if (predictions.isEmpty()) { throw new IllegalArgumentException("Parameter 'predictions' is an empty map"); } if (!(gold.keySet().containsAll(predictions.keySet()) && predictions.keySet() .containsAll(gold.keySet()))) { throw new IllegalArgumentException( "Gold set and predictions contain different instance IDs"); } Set<String> correctPredictions = new TreeSet<>(); Set<String> wrongPredictions = new TreeSet<>(); for (String id : gold.keySet()) { int goldLabel = gold.get(id); int predictedLabel = predictions.get(id); if (goldLabel == predictedLabel) { correctPredictions.add(id); } else { wrongPredictions.add(id); } } return ((double) correctPredictions.size()) / ((double) correctPredictions.size() + wrongPredictions.size()); } static Map<String, Integer> readLabelsFromFile(File file); static double computeAccuracy(Map<String, Integer> gold, Map<String, Integer> predictions); static void main(String[] args); }
Scorer { public static double computeAccuracy(Map<String, Integer> gold, Map<String, Integer> predictions) throws IllegalArgumentException { if (gold == null) { throw new IllegalArgumentException("Parameter 'gold' is null"); } if (predictions == null) { throw new IllegalArgumentException("Parameter 'predictions' is null"); } if (gold.isEmpty()) { throw new IllegalArgumentException("Parameter 'gold' is an empty map"); } if (predictions.isEmpty()) { throw new IllegalArgumentException("Parameter 'predictions' is an empty map"); } if (!(gold.keySet().containsAll(predictions.keySet()) && predictions.keySet() .containsAll(gold.keySet()))) { throw new IllegalArgumentException( "Gold set and predictions contain different instance IDs"); } Set<String> correctPredictions = new TreeSet<>(); Set<String> wrongPredictions = new TreeSet<>(); for (String id : gold.keySet()) { int goldLabel = gold.get(id); int predictedLabel = predictions.get(id); if (goldLabel == predictedLabel) { correctPredictions.add(id); } else { wrongPredictions.add(id); } } return ((double) correctPredictions.size()) / ((double) correctPredictions.size() + wrongPredictions.size()); } static Map<String, Integer> readLabelsFromFile(File file); static double computeAccuracy(Map<String, Integer> gold, Map<String, Integer> predictions); static void main(String[] args); }
@Test public void getDOI_inInput_shouldWork() { String input = "{\"reference-count\":176,\"publisher\":\"IOP Publishing\",\"issue\":\"4\",\"content-domain\":{\"domain\":[],\"crossmark-restriction\":false},\"short-container-title\":[\"Russ. Chem. Rev.\"],\"published-print\":{\"date-parts\":[[1998,4,30]]},\"DOI\":\"10.1070/rc1998v067n04abeh000372\",\"type\":\"journal-article\",\"created\":{\"date-parts\":[[2002,8,24]],\"date-time\":\"2002-08-24T21:29:52Z\",\"timestamp\":{\"$numberLong\":\"1030224592000\"}},\"page\":\"279-293\",\"source\":\"Crossref\",\"is-referenced-by-count\":24,\"title\":[\"Haloalkenes activated by geminal groups in reactions with N-nucleophiles\"],\"prefix\":\"10.1070\",\"volume\":\"67\",\"author\":[{\"given\":\"Alexander Yu\",\"family\":\"Rulev\",\"sequence\":\"first\",\"affiliation\":[]}],\"member\":\"266\",\"published-online\":{\"date-parts\":[[2007,10,17]]},\"container-title\":[\"Russian Chemical Reviews\"],\"deposited\":{\"date-parts\":[[2017,11,23]],\"date-time\":\"2017-11-23T03:38:45Z\",\"timestamp\":{\"$numberLong\":\"1511408325000\"}},\"score\":1,\"issued\":{\"date-parts\":[[1998,4,30]]},\"references-count\":176,\"journal-issue\":{\"published-print\":{\"date-parts\":[[1998,4,30]]},\"issue\":\"4\"},\"URL\":\"http: String doi = "10.1070/rc1998v067n04abeh000372"; String output = target.fetchDOI(input); assertThat(output, is(doi)); }
public String fetchDOI(String input) { Matcher doiMatcher = DOIPattern.matcher(input); while (doiMatcher.find()) { if (doiMatcher.groupCount() == 1) { return doiMatcher.group(1); } } return null; }
LookupEngine { public String fetchDOI(String input) { Matcher doiMatcher = DOIPattern.matcher(input); while (doiMatcher.find()) { if (doiMatcher.groupCount() == 1) { return doiMatcher.group(1); } } return null; } }
LookupEngine { public String fetchDOI(String input) { Matcher doiMatcher = DOIPattern.matcher(input); while (doiMatcher.find()) { if (doiMatcher.groupCount() == 1) { return doiMatcher.group(1); } } return null; } LookupEngine(); LookupEngine(StorageEnvFactory storageFactory); }
LookupEngine { public String fetchDOI(String input) { Matcher doiMatcher = DOIPattern.matcher(input); while (doiMatcher.find()) { if (doiMatcher.groupCount() == 1) { return doiMatcher.group(1); } } return null; } LookupEngine(); LookupEngine(StorageEnvFactory storageFactory); String retrieveByArticleMetadata(String title, String firstAuthor, Boolean postValidate); void retrieveByArticleMetadataAsync(String title, String firstAuthor, Boolean postValidate, Consumer<MatchingDocument> callback); String retrieveByJournalMetadata(String title, String volume, String firstPage); void retrieveByJournalMetadataAsync(String jtitle, String volume, String firstPage, String atitle, String firstAuthor, Boolean postValidate, Consumer<MatchingDocument> callback); void retrieveByJournalMetadataAsync(String jtitle, String volume, String firstPage, Consumer<MatchingDocument> callback); String retrieveByJournalMetadata(String title, String volume, String firstPage, String firstAuthor); void retrieveByJournalMetadataAsync(String title, String volume, String firstPage, String firstAuthor, Consumer<MatchingDocument> callback); String retrieveByDoi(String doi, Boolean postValidate, String firstAuthor, String atitle); String retrieveByPmid(String pmid, Boolean postValidate, String firstAuthor, String atitle); String retrieveByPmc(String pmc, Boolean postValidate, String firstAuthor, String atitle); String retrieveByIstexid(String istexid, Boolean postValidate, String firstAuthor, String atitle); String retrieveByPii(String pii, Boolean postValidate, String firstAuthor, String atitle); PmidData retrievePMidsByDoi(String doi); PmidData retrievePMidsByPmid(String pmid); PmidData retrievePMidsByPmc(String pmc); IstexData retrieveIstexIdsByDoi(String doi); IstexData retrieveIstexIdsByIstexId(String istexId); String retrieveOAUrlByDoi(String doi); Pair<String,String> retrieveOaIstexUrlByDoi(String doi); String retrieveOAUrlByPmid(String pmid); Pair<String,String> retrieveOaIstexUrlByPmid(String pmid); String retrieveOAUrlByPmc(String pmc); Pair<String,String> retrieveOaIstexUrlByPmc(String pmc); String retrieveOAUrlByPii(String pii); Pair<String,String> retrieveOaIstexUrlByPii(String pii); String retrieveByBiblio(String biblio); void retrieveByBiblioAsync(String biblio, Boolean postValidate, String firstAuthor, String title, Boolean parseReference, Consumer<MatchingDocument> callback); void retrieveByBiblioAsync(String biblio, Consumer<MatchingDocument> callback); String fetchDOI(String input); void setMetadataMatching(MetadataMatching metadataMatching); void setOaDoiLookup(OALookup oaDoiLookup); void setIstexLookup(IstexIdsLookup istexLookup); void setMetadataLookup(MetadataLookup metadataLookup); void setPmidLookup(PMIdsLookup pmidLookup); void setGrobidClient(GrobidClient grobidClient); }
LookupEngine { public String fetchDOI(String input) { Matcher doiMatcher = DOIPattern.matcher(input); while (doiMatcher.find()) { if (doiMatcher.groupCount() == 1) { return doiMatcher.group(1); } } return null; } LookupEngine(); LookupEngine(StorageEnvFactory storageFactory); String retrieveByArticleMetadata(String title, String firstAuthor, Boolean postValidate); void retrieveByArticleMetadataAsync(String title, String firstAuthor, Boolean postValidate, Consumer<MatchingDocument> callback); String retrieveByJournalMetadata(String title, String volume, String firstPage); void retrieveByJournalMetadataAsync(String jtitle, String volume, String firstPage, String atitle, String firstAuthor, Boolean postValidate, Consumer<MatchingDocument> callback); void retrieveByJournalMetadataAsync(String jtitle, String volume, String firstPage, Consumer<MatchingDocument> callback); String retrieveByJournalMetadata(String title, String volume, String firstPage, String firstAuthor); void retrieveByJournalMetadataAsync(String title, String volume, String firstPage, String firstAuthor, Consumer<MatchingDocument> callback); String retrieveByDoi(String doi, Boolean postValidate, String firstAuthor, String atitle); String retrieveByPmid(String pmid, Boolean postValidate, String firstAuthor, String atitle); String retrieveByPmc(String pmc, Boolean postValidate, String firstAuthor, String atitle); String retrieveByIstexid(String istexid, Boolean postValidate, String firstAuthor, String atitle); String retrieveByPii(String pii, Boolean postValidate, String firstAuthor, String atitle); PmidData retrievePMidsByDoi(String doi); PmidData retrievePMidsByPmid(String pmid); PmidData retrievePMidsByPmc(String pmc); IstexData retrieveIstexIdsByDoi(String doi); IstexData retrieveIstexIdsByIstexId(String istexId); String retrieveOAUrlByDoi(String doi); Pair<String,String> retrieveOaIstexUrlByDoi(String doi); String retrieveOAUrlByPmid(String pmid); Pair<String,String> retrieveOaIstexUrlByPmid(String pmid); String retrieveOAUrlByPmc(String pmc); Pair<String,String> retrieveOaIstexUrlByPmc(String pmc); String retrieveOAUrlByPii(String pii); Pair<String,String> retrieveOaIstexUrlByPii(String pii); String retrieveByBiblio(String biblio); void retrieveByBiblioAsync(String biblio, Boolean postValidate, String firstAuthor, String title, Boolean parseReference, Consumer<MatchingDocument> callback); void retrieveByBiblioAsync(String biblio, Consumer<MatchingDocument> callback); String fetchDOI(String input); void setMetadataMatching(MetadataMatching metadataMatching); void setOaDoiLookup(OALookup oaDoiLookup); void setIstexLookup(IstexIdsLookup istexLookup); void setMetadataLookup(MetadataLookup metadataLookup); void setPmidLookup(PMIdsLookup pmidLookup); void setGrobidClient(GrobidClient grobidClient); static Pattern DOIPattern; }
@Test public void getByQuery_DOIexists_WithPostvalidation_shouldReturnJSONFromTitleFirstAuthor() { final String myDOI = "myDOI"; final boolean postValidate = true; final String atitle = "atitle"; final String firstAuthor = "firstAuthor"; final String jsonOutput = "{\"DOI\":\"" + myDOI + "\",\"title\":[\"" + atitle + "12312312313\"],\"author\":[{\"given\":\"Alexander Yu\",\"family\":\"" + firstAuthor + "\",\"sequence\":\"first\",\"affiliation\":[]}]}"; final MatchingDocument response = new MatchingDocument(myDOI, jsonOutput); expect(mockMetadataLookup.retrieveByMetadata(myDOI)).andReturn(new MatchingDocument()); mockMetadataMatching.retrieveByMetadataAsync(eq(atitle), eq(firstAuthor), anyObject()); replay(mockMetadataLookup, mockedAsyncResponse, mockPmidsLookup, mockOALookup, mockIstexLookup, mockMetadataMatching); target.getByQuery(myDOI, null, null, null, null, firstAuthor, atitle, postValidate, null, null, null, null, null, mockedAsyncResponse); verify(mockMetadataLookup, mockedAsyncResponse, mockPmidsLookup, mockOALookup, mockIstexLookup, mockMetadataMatching); }
protected void getByQuery( String doi, String pmid, String pmc, String pii, String istexid, String firstAuthor, String atitle, final Boolean postValidate, String jtitle, String volume, String firstPage, String biblio, final Boolean parseReference, AsyncResponse asyncResponse ) { boolean areParametersEnoughToLookup = false; StringBuilder messagesSb = new StringBuilder(); if (isNotBlank(doi)) { areParametersEnoughToLookup = true; try { final String response = lookupEngine.retrieveByDoi(doi, postValidate, firstAuthor, atitle); if (isNotBlank(response)) { asyncResponse.resume(response); return; } } catch (NotFoundException e) { messagesSb.append(e.getMessage()); LOGGER.warn("DOI did not matched, move to additional metadata"); } } if (isNotBlank(pmid)) { areParametersEnoughToLookup = true; try { final String response = lookupEngine.retrieveByPmid(pmid, postValidate, firstAuthor, atitle); if (isNotBlank(response)) { asyncResponse.resume(response); return; } } catch (NotFoundException e) { LOGGER.warn("PMID did not matched, move to additional metadata"); } } if (isNotBlank(pmc)) { areParametersEnoughToLookup = true; try { final String response = lookupEngine.retrieveByPmc(pmc, postValidate, firstAuthor, atitle); if (isNotBlank(response)) { asyncResponse.resume(response); return; } } catch (NotFoundException e) { LOGGER.warn("PMC ID did not matched, move to additional metadata"); } } if (isNotBlank(pii)) { areParametersEnoughToLookup = true; try { final String response = lookupEngine.retrieveByPii(pii, postValidate, firstAuthor, atitle); if (isNotBlank(response)) { asyncResponse.resume(response); return; } } catch (NotFoundException e) { LOGGER.warn("PII ID did not matched, move to additional metadata"); } } if (isNotBlank(istexid)) { areParametersEnoughToLookup = true; try { final String response = lookupEngine.retrieveByIstexid(istexid, postValidate, firstAuthor, atitle); if (isNotBlank(response)) { asyncResponse.resume(response); return; } } catch (NotFoundException e) { LOGGER.warn("ISTEX ID did not matched, move to additional metadata"); } } if (isNotBlank(atitle) && isNotBlank(firstAuthor)) { LOGGER.debug("Match with metadata"); lookupEngine.retrieveByArticleMetadataAsync(atitle, firstAuthor, postValidate, matchingDocument -> { if (matchingDocument.isException()) { LOGGER.debug("Error with title/first author, trying to match with journal infos (no first author)"); if (isNotBlank(jtitle) && isNotBlank(volume) && isNotBlank(firstPage)) { lookupEngine.retrieveByJournalMetadataAsync(jtitle, volume, firstPage, atitle, firstAuthor, postValidate, matchingDocumentJournal -> { if (matchingDocumentJournal.isException()) { LOGGER.debug("Error with journal title, trying to match with biblio string"); if (isNotBlank(biblio)) { lookupEngine.retrieveByBiblioAsync(biblio, postValidate, firstAuthor, atitle, parseReference, MatchingDocumentBiblio -> { if (MatchingDocumentBiblio.isException()) { asyncResponse.resume(MatchingDocumentBiblio.getException()); } else { asyncResponse.resume(MatchingDocumentBiblio.getFinalJsonObject()); } }); return; } else { asyncResponse.resume(matchingDocument.getException()); } } else { asyncResponse.resume(matchingDocumentJournal.getFinalJsonObject()); } }); return; } LOGGER.debug("Error with title/first author, trying to match with journal infos (with first author)"); if (isNotBlank(jtitle) && isNotBlank(volume) && isNotBlank(firstPage)) { lookupEngine.retrieveByJournalMetadataAsync(jtitle, volume, firstPage, atitle, firstAuthor, postValidate, matchingDocumentJournal -> { if (matchingDocumentJournal.isException()) { LOGGER.debug("Error with journal info, trying to match with biblio string"); if (isNotBlank(biblio)) { lookupEngine.retrieveByBiblioAsync(biblio, postValidate, firstAuthor, atitle, parseReference, matchingDocumentBiblio -> { if (matchingDocumentBiblio.isException()) { asyncResponse.resume(matchingDocumentBiblio.getException()); } else { asyncResponse.resume(matchingDocumentBiblio.getFinalJsonObject()); } }); return; } else { asyncResponse.resume(matchingDocument.getException()); } } else { asyncResponse.resume(matchingDocumentJournal.getFinalJsonObject()); } }); return; } LOGGER.debug("Error with title/first author, trying to match with biblio string"); if (isNotBlank(biblio)) { lookupEngine.retrieveByBiblioAsync(biblio, postValidate, firstAuthor, atitle, parseReference, matchingDocumentBiblio -> { if (matchingDocumentBiblio.isException()) { asyncResponse.resume(matchingDocumentBiblio.getException()); } else { asyncResponse.resume(matchingDocumentBiblio.getFinalJsonObject()); } }); return; } else { asyncResponse.resume(matchingDocument.getException()); } } else { asyncResponse.resume(matchingDocument.getFinalJsonObject()); } }); return; } if (isNotBlank(jtitle) && isNotBlank(firstAuthor) && isNotBlank(volume) && isNotBlank(firstPage)) { LOGGER.debug("Match with journal title and first page"); lookupEngine.retrieveByJournalMetadataAsync(jtitle, volume, firstPage, atitle, firstAuthor, postValidate, matchingDocument -> { if (matchingDocument.isException()) { if (isNotBlank(biblio)) { lookupEngine.retrieveByBiblioAsync(biblio, postValidate, firstAuthor, atitle, parseReference, matchingDocumentBiblio -> { if (matchingDocumentBiblio.isException()) { asyncResponse.resume(matchingDocumentBiblio.getException()); } else { asyncResponse.resume(matchingDocumentBiblio.getFinalJsonObject()); } }); return; } else { asyncResponse.resume(matchingDocument.getException()); } } else { asyncResponse.resume(matchingDocument.getFinalJsonObject()); } }); return; } if (isNotBlank(jtitle) && isNotBlank(volume) && isNotBlank(firstPage)) { LOGGER.debug("Match with journal title without first author"); lookupEngine.retrieveByJournalMetadataAsync(jtitle, volume, firstPage, atitle, firstAuthor, postValidate, matchingDocument -> { if (matchingDocument.isException()) { if (isNotBlank(biblio)) { lookupEngine.retrieveByBiblioAsync(biblio, postValidate, firstAuthor, atitle, parseReference, matchingDocumentBiblio -> { if (matchingDocumentBiblio.isException()) { asyncResponse.resume(matchingDocumentBiblio.getException()); } else { asyncResponse.resume(matchingDocumentBiblio.getFinalJsonObject()); } }); return; } else { asyncResponse.resume(matchingDocument.getException()); } } else { asyncResponse.resume(matchingDocument.getFinalJsonObject()); } }); return; } if (isNotBlank(biblio)) { LOGGER.debug("Match with biblio string"); lookupEngine.retrieveByBiblioAsync(biblio, postValidate, firstAuthor, atitle, parseReference, matchingDocumentBiblio -> { if (matchingDocumentBiblio.isException()) { asyncResponse.resume(matchingDocumentBiblio.getException()); } else { asyncResponse.resume(matchingDocumentBiblio.getFinalJsonObject()); } }); return; } if (areParametersEnoughToLookup) { throw new ServiceException(404, messagesSb.toString()); } else { throw new ServiceException(400, "The supplied parameters were not sufficient to select the query"); } }
LookupController { protected void getByQuery( String doi, String pmid, String pmc, String pii, String istexid, String firstAuthor, String atitle, final Boolean postValidate, String jtitle, String volume, String firstPage, String biblio, final Boolean parseReference, AsyncResponse asyncResponse ) { boolean areParametersEnoughToLookup = false; StringBuilder messagesSb = new StringBuilder(); if (isNotBlank(doi)) { areParametersEnoughToLookup = true; try { final String response = lookupEngine.retrieveByDoi(doi, postValidate, firstAuthor, atitle); if (isNotBlank(response)) { asyncResponse.resume(response); return; } } catch (NotFoundException e) { messagesSb.append(e.getMessage()); LOGGER.warn("DOI did not matched, move to additional metadata"); } } if (isNotBlank(pmid)) { areParametersEnoughToLookup = true; try { final String response = lookupEngine.retrieveByPmid(pmid, postValidate, firstAuthor, atitle); if (isNotBlank(response)) { asyncResponse.resume(response); return; } } catch (NotFoundException e) { LOGGER.warn("PMID did not matched, move to additional metadata"); } } if (isNotBlank(pmc)) { areParametersEnoughToLookup = true; try { final String response = lookupEngine.retrieveByPmc(pmc, postValidate, firstAuthor, atitle); if (isNotBlank(response)) { asyncResponse.resume(response); return; } } catch (NotFoundException e) { LOGGER.warn("PMC ID did not matched, move to additional metadata"); } } if (isNotBlank(pii)) { areParametersEnoughToLookup = true; try { final String response = lookupEngine.retrieveByPii(pii, postValidate, firstAuthor, atitle); if (isNotBlank(response)) { asyncResponse.resume(response); return; } } catch (NotFoundException e) { LOGGER.warn("PII ID did not matched, move to additional metadata"); } } if (isNotBlank(istexid)) { areParametersEnoughToLookup = true; try { final String response = lookupEngine.retrieveByIstexid(istexid, postValidate, firstAuthor, atitle); if (isNotBlank(response)) { asyncResponse.resume(response); return; } } catch (NotFoundException e) { LOGGER.warn("ISTEX ID did not matched, move to additional metadata"); } } if (isNotBlank(atitle) && isNotBlank(firstAuthor)) { LOGGER.debug("Match with metadata"); lookupEngine.retrieveByArticleMetadataAsync(atitle, firstAuthor, postValidate, matchingDocument -> { if (matchingDocument.isException()) { LOGGER.debug("Error with title/first author, trying to match with journal infos (no first author)"); if (isNotBlank(jtitle) && isNotBlank(volume) && isNotBlank(firstPage)) { lookupEngine.retrieveByJournalMetadataAsync(jtitle, volume, firstPage, atitle, firstAuthor, postValidate, matchingDocumentJournal -> { if (matchingDocumentJournal.isException()) { LOGGER.debug("Error with journal title, trying to match with biblio string"); if (isNotBlank(biblio)) { lookupEngine.retrieveByBiblioAsync(biblio, postValidate, firstAuthor, atitle, parseReference, MatchingDocumentBiblio -> { if (MatchingDocumentBiblio.isException()) { asyncResponse.resume(MatchingDocumentBiblio.getException()); } else { asyncResponse.resume(MatchingDocumentBiblio.getFinalJsonObject()); } }); return; } else { asyncResponse.resume(matchingDocument.getException()); } } else { asyncResponse.resume(matchingDocumentJournal.getFinalJsonObject()); } }); return; } LOGGER.debug("Error with title/first author, trying to match with journal infos (with first author)"); if (isNotBlank(jtitle) && isNotBlank(volume) && isNotBlank(firstPage)) { lookupEngine.retrieveByJournalMetadataAsync(jtitle, volume, firstPage, atitle, firstAuthor, postValidate, matchingDocumentJournal -> { if (matchingDocumentJournal.isException()) { LOGGER.debug("Error with journal info, trying to match with biblio string"); if (isNotBlank(biblio)) { lookupEngine.retrieveByBiblioAsync(biblio, postValidate, firstAuthor, atitle, parseReference, matchingDocumentBiblio -> { if (matchingDocumentBiblio.isException()) { asyncResponse.resume(matchingDocumentBiblio.getException()); } else { asyncResponse.resume(matchingDocumentBiblio.getFinalJsonObject()); } }); return; } else { asyncResponse.resume(matchingDocument.getException()); } } else { asyncResponse.resume(matchingDocumentJournal.getFinalJsonObject()); } }); return; } LOGGER.debug("Error with title/first author, trying to match with biblio string"); if (isNotBlank(biblio)) { lookupEngine.retrieveByBiblioAsync(biblio, postValidate, firstAuthor, atitle, parseReference, matchingDocumentBiblio -> { if (matchingDocumentBiblio.isException()) { asyncResponse.resume(matchingDocumentBiblio.getException()); } else { asyncResponse.resume(matchingDocumentBiblio.getFinalJsonObject()); } }); return; } else { asyncResponse.resume(matchingDocument.getException()); } } else { asyncResponse.resume(matchingDocument.getFinalJsonObject()); } }); return; } if (isNotBlank(jtitle) && isNotBlank(firstAuthor) && isNotBlank(volume) && isNotBlank(firstPage)) { LOGGER.debug("Match with journal title and first page"); lookupEngine.retrieveByJournalMetadataAsync(jtitle, volume, firstPage, atitle, firstAuthor, postValidate, matchingDocument -> { if (matchingDocument.isException()) { if (isNotBlank(biblio)) { lookupEngine.retrieveByBiblioAsync(biblio, postValidate, firstAuthor, atitle, parseReference, matchingDocumentBiblio -> { if (matchingDocumentBiblio.isException()) { asyncResponse.resume(matchingDocumentBiblio.getException()); } else { asyncResponse.resume(matchingDocumentBiblio.getFinalJsonObject()); } }); return; } else { asyncResponse.resume(matchingDocument.getException()); } } else { asyncResponse.resume(matchingDocument.getFinalJsonObject()); } }); return; } if (isNotBlank(jtitle) && isNotBlank(volume) && isNotBlank(firstPage)) { LOGGER.debug("Match with journal title without first author"); lookupEngine.retrieveByJournalMetadataAsync(jtitle, volume, firstPage, atitle, firstAuthor, postValidate, matchingDocument -> { if (matchingDocument.isException()) { if (isNotBlank(biblio)) { lookupEngine.retrieveByBiblioAsync(biblio, postValidate, firstAuthor, atitle, parseReference, matchingDocumentBiblio -> { if (matchingDocumentBiblio.isException()) { asyncResponse.resume(matchingDocumentBiblio.getException()); } else { asyncResponse.resume(matchingDocumentBiblio.getFinalJsonObject()); } }); return; } else { asyncResponse.resume(matchingDocument.getException()); } } else { asyncResponse.resume(matchingDocument.getFinalJsonObject()); } }); return; } if (isNotBlank(biblio)) { LOGGER.debug("Match with biblio string"); lookupEngine.retrieveByBiblioAsync(biblio, postValidate, firstAuthor, atitle, parseReference, matchingDocumentBiblio -> { if (matchingDocumentBiblio.isException()) { asyncResponse.resume(matchingDocumentBiblio.getException()); } else { asyncResponse.resume(matchingDocumentBiblio.getFinalJsonObject()); } }); return; } if (areParametersEnoughToLookup) { throw new ServiceException(404, messagesSb.toString()); } else { throw new ServiceException(400, "The supplied parameters were not sufficient to select the query"); } } }
LookupController { protected void getByQuery( String doi, String pmid, String pmc, String pii, String istexid, String firstAuthor, String atitle, final Boolean postValidate, String jtitle, String volume, String firstPage, String biblio, final Boolean parseReference, AsyncResponse asyncResponse ) { boolean areParametersEnoughToLookup = false; StringBuilder messagesSb = new StringBuilder(); if (isNotBlank(doi)) { areParametersEnoughToLookup = true; try { final String response = lookupEngine.retrieveByDoi(doi, postValidate, firstAuthor, atitle); if (isNotBlank(response)) { asyncResponse.resume(response); return; } } catch (NotFoundException e) { messagesSb.append(e.getMessage()); LOGGER.warn("DOI did not matched, move to additional metadata"); } } if (isNotBlank(pmid)) { areParametersEnoughToLookup = true; try { final String response = lookupEngine.retrieveByPmid(pmid, postValidate, firstAuthor, atitle); if (isNotBlank(response)) { asyncResponse.resume(response); return; } } catch (NotFoundException e) { LOGGER.warn("PMID did not matched, move to additional metadata"); } } if (isNotBlank(pmc)) { areParametersEnoughToLookup = true; try { final String response = lookupEngine.retrieveByPmc(pmc, postValidate, firstAuthor, atitle); if (isNotBlank(response)) { asyncResponse.resume(response); return; } } catch (NotFoundException e) { LOGGER.warn("PMC ID did not matched, move to additional metadata"); } } if (isNotBlank(pii)) { areParametersEnoughToLookup = true; try { final String response = lookupEngine.retrieveByPii(pii, postValidate, firstAuthor, atitle); if (isNotBlank(response)) { asyncResponse.resume(response); return; } } catch (NotFoundException e) { LOGGER.warn("PII ID did not matched, move to additional metadata"); } } if (isNotBlank(istexid)) { areParametersEnoughToLookup = true; try { final String response = lookupEngine.retrieveByIstexid(istexid, postValidate, firstAuthor, atitle); if (isNotBlank(response)) { asyncResponse.resume(response); return; } } catch (NotFoundException e) { LOGGER.warn("ISTEX ID did not matched, move to additional metadata"); } } if (isNotBlank(atitle) && isNotBlank(firstAuthor)) { LOGGER.debug("Match with metadata"); lookupEngine.retrieveByArticleMetadataAsync(atitle, firstAuthor, postValidate, matchingDocument -> { if (matchingDocument.isException()) { LOGGER.debug("Error with title/first author, trying to match with journal infos (no first author)"); if (isNotBlank(jtitle) && isNotBlank(volume) && isNotBlank(firstPage)) { lookupEngine.retrieveByJournalMetadataAsync(jtitle, volume, firstPage, atitle, firstAuthor, postValidate, matchingDocumentJournal -> { if (matchingDocumentJournal.isException()) { LOGGER.debug("Error with journal title, trying to match with biblio string"); if (isNotBlank(biblio)) { lookupEngine.retrieveByBiblioAsync(biblio, postValidate, firstAuthor, atitle, parseReference, MatchingDocumentBiblio -> { if (MatchingDocumentBiblio.isException()) { asyncResponse.resume(MatchingDocumentBiblio.getException()); } else { asyncResponse.resume(MatchingDocumentBiblio.getFinalJsonObject()); } }); return; } else { asyncResponse.resume(matchingDocument.getException()); } } else { asyncResponse.resume(matchingDocumentJournal.getFinalJsonObject()); } }); return; } LOGGER.debug("Error with title/first author, trying to match with journal infos (with first author)"); if (isNotBlank(jtitle) && isNotBlank(volume) && isNotBlank(firstPage)) { lookupEngine.retrieveByJournalMetadataAsync(jtitle, volume, firstPage, atitle, firstAuthor, postValidate, matchingDocumentJournal -> { if (matchingDocumentJournal.isException()) { LOGGER.debug("Error with journal info, trying to match with biblio string"); if (isNotBlank(biblio)) { lookupEngine.retrieveByBiblioAsync(biblio, postValidate, firstAuthor, atitle, parseReference, matchingDocumentBiblio -> { if (matchingDocumentBiblio.isException()) { asyncResponse.resume(matchingDocumentBiblio.getException()); } else { asyncResponse.resume(matchingDocumentBiblio.getFinalJsonObject()); } }); return; } else { asyncResponse.resume(matchingDocument.getException()); } } else { asyncResponse.resume(matchingDocumentJournal.getFinalJsonObject()); } }); return; } LOGGER.debug("Error with title/first author, trying to match with biblio string"); if (isNotBlank(biblio)) { lookupEngine.retrieveByBiblioAsync(biblio, postValidate, firstAuthor, atitle, parseReference, matchingDocumentBiblio -> { if (matchingDocumentBiblio.isException()) { asyncResponse.resume(matchingDocumentBiblio.getException()); } else { asyncResponse.resume(matchingDocumentBiblio.getFinalJsonObject()); } }); return; } else { asyncResponse.resume(matchingDocument.getException()); } } else { asyncResponse.resume(matchingDocument.getFinalJsonObject()); } }); return; } if (isNotBlank(jtitle) && isNotBlank(firstAuthor) && isNotBlank(volume) && isNotBlank(firstPage)) { LOGGER.debug("Match with journal title and first page"); lookupEngine.retrieveByJournalMetadataAsync(jtitle, volume, firstPage, atitle, firstAuthor, postValidate, matchingDocument -> { if (matchingDocument.isException()) { if (isNotBlank(biblio)) { lookupEngine.retrieveByBiblioAsync(biblio, postValidate, firstAuthor, atitle, parseReference, matchingDocumentBiblio -> { if (matchingDocumentBiblio.isException()) { asyncResponse.resume(matchingDocumentBiblio.getException()); } else { asyncResponse.resume(matchingDocumentBiblio.getFinalJsonObject()); } }); return; } else { asyncResponse.resume(matchingDocument.getException()); } } else { asyncResponse.resume(matchingDocument.getFinalJsonObject()); } }); return; } if (isNotBlank(jtitle) && isNotBlank(volume) && isNotBlank(firstPage)) { LOGGER.debug("Match with journal title without first author"); lookupEngine.retrieveByJournalMetadataAsync(jtitle, volume, firstPage, atitle, firstAuthor, postValidate, matchingDocument -> { if (matchingDocument.isException()) { if (isNotBlank(biblio)) { lookupEngine.retrieveByBiblioAsync(biblio, postValidate, firstAuthor, atitle, parseReference, matchingDocumentBiblio -> { if (matchingDocumentBiblio.isException()) { asyncResponse.resume(matchingDocumentBiblio.getException()); } else { asyncResponse.resume(matchingDocumentBiblio.getFinalJsonObject()); } }); return; } else { asyncResponse.resume(matchingDocument.getException()); } } else { asyncResponse.resume(matchingDocument.getFinalJsonObject()); } }); return; } if (isNotBlank(biblio)) { LOGGER.debug("Match with biblio string"); lookupEngine.retrieveByBiblioAsync(biblio, postValidate, firstAuthor, atitle, parseReference, matchingDocumentBiblio -> { if (matchingDocumentBiblio.isException()) { asyncResponse.resume(matchingDocumentBiblio.getException()); } else { asyncResponse.resume(matchingDocumentBiblio.getFinalJsonObject()); } }); return; } if (areParametersEnoughToLookup) { throw new ServiceException(404, messagesSb.toString()); } else { throw new ServiceException(400, "The supplied parameters were not sufficient to select the query"); } } protected LookupController(); @Inject LookupController(LookupConfiguration configuration, StorageEnvFactory storageEnvFactory); }
LookupController { protected void getByQuery( String doi, String pmid, String pmc, String pii, String istexid, String firstAuthor, String atitle, final Boolean postValidate, String jtitle, String volume, String firstPage, String biblio, final Boolean parseReference, AsyncResponse asyncResponse ) { boolean areParametersEnoughToLookup = false; StringBuilder messagesSb = new StringBuilder(); if (isNotBlank(doi)) { areParametersEnoughToLookup = true; try { final String response = lookupEngine.retrieveByDoi(doi, postValidate, firstAuthor, atitle); if (isNotBlank(response)) { asyncResponse.resume(response); return; } } catch (NotFoundException e) { messagesSb.append(e.getMessage()); LOGGER.warn("DOI did not matched, move to additional metadata"); } } if (isNotBlank(pmid)) { areParametersEnoughToLookup = true; try { final String response = lookupEngine.retrieveByPmid(pmid, postValidate, firstAuthor, atitle); if (isNotBlank(response)) { asyncResponse.resume(response); return; } } catch (NotFoundException e) { LOGGER.warn("PMID did not matched, move to additional metadata"); } } if (isNotBlank(pmc)) { areParametersEnoughToLookup = true; try { final String response = lookupEngine.retrieveByPmc(pmc, postValidate, firstAuthor, atitle); if (isNotBlank(response)) { asyncResponse.resume(response); return; } } catch (NotFoundException e) { LOGGER.warn("PMC ID did not matched, move to additional metadata"); } } if (isNotBlank(pii)) { areParametersEnoughToLookup = true; try { final String response = lookupEngine.retrieveByPii(pii, postValidate, firstAuthor, atitle); if (isNotBlank(response)) { asyncResponse.resume(response); return; } } catch (NotFoundException e) { LOGGER.warn("PII ID did not matched, move to additional metadata"); } } if (isNotBlank(istexid)) { areParametersEnoughToLookup = true; try { final String response = lookupEngine.retrieveByIstexid(istexid, postValidate, firstAuthor, atitle); if (isNotBlank(response)) { asyncResponse.resume(response); return; } } catch (NotFoundException e) { LOGGER.warn("ISTEX ID did not matched, move to additional metadata"); } } if (isNotBlank(atitle) && isNotBlank(firstAuthor)) { LOGGER.debug("Match with metadata"); lookupEngine.retrieveByArticleMetadataAsync(atitle, firstAuthor, postValidate, matchingDocument -> { if (matchingDocument.isException()) { LOGGER.debug("Error with title/first author, trying to match with journal infos (no first author)"); if (isNotBlank(jtitle) && isNotBlank(volume) && isNotBlank(firstPage)) { lookupEngine.retrieveByJournalMetadataAsync(jtitle, volume, firstPage, atitle, firstAuthor, postValidate, matchingDocumentJournal -> { if (matchingDocumentJournal.isException()) { LOGGER.debug("Error with journal title, trying to match with biblio string"); if (isNotBlank(biblio)) { lookupEngine.retrieveByBiblioAsync(biblio, postValidate, firstAuthor, atitle, parseReference, MatchingDocumentBiblio -> { if (MatchingDocumentBiblio.isException()) { asyncResponse.resume(MatchingDocumentBiblio.getException()); } else { asyncResponse.resume(MatchingDocumentBiblio.getFinalJsonObject()); } }); return; } else { asyncResponse.resume(matchingDocument.getException()); } } else { asyncResponse.resume(matchingDocumentJournal.getFinalJsonObject()); } }); return; } LOGGER.debug("Error with title/first author, trying to match with journal infos (with first author)"); if (isNotBlank(jtitle) && isNotBlank(volume) && isNotBlank(firstPage)) { lookupEngine.retrieveByJournalMetadataAsync(jtitle, volume, firstPage, atitle, firstAuthor, postValidate, matchingDocumentJournal -> { if (matchingDocumentJournal.isException()) { LOGGER.debug("Error with journal info, trying to match with biblio string"); if (isNotBlank(biblio)) { lookupEngine.retrieveByBiblioAsync(biblio, postValidate, firstAuthor, atitle, parseReference, matchingDocumentBiblio -> { if (matchingDocumentBiblio.isException()) { asyncResponse.resume(matchingDocumentBiblio.getException()); } else { asyncResponse.resume(matchingDocumentBiblio.getFinalJsonObject()); } }); return; } else { asyncResponse.resume(matchingDocument.getException()); } } else { asyncResponse.resume(matchingDocumentJournal.getFinalJsonObject()); } }); return; } LOGGER.debug("Error with title/first author, trying to match with biblio string"); if (isNotBlank(biblio)) { lookupEngine.retrieveByBiblioAsync(biblio, postValidate, firstAuthor, atitle, parseReference, matchingDocumentBiblio -> { if (matchingDocumentBiblio.isException()) { asyncResponse.resume(matchingDocumentBiblio.getException()); } else { asyncResponse.resume(matchingDocumentBiblio.getFinalJsonObject()); } }); return; } else { asyncResponse.resume(matchingDocument.getException()); } } else { asyncResponse.resume(matchingDocument.getFinalJsonObject()); } }); return; } if (isNotBlank(jtitle) && isNotBlank(firstAuthor) && isNotBlank(volume) && isNotBlank(firstPage)) { LOGGER.debug("Match with journal title and first page"); lookupEngine.retrieveByJournalMetadataAsync(jtitle, volume, firstPage, atitle, firstAuthor, postValidate, matchingDocument -> { if (matchingDocument.isException()) { if (isNotBlank(biblio)) { lookupEngine.retrieveByBiblioAsync(biblio, postValidate, firstAuthor, atitle, parseReference, matchingDocumentBiblio -> { if (matchingDocumentBiblio.isException()) { asyncResponse.resume(matchingDocumentBiblio.getException()); } else { asyncResponse.resume(matchingDocumentBiblio.getFinalJsonObject()); } }); return; } else { asyncResponse.resume(matchingDocument.getException()); } } else { asyncResponse.resume(matchingDocument.getFinalJsonObject()); } }); return; } if (isNotBlank(jtitle) && isNotBlank(volume) && isNotBlank(firstPage)) { LOGGER.debug("Match with journal title without first author"); lookupEngine.retrieveByJournalMetadataAsync(jtitle, volume, firstPage, atitle, firstAuthor, postValidate, matchingDocument -> { if (matchingDocument.isException()) { if (isNotBlank(biblio)) { lookupEngine.retrieveByBiblioAsync(biblio, postValidate, firstAuthor, atitle, parseReference, matchingDocumentBiblio -> { if (matchingDocumentBiblio.isException()) { asyncResponse.resume(matchingDocumentBiblio.getException()); } else { asyncResponse.resume(matchingDocumentBiblio.getFinalJsonObject()); } }); return; } else { asyncResponse.resume(matchingDocument.getException()); } } else { asyncResponse.resume(matchingDocument.getFinalJsonObject()); } }); return; } if (isNotBlank(biblio)) { LOGGER.debug("Match with biblio string"); lookupEngine.retrieveByBiblioAsync(biblio, postValidate, firstAuthor, atitle, parseReference, matchingDocumentBiblio -> { if (matchingDocumentBiblio.isException()) { asyncResponse.resume(matchingDocumentBiblio.getException()); } else { asyncResponse.resume(matchingDocumentBiblio.getFinalJsonObject()); } }); return; } if (areParametersEnoughToLookup) { throw new ServiceException(404, messagesSb.toString()); } else { throw new ServiceException(400, "The supplied parameters were not sufficient to select the query"); } } protected LookupController(); @Inject LookupController(LookupConfiguration configuration, StorageEnvFactory storageEnvFactory); @GET @Produces(MediaType.APPLICATION_JSON) @Path("/") void getByQueryAsync( @QueryParam("doi") String doi, @QueryParam("pmid") String pmid, @QueryParam("pmc") String pmc, @QueryParam("pii") String pii, @QueryParam("istexid") String istexid, @QueryParam("firstAuthor") String firstAuthor, @QueryParam("atitle") String atitle, @QueryParam("postValidate") Boolean postValidate, @QueryParam("jtitle") String jtitle, @QueryParam("volume") String volume, @QueryParam("firstPage") String firstPage, @QueryParam("biblio") String biblio, @QueryParam("parseReference") Boolean parseReference, @Suspended final AsyncResponse asyncResponse); @GET @Produces(MediaType.APPLICATION_JSON) @Path("/doi/{doi}") String getByDoi(@PathParam("doi") String doi); @GET @Produces(MediaType.APPLICATION_JSON) @Path("/pmid/{pmid}") String getByPmid(@PathParam("pmid") String pmid); @GET @Produces(MediaType.APPLICATION_JSON) @Path("/pii/{pii}") String getByPii(@PathParam("pii") String pii); @GET @Produces(MediaType.APPLICATION_JSON) @Path("/pmc/{pmc}") String getByPmc(@PathParam("pmc") String pmc); @GET @Produces(MediaType.APPLICATION_JSON) @Path("/istexid/{istexid}") String getByIstexid(@PathParam("istexid") String istexid); @POST @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.TEXT_PLAIN) @Path("/") void getByBiblioStringWithPost(String biblio, @Suspended final AsyncResponse asyncResponse); }
LookupController { protected void getByQuery( String doi, String pmid, String pmc, String pii, String istexid, String firstAuthor, String atitle, final Boolean postValidate, String jtitle, String volume, String firstPage, String biblio, final Boolean parseReference, AsyncResponse asyncResponse ) { boolean areParametersEnoughToLookup = false; StringBuilder messagesSb = new StringBuilder(); if (isNotBlank(doi)) { areParametersEnoughToLookup = true; try { final String response = lookupEngine.retrieveByDoi(doi, postValidate, firstAuthor, atitle); if (isNotBlank(response)) { asyncResponse.resume(response); return; } } catch (NotFoundException e) { messagesSb.append(e.getMessage()); LOGGER.warn("DOI did not matched, move to additional metadata"); } } if (isNotBlank(pmid)) { areParametersEnoughToLookup = true; try { final String response = lookupEngine.retrieveByPmid(pmid, postValidate, firstAuthor, atitle); if (isNotBlank(response)) { asyncResponse.resume(response); return; } } catch (NotFoundException e) { LOGGER.warn("PMID did not matched, move to additional metadata"); } } if (isNotBlank(pmc)) { areParametersEnoughToLookup = true; try { final String response = lookupEngine.retrieveByPmc(pmc, postValidate, firstAuthor, atitle); if (isNotBlank(response)) { asyncResponse.resume(response); return; } } catch (NotFoundException e) { LOGGER.warn("PMC ID did not matched, move to additional metadata"); } } if (isNotBlank(pii)) { areParametersEnoughToLookup = true; try { final String response = lookupEngine.retrieveByPii(pii, postValidate, firstAuthor, atitle); if (isNotBlank(response)) { asyncResponse.resume(response); return; } } catch (NotFoundException e) { LOGGER.warn("PII ID did not matched, move to additional metadata"); } } if (isNotBlank(istexid)) { areParametersEnoughToLookup = true; try { final String response = lookupEngine.retrieveByIstexid(istexid, postValidate, firstAuthor, atitle); if (isNotBlank(response)) { asyncResponse.resume(response); return; } } catch (NotFoundException e) { LOGGER.warn("ISTEX ID did not matched, move to additional metadata"); } } if (isNotBlank(atitle) && isNotBlank(firstAuthor)) { LOGGER.debug("Match with metadata"); lookupEngine.retrieveByArticleMetadataAsync(atitle, firstAuthor, postValidate, matchingDocument -> { if (matchingDocument.isException()) { LOGGER.debug("Error with title/first author, trying to match with journal infos (no first author)"); if (isNotBlank(jtitle) && isNotBlank(volume) && isNotBlank(firstPage)) { lookupEngine.retrieveByJournalMetadataAsync(jtitle, volume, firstPage, atitle, firstAuthor, postValidate, matchingDocumentJournal -> { if (matchingDocumentJournal.isException()) { LOGGER.debug("Error with journal title, trying to match with biblio string"); if (isNotBlank(biblio)) { lookupEngine.retrieveByBiblioAsync(biblio, postValidate, firstAuthor, atitle, parseReference, MatchingDocumentBiblio -> { if (MatchingDocumentBiblio.isException()) { asyncResponse.resume(MatchingDocumentBiblio.getException()); } else { asyncResponse.resume(MatchingDocumentBiblio.getFinalJsonObject()); } }); return; } else { asyncResponse.resume(matchingDocument.getException()); } } else { asyncResponse.resume(matchingDocumentJournal.getFinalJsonObject()); } }); return; } LOGGER.debug("Error with title/first author, trying to match with journal infos (with first author)"); if (isNotBlank(jtitle) && isNotBlank(volume) && isNotBlank(firstPage)) { lookupEngine.retrieveByJournalMetadataAsync(jtitle, volume, firstPage, atitle, firstAuthor, postValidate, matchingDocumentJournal -> { if (matchingDocumentJournal.isException()) { LOGGER.debug("Error with journal info, trying to match with biblio string"); if (isNotBlank(biblio)) { lookupEngine.retrieveByBiblioAsync(biblio, postValidate, firstAuthor, atitle, parseReference, matchingDocumentBiblio -> { if (matchingDocumentBiblio.isException()) { asyncResponse.resume(matchingDocumentBiblio.getException()); } else { asyncResponse.resume(matchingDocumentBiblio.getFinalJsonObject()); } }); return; } else { asyncResponse.resume(matchingDocument.getException()); } } else { asyncResponse.resume(matchingDocumentJournal.getFinalJsonObject()); } }); return; } LOGGER.debug("Error with title/first author, trying to match with biblio string"); if (isNotBlank(biblio)) { lookupEngine.retrieveByBiblioAsync(biblio, postValidate, firstAuthor, atitle, parseReference, matchingDocumentBiblio -> { if (matchingDocumentBiblio.isException()) { asyncResponse.resume(matchingDocumentBiblio.getException()); } else { asyncResponse.resume(matchingDocumentBiblio.getFinalJsonObject()); } }); return; } else { asyncResponse.resume(matchingDocument.getException()); } } else { asyncResponse.resume(matchingDocument.getFinalJsonObject()); } }); return; } if (isNotBlank(jtitle) && isNotBlank(firstAuthor) && isNotBlank(volume) && isNotBlank(firstPage)) { LOGGER.debug("Match with journal title and first page"); lookupEngine.retrieveByJournalMetadataAsync(jtitle, volume, firstPage, atitle, firstAuthor, postValidate, matchingDocument -> { if (matchingDocument.isException()) { if (isNotBlank(biblio)) { lookupEngine.retrieveByBiblioAsync(biblio, postValidate, firstAuthor, atitle, parseReference, matchingDocumentBiblio -> { if (matchingDocumentBiblio.isException()) { asyncResponse.resume(matchingDocumentBiblio.getException()); } else { asyncResponse.resume(matchingDocumentBiblio.getFinalJsonObject()); } }); return; } else { asyncResponse.resume(matchingDocument.getException()); } } else { asyncResponse.resume(matchingDocument.getFinalJsonObject()); } }); return; } if (isNotBlank(jtitle) && isNotBlank(volume) && isNotBlank(firstPage)) { LOGGER.debug("Match with journal title without first author"); lookupEngine.retrieveByJournalMetadataAsync(jtitle, volume, firstPage, atitle, firstAuthor, postValidate, matchingDocument -> { if (matchingDocument.isException()) { if (isNotBlank(biblio)) { lookupEngine.retrieveByBiblioAsync(biblio, postValidate, firstAuthor, atitle, parseReference, matchingDocumentBiblio -> { if (matchingDocumentBiblio.isException()) { asyncResponse.resume(matchingDocumentBiblio.getException()); } else { asyncResponse.resume(matchingDocumentBiblio.getFinalJsonObject()); } }); return; } else { asyncResponse.resume(matchingDocument.getException()); } } else { asyncResponse.resume(matchingDocument.getFinalJsonObject()); } }); return; } if (isNotBlank(biblio)) { LOGGER.debug("Match with biblio string"); lookupEngine.retrieveByBiblioAsync(biblio, postValidate, firstAuthor, atitle, parseReference, matchingDocumentBiblio -> { if (matchingDocumentBiblio.isException()) { asyncResponse.resume(matchingDocumentBiblio.getException()); } else { asyncResponse.resume(matchingDocumentBiblio.getFinalJsonObject()); } }); return; } if (areParametersEnoughToLookup) { throw new ServiceException(404, messagesSb.toString()); } else { throw new ServiceException(400, "The supplied parameters were not sufficient to select the query"); } } protected LookupController(); @Inject LookupController(LookupConfiguration configuration, StorageEnvFactory storageEnvFactory); @GET @Produces(MediaType.APPLICATION_JSON) @Path("/") void getByQueryAsync( @QueryParam("doi") String doi, @QueryParam("pmid") String pmid, @QueryParam("pmc") String pmc, @QueryParam("pii") String pii, @QueryParam("istexid") String istexid, @QueryParam("firstAuthor") String firstAuthor, @QueryParam("atitle") String atitle, @QueryParam("postValidate") Boolean postValidate, @QueryParam("jtitle") String jtitle, @QueryParam("volume") String volume, @QueryParam("firstPage") String firstPage, @QueryParam("biblio") String biblio, @QueryParam("parseReference") Boolean parseReference, @Suspended final AsyncResponse asyncResponse); @GET @Produces(MediaType.APPLICATION_JSON) @Path("/doi/{doi}") String getByDoi(@PathParam("doi") String doi); @GET @Produces(MediaType.APPLICATION_JSON) @Path("/pmid/{pmid}") String getByPmid(@PathParam("pmid") String pmid); @GET @Produces(MediaType.APPLICATION_JSON) @Path("/pii/{pii}") String getByPii(@PathParam("pii") String pii); @GET @Produces(MediaType.APPLICATION_JSON) @Path("/pmc/{pmc}") String getByPmc(@PathParam("pmc") String pmc); @GET @Produces(MediaType.APPLICATION_JSON) @Path("/istexid/{istexid}") String getByIstexid(@PathParam("istexid") String istexid); @POST @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.TEXT_PLAIN) @Path("/") void getByBiblioStringWithPost(String biblio, @Suspended final AsyncResponse asyncResponse); }

Dataset Description

Microsoft created this large dataset of Java Junit test cases with its corresponding focal methods. It contains 780k pairs of JUnit test cases and focal methods which were extracted from a total of 91K Java open source project hosted on GitHub.

The mapping between test case and focal methods are based heuristics rules and Java developer's best practice.

More information could be found here:

Dataset Schema

target: <TEST_CASE>
src_fm: <FOCAL_METHOD>
src_fm_fc: <FOCAL_CLASS_NAME> <FOCAL_METHOD>
src_fm_fc_co: <FOCAL_CLASS_NAME> <FOCAL_METHOD> <CONTRSUCTORS>
src_fm_fc_ms: <FOCAL_CLASS_NAME> <FOCAL_METHOD> <CONTRSUCTORS> <METHOD_SIGNATURES>
src_fm_fc_ms_ff: <FOCAL_CLASS_NAME> <FOCAL_METHOD> <CONTRSUCTORS> <METHOD_SIGNATURES> <FIELDS>

Focal Context

  • fm: this representation incorporates exclusively the source code of the focal method. Intuitively, this contains the most important information for generating accurate test cases for the given method.
  • fm+fc: this representations adds the focal class name, which can provide meaningful semantic information to the model.
  • fm+fc+c: this representation adds the signatures of the constructor methods of the focal class. The idea behind this augmentation is that the test case may require instantiating an object of the focal class in order to properly test the focal method.
  • fm+fc+c+m: this representation adds the signatures of the other public methods in the focal class. The rationale which motivated this inclusion is that the test case may need to invoke other auxiliary methods within the class (e.g., getters, setters) to set up or tear down the testing environment.
  • fm+fc+c+m+f : this representation adds the public fields of the focal class. The motivation is that test cases may need to inspect the status of the public fields to properly test a focal method.

image/png

The different levels of focal contexts are the following:

FM: focal method
FM_FC: focal method + focal class name
FM_FC_CO: focal method + focal class name + constructor signatures
FM_FC_MS: focal method + focal class name + constructor signatures + public method signatures
FM_FC_MS_FF: focal method + focal class name + constructor signatures + public method signatures + public fields

Lmitations

The original authors validate the heuristics by inspecting a statistically significant sample (confidence level of 95% within 10% margin of error) of 97 samples from the training set. Two authors independently evaluated the sample, then met to discuss the disagreements. We found that 90.72% of the samples have a correct link between the test case and the corresponding focal method

Contribution

All the thanks to the original authors.

Downloads last month
235