@Test(expected = FieldUsedInLookupException.class) public void shouldValidateFieldUsedByLookup() { setupEntity(); entityValidator.validateFieldNotUsedByLookups(entity, 111L); }
public void validateFieldNotUsedByLookups(Entity entity, Long fieldId) { StringBuilder lookups = new StringBuilder(); for (Lookup lookup : entity.getLookups()) { for (Field field : lookup.getFields()) { if (Objects.equals(fieldId, field.getId())) { if (lookups.length() != 0) { lookups.append(' '); } lookups.append(lookup.getLookupName()); } } } if (lookups.length() > 0) { throw new FieldUsedInLookupException(entity.getField(fieldId).getDisplayName(), lookups.toString()); } }
EntityValidator { public void validateFieldNotUsedByLookups(Entity entity, Long fieldId) { StringBuilder lookups = new StringBuilder(); for (Lookup lookup : entity.getLookups()) { for (Field field : lookup.getFields()) { if (Objects.equals(fieldId, field.getId())) { if (lookups.length() != 0) { lookups.append(' '); } lookups.append(lookup.getLookupName()); } } } if (lookups.length() > 0) { throw new FieldUsedInLookupException(entity.getField(fieldId).getDisplayName(), lookups.toString()); } } }
EntityValidator { public void validateFieldNotUsedByLookups(Entity entity, Long fieldId) { StringBuilder lookups = new StringBuilder(); for (Lookup lookup : entity.getLookups()) { for (Field field : lookup.getFields()) { if (Objects.equals(fieldId, field.getId())) { if (lookups.length() != 0) { lookups.append(' '); } lookups.append(lookup.getLookupName()); } } } if (lookups.length() > 0) { throw new FieldUsedInLookupException(entity.getField(fieldId).getDisplayName(), lookups.toString()); } }  }
EntityValidator { public void validateFieldNotUsedByLookups(Entity entity, Long fieldId) { StringBuilder lookups = new StringBuilder(); for (Lookup lookup : entity.getLookups()) { for (Field field : lookup.getFields()) { if (Objects.equals(fieldId, field.getId())) { if (lookups.length() != 0) { lookups.append(' '); } lookups.append(lookup.getLookupName()); } } } if (lookups.length() > 0) { throw new FieldUsedInLookupException(entity.getField(fieldId).getDisplayName(), lookups.toString()); } }  void validateEntity(EntityDraft draft); void validateAdvancedSettingsEdit(Entity entity, String path); void validateFieldNotUsedByLookups(Entity entity, Long fieldId); @Autowired void setPersistenceManagerFactory(PersistenceManagerFactory persistenceManagerFactory); @Autowired void setBundleContext(BundleContext bundleContext); }
EntityValidator { public void validateFieldNotUsedByLookups(Entity entity, Long fieldId) { StringBuilder lookups = new StringBuilder(); for (Lookup lookup : entity.getLookups()) { for (Field field : lookup.getFields()) { if (Objects.equals(fieldId, field.getId())) { if (lookups.length() != 0) { lookups.append(' '); } lookups.append(lookup.getLookupName()); } } } if (lookups.length() > 0) { throw new FieldUsedInLookupException(entity.getField(fieldId).getDisplayName(), lookups.toString()); } }  void validateEntity(EntityDraft draft); void validateAdvancedSettingsEdit(Entity entity, String path); void validateFieldNotUsedByLookups(Entity entity, Long fieldId); @Autowired void setPersistenceManagerFactory(PersistenceManagerFactory persistenceManagerFactory); @Autowired void setBundleContext(BundleContext bundleContext);  }