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)); } }
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)); }
public TagDefinitionModelDao(final ControlTagType tag) { this(tag.getId(), null, null, tag.name(), tag.getDescription(), JOINER.join(tag.getApplicableObjectTypes())); }
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) { } } }
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)); } }
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)); }
public TagDefinitionModelDao(final ControlTagType tag) { this(tag.getId(), null, null, tag.name(), tag.getDescription(), JOINER.join(tag.getApplicableObjectTypes())); }
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) { } } }