@Override public void writeExternal(final ObjectOutput out) throws IOException { out.writeBoolean(numberOfUnpaidInvoicesEqualsOrExceeds != null); if (numberOfUnpaidInvoicesEqualsOrExceeds != null) { out.writeInt(numberOfUnpaidInvoicesEqualsOrExceeds); } out.writeObject(totalUnpaidInvoiceBalanceEqualsOrExceeds); out.writeObject(timeSinceEarliestUnpaidInvoiceEqualsOrExceeds); out.writeObject(responseForLastFailedPayment); out.writeBoolean(controlTagInclusion != null); if (controlTagInclusion != null) { out.writeUTF(controlTagInclusion.name()); } out.writeBoolean(controlTagExclusion != null); if (controlTagExclusion != null) { out.writeUTF(controlTagExclusion.name()); } }
private void validateApplicableObjectTypes(final UUID tagDefinitionId, final ObjectType objectType) throws TagApiException { final ControlTagType controlTagType = Iterables.tryFind(ImmutableList.<ControlTagType>copyOf(ControlTagType.values()), new Predicate<ControlTagType>() { @Override public boolean apply(final ControlTagType input) { return input.getId().equals(tagDefinitionId); } }).orNull(); if (controlTagType != null && !controlTagType.getApplicableObjectTypes().contains(objectType)) { // TODO Add missing ErrorCode.TAG_NOT_APPLICABLE // throw new TagApiException(ErrorCode.TAG_NOT_APPLICABLE); throw new IllegalStateException(String.format("Invalid control tag '%s' for object type '%s'", controlTagType.name(), objectType)); } }
public static TagDefinitionModelDao lookup(final String tagDefinitionName) { for (final ControlTagType t : ControlTagType.values()) { if (t.name().equals(tagDefinitionName)) { return new TagDefinitionModelDao(t); } } for (final TagDefinitionModelDao t : SYSTEM_DEFINED_TAG_DEFINITIONS) { if (t.getName().equals(tagDefinitionName)) { return t; } } return null; }
public TagDefinitionModelDao(final ControlTagType tag) { this(tag.getId(), null, null, tag.name(), tag.getDescription(), JOINER.join(tag.getApplicableObjectTypes())); }
@Test(groups = "slow") public void testGetByName() throws TagDefinitionApiException { // User Tag eventsListener.pushExpectedEvent(NextEvent.TAG_DEFINITION); final TagDefinitionModelDao defYo = tagDefinitionDao.create(UUID.randomUUID().toString().substring(0, 5), "defintion yo", ObjectType.ACCOUNT.name(),internalCallContext); assertListenerStatus(); final TagDefinitionModelDao resDefYo = tagDefinitionDao.getByName(defYo.getName(), internalCallContext); assertEquals(defYo, resDefYo); // Control Tag try { tagDefinitionDao.create(ControlTagType.AUTO_PAY_OFF.name(), ControlTagType.AUTO_INVOICING_OFF.name(), ObjectType.ACCOUNT.name(), internalCallContext); Assert.fail("Should not be able to create a invoice tag"); } catch (TagDefinitionApiException ignore) { } final TagDefinitionModelDao resdef_AUTO_PAY_OFF = tagDefinitionDao.getByName(ControlTagType.AUTO_PAY_OFF.name(), internalCallContext); assertEquals(resdef_AUTO_PAY_OFF.getId(), ControlTagType.AUTO_PAY_OFF.getId()); assertEquals(resdef_AUTO_PAY_OFF.getName(), ControlTagType.AUTO_PAY_OFF.name()); assertEquals(resdef_AUTO_PAY_OFF.getDescription(), ControlTagType.AUTO_PAY_OFF.getDescription()); }
@Test(groups = "fast") public void testDefaultTagDefinition() throws TagApiException, TagDefinitionApiException { final DefaultTagDefinition def1 = new DefaultTagDefinition(UUID.randomUUID(), "foo", "nothing", false); Assert.assertFalse(def1.getApplicableObjectTypes().isEmpty()); Assert.assertEquals(ImmutableList.<ObjectType>copyOf(ObjectType.values()), def1.getApplicableObjectTypes()); for (final ControlTagType cur : ControlTagType.values()) { final DefaultTagDefinition curDef = new DefaultTagDefinition(cur.getId(), cur.name(), cur.getDescription(), true); Assert.assertFalse(curDef.getApplicableObjectTypes().isEmpty()); Assert.assertEquals(curDef.getApplicableObjectTypes(), cur.getApplicableObjectTypes()); } try { new DefaultTagDefinition(UUID.randomUUID(), "bar", "nothing again", true); Assert.fail("Not a control tag type"); } catch (final IllegalStateException e) { } } }
@Test(groups = "slow") public void testGetById() throws TagDefinitionApiException { // User Tag eventsListener.pushExpectedEvent(NextEvent.TAG_DEFINITION); final TagDefinitionModelDao defYo = tagDefinitionDao.create(UUID.randomUUID().toString().substring(0, 5), "defintion yo", ObjectType.ACCOUNT.name(),internalCallContext); assertListenerStatus(); final TagDefinitionModelDao resDefYo = tagDefinitionDao.getById(defYo.getId(), internalCallContext); assertEquals(defYo, resDefYo); // Control Tag try { tagDefinitionDao.create(ControlTagType.AUTO_INVOICING_OFF.name(), ControlTagType.AUTO_INVOICING_OFF.name(), ObjectType.ACCOUNT.name(),internalCallContext); Assert.fail("Should not be able to create a invoice tag"); } catch (TagDefinitionApiException ignore) { } final TagDefinitionModelDao resdef_AUTO_INVOICING_OFF = tagDefinitionDao.getById(ControlTagType.AUTO_INVOICING_OFF.getId(), internalCallContext); assertEquals(resdef_AUTO_INVOICING_OFF.getId(), ControlTagType.AUTO_INVOICING_OFF.getId()); assertEquals(resdef_AUTO_INVOICING_OFF.getName(), ControlTagType.AUTO_INVOICING_OFF.name()); assertEquals(resdef_AUTO_INVOICING_OFF.getDescription(), ControlTagType.AUTO_INVOICING_OFF.getDescription()); }
@Override public void writeExternal(final ObjectOutput out) throws IOException { out.writeBoolean(numberOfUnpaidInvoicesEqualsOrExceeds != null); if (numberOfUnpaidInvoicesEqualsOrExceeds != null) { out.writeInt(numberOfUnpaidInvoicesEqualsOrExceeds); } out.writeObject(totalUnpaidInvoiceBalanceEqualsOrExceeds); out.writeObject(timeSinceEarliestUnpaidInvoiceEqualsOrExceeds); out.writeObject(responseForLastFailedPayment); out.writeBoolean(controlTagInclusion != null); if (controlTagInclusion != null) { out.writeUTF(controlTagInclusion.name()); } out.writeBoolean(controlTagExclusion != null); if (controlTagExclusion != null) { out.writeUTF(controlTagExclusion.name()); } }
private void validateApplicableObjectTypes(final UUID tagDefinitionId, final ObjectType objectType) throws TagApiException { final ControlTagType controlTagType = Iterables.tryFind(ImmutableList.<ControlTagType>copyOf(ControlTagType.values()), new Predicate<ControlTagType>() { @Override public boolean apply(final ControlTagType input) { return input.getId().equals(tagDefinitionId); } }).orNull(); if (controlTagType != null && !controlTagType.getApplicableObjectTypes().contains(objectType)) { // TODO Add missing ErrorCode.TAG_NOT_APPLICABLE // throw new TagApiException(ErrorCode.TAG_NOT_APPLICABLE); throw new IllegalStateException(String.format("Invalid control tag '%s' for object type '%s'", controlTagType.name(), objectType)); } }
public static TagDefinitionModelDao lookup(final String tagDefinitionName) { for (final ControlTagType t : ControlTagType.values()) { if (t.name().equals(tagDefinitionName)) { return new TagDefinitionModelDao(t); } } for (final TagDefinitionModelDao t : SYSTEM_DEFINED_TAG_DEFINITIONS) { if (t.getName().equals(tagDefinitionName)) { return t; } } return null; }
public TagDefinitionModelDao(final ControlTagType tag) { this(tag.getId(), null, null, tag.name(), tag.getDescription(), JOINER.join(tag.getApplicableObjectTypes())); }
@Test(groups = "slow") public void testGetByName() throws TagDefinitionApiException { // User Tag eventsListener.pushExpectedEvent(NextEvent.TAG_DEFINITION); final TagDefinitionModelDao defYo = tagDefinitionDao.create(UUID.randomUUID().toString().substring(0, 5), "defintion yo", ObjectType.ACCOUNT.name(),internalCallContext); assertListenerStatus(); final TagDefinitionModelDao resDefYo = tagDefinitionDao.getByName(defYo.getName(), internalCallContext); assertEquals(defYo, resDefYo); // Control Tag try { tagDefinitionDao.create(ControlTagType.AUTO_PAY_OFF.name(), ControlTagType.AUTO_INVOICING_OFF.name(), ObjectType.ACCOUNT.name(), internalCallContext); Assert.fail("Should not be able to create a invoice tag"); } catch (TagDefinitionApiException ignore) { } final TagDefinitionModelDao resdef_AUTO_PAY_OFF = tagDefinitionDao.getByName(ControlTagType.AUTO_PAY_OFF.name(), internalCallContext); assertEquals(resdef_AUTO_PAY_OFF.getId(), ControlTagType.AUTO_PAY_OFF.getId()); assertEquals(resdef_AUTO_PAY_OFF.getName(), ControlTagType.AUTO_PAY_OFF.name()); assertEquals(resdef_AUTO_PAY_OFF.getDescription(), ControlTagType.AUTO_PAY_OFF.getDescription()); }
@Test(groups = "fast") public void testDefaultTagDefinition() throws TagApiException, TagDefinitionApiException { final DefaultTagDefinition def1 = new DefaultTagDefinition(UUID.randomUUID(), "foo", "nothing", false); Assert.assertFalse(def1.getApplicableObjectTypes().isEmpty()); Assert.assertEquals(ImmutableList.<ObjectType>copyOf(ObjectType.values()), def1.getApplicableObjectTypes()); for (final ControlTagType cur : ControlTagType.values()) { final DefaultTagDefinition curDef = new DefaultTagDefinition(cur.getId(), cur.name(), cur.getDescription(), true); Assert.assertFalse(curDef.getApplicableObjectTypes().isEmpty()); Assert.assertEquals(curDef.getApplicableObjectTypes(), cur.getApplicableObjectTypes()); } try { new DefaultTagDefinition(UUID.randomUUID(), "bar", "nothing again", true); Assert.fail("Not a control tag type"); } catch (final IllegalStateException e) { } } }
@Test(groups = "slow") public void testGetById() throws TagDefinitionApiException { // User Tag eventsListener.pushExpectedEvent(NextEvent.TAG_DEFINITION); final TagDefinitionModelDao defYo = tagDefinitionDao.create(UUID.randomUUID().toString().substring(0, 5), "defintion yo", ObjectType.ACCOUNT.name(),internalCallContext); assertListenerStatus(); final TagDefinitionModelDao resDefYo = tagDefinitionDao.getById(defYo.getId(), internalCallContext); assertEquals(defYo, resDefYo); // Control Tag try { tagDefinitionDao.create(ControlTagType.AUTO_INVOICING_OFF.name(), ControlTagType.AUTO_INVOICING_OFF.name(), ObjectType.ACCOUNT.name(),internalCallContext); Assert.fail("Should not be able to create a invoice tag"); } catch (TagDefinitionApiException ignore) { } final TagDefinitionModelDao resdef_AUTO_INVOICING_OFF = tagDefinitionDao.getById(ControlTagType.AUTO_INVOICING_OFF.getId(), internalCallContext); assertEquals(resdef_AUTO_INVOICING_OFF.getId(), ControlTagType.AUTO_INVOICING_OFF.getId()); assertEquals(resdef_AUTO_INVOICING_OFF.getName(), ControlTagType.AUTO_INVOICING_OFF.name()); assertEquals(resdef_AUTO_INVOICING_OFF.getDescription(), ControlTagType.AUTO_INVOICING_OFF.getDescription()); }