public DefaultControlTag(final UUID id, final ControlTagType controlTagType, final ObjectType objectType, final UUID objectId, final DateTime createdDate) { super(id, controlTagType.getId(), objectType, objectId, createdDate); this.controlTagType = controlTagType; }
public DefaultTagDefinition(final ControlTagType controlTag) { this(controlTag.getId(), controlTag.toString(), controlTag.getDescription(), true, controlTag.getApplicableObjectTypes()); }
@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) { } } }
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()); }
private static List<ObjectType> getApplicableObjectTypes(final UUID id, final Boolean isControlTag) { if (!isControlTag) { return ImmutableList.<ObjectType>copyOf(ObjectType.values()); } for (final ControlTagType cur : ControlTagType.values()) { if (cur.getId().equals(id)) { return cur.getApplicableObjectTypes(); } } throw new IllegalStateException(String.format("ControlTag id %s does not seem to exist", id)); }
/** * Convenience method to return whether an account is configured with auto_invoicing_off * (information of which control tag is configured with which behavior stays here) * * @param input tagDefinitionIds for all the tags associated to a given account * @return whether that account is set with auto_invoicing_off */ public static boolean isAutoInvoicingOff(final Collection<UUID> input) { for (UUID cur : input) { for (ControlTagType controlTag : values()) { if (controlTag.getId().equals(cur) && controlTag.getAutoInvoicingOff()) { return true; } } } return false; } }
/** * Convenience method to return whether an account is configured with auto_pay_off * (information of which control tag is configured with which behavior stays here) * * @param input tagDefinitionIds for all the tags associated to a given account * @return whether that account is set with auto_pay_off */ public static boolean isAutoPayOff(final Collection<UUID> input) { for (UUID cur : input) { for (ControlTagType controlTag : values()) { if (controlTag.getId().equals(cur) && controlTag.getAutoPaymentOff()) { return true; } } } return false; }
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)); } }
@AllowConcurrentEvents @Subscribe public void handleTagRemoval(final ControlTagDeletionInternalEvent event) { if (event.getTagDefinition().getName().equals(ControlTagType.OVERDUE_ENFORCEMENT_OFF.toString()) && event.getObjectType() == ObjectType.ACCOUNT) { insertBusEventIntoNotificationQueue(event.getObjectId(), event); } else if (event.getTagDefinition().getName().equals(ControlTagType.WRITTEN_OFF.toString()) && event.getObjectType() == ObjectType.INVOICE) { final UUID accountId = nonEntityDao.retrieveIdFromObject(event.getSearchKey1(), ObjectType.ACCOUNT, objectIdCacheController); insertBusEventIntoNotificationQueue(accountId, event); } }
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 static Collection<TagDefinitionModelDao> get(final boolean includeSystemTags) { final Collection<TagDefinitionModelDao> all = includeSystemTags ? new LinkedList<TagDefinitionModelDao>(SYSTEM_DEFINED_TAG_DEFINITIONS) : new LinkedList<TagDefinitionModelDao>(); for (final ControlTagType controlTag : ControlTagType.values()) { all.add(new TagDefinitionModelDao(controlTag)); } return all; }
@Override public int hashCode() { int result = numberOfUnpaidInvoicesEqualsOrExceeds != null ? numberOfUnpaidInvoicesEqualsOrExceeds.hashCode() : 0; result = 31 * result + (totalUnpaidInvoiceBalanceEqualsOrExceeds != null ? totalUnpaidInvoiceBalanceEqualsOrExceeds.hashCode() : 0); result = 31 * result + (timeSinceEarliestUnpaidInvoiceEqualsOrExceeds != null ? timeSinceEarliestUnpaidInvoiceEqualsOrExceeds.hashCode() : 0); result = 31 * result + Arrays.hashCode(responseForLastFailedPayment); result = 31 * result + (controlTagInclusion != null ? controlTagInclusion.hashCode() : 0); result = 31 * result + (controlTagExclusion != null ? controlTagExclusion.hashCode() : 0); return result; }
@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()); } }
public static TagDefinitionModelDao lookup(final UUID tagDefinitionId) { for (final ControlTagType t : ControlTagType.values()) { if (t.getId().equals(tagDefinitionId)) { return new TagDefinitionModelDao(t); } } for (final TagDefinitionModelDao t : SYSTEM_DEFINED_TAG_DEFINITIONS) { if (t.getId().equals(tagDefinitionId)) { return t; } } return null; } }
@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()); }
private static List<ObjectType> getApplicableObjectTypes(final UUID id, final Boolean isControlTag) { if (!isControlTag) { return ImmutableList.<ObjectType>copyOf(ObjectType.values()); } for (final ControlTagType cur : ControlTagType.values()) { if (cur.getId().equals(id)) { return cur.getApplicableObjectTypes(); } } throw new IllegalStateException(String.format("ControlTag id %s does not seem to exist", id)); }
/** * Convenience method to return whether an account is configured with auto_invoicing_off * (information of which control tag is configured with which behavior stays here) * * @param input tagDefinitionIds for all the tags associated to a given account * @return whether that account is set with auto_invoicing_off */ public static boolean isAutoInvoicingOff(final Collection<UUID> input) { for (UUID cur : input) { for (ControlTagType controlTag : values()) { if (controlTag.getId().equals(cur) && controlTag.getAutoInvoicingOff()) { return true; } } } return false; } }