private void preloadCache() {
   List<Entity> entities = loadEntities();
   log.info("Pre-loaded configuration for " + entities.size() + " entities.");
   Map<String, List<CustomField>> customFieldsListByEntityName =
       new HashMap<String, List<CustomField>>();
   Map<String, Map<String, CustomField>> customFieldsMapByEntityName =
       new HashMap<String, Map<String, CustomField>>();
   for (Entity entity : entities) {
     List<CustomField> customFields = loadCustomFields(entity.getName());
     customFieldsListByEntityName.put(entity.getName(), customFields);
     log.info(
         "Pre-loaded a list of "
             + customFields.size()
             + " custom fields for entity "
             + entity.getName());
     Map<String, CustomField> customFieldMap = new HashMap<String, CustomField>();
     for (CustomField field : customFields) {
       customFieldMap.put(field.getFieldName(), field);
     }
     customFieldsMapByEntityName.put(entity.getName(), customFieldMap);
     Context.getConfiguration()
         .registerConfigurationEntry(
             entity.getName(),
             ConfigurationRegistry.CUSTOM_FIELD_LIST_BY_ENTITY_NAME_MAP,
             customFieldsListByEntityName);
     Context.getConfiguration()
         .registerConfigurationEntry(
             entity.getName(),
             ConfigurationRegistry.CUSTOM_FIELD_MAP_BY_ENTITY_NAME_MAP,
             customFieldsMapByEntityName);
   }
 }
  public PersonIdentifier getGlobalIdentifierById(PersonIdentifier personIdentifier) {

    ValidationService validationService = Context.getValidationService();
    validationService.validate(personIdentifier);

    GlobalIdentifier globalIdentifier = Context.getConfiguration().getGlobalIdentifier();
    if (!globalIdentifier.isAssignGlobalIdentifier()) {
      log.warn("The system is not configured to assign global identifiers.");
      return null;
    }

    IdentifierDomain globalDomain = globalIdentifier.getIdentifierDomain();
    // Check to see if the person already has a global identifier
    Person person = personDao.getPersonById(personIdentifier);
    if (person != null) {
      for (PersonIdentifier identifier : person.getPersonIdentifiers()) {
        IdentifierDomain identifierDomain = identifier.getIdentifierDomain();
        if (identifierDomain != null && identifierDomain.equals(globalDomain)) {
          if (log.isTraceEnabled()) {
            log.trace("Person has a global identifier assigned: " + identifier);
          }
          return identifier;
        }
      }
    }
    return null;
  }
 public BlockingSettingsWeb loadBlockingConfigurationData() {
   log.debug("Received request to load the blocking configuration data.");
   try {
     Configuration configuration = Context.getConfiguration();
     BlockingSettings settings =
         (BlockingSettings)
             configuration.lookupConfigurationEntry(
                 BasicBlockingConstants.BLOCKING_SETTINGS_REGISTRY_KEY);
     return convertToClientModel(settings);
   } catch (Throwable t) {
     log.error("Failed to execute: " + t.getMessage(), t);
     throw new RuntimeException(t);
   }
 }
 public String saveBlockingConfigurationData(BlockingSettingsWeb blockingConfiguration) {
   Configuration configuration = Context.getConfiguration();
   String returnMessage = "";
   try {
     Component component =
         configuration.lookupExtensionComponentByComponentType(ComponentType.BLOCKING);
     String loaderBeanName = configuration.getExtensionBeanNameFromComponent(component);
     ConfigurationLoader loader = (ConfigurationLoader) context.getBean(loaderBeanName);
     BlockingSettings blockingSettings = convertFromClientModel(blockingConfiguration);
     loader.saveAndRegisterComponentConfiguration(configuration, blockingSettings);
   } catch (Exception e) {
     log.warn("Failed while saving the blocking configuration: " + e, e);
     returnMessage = e.getMessage();
   }
   return returnMessage;
 }
 @SuppressWarnings("unchecked")
 public void update(Observable o, Object eventData) {
   if (!(o instanceof EventObservable)
       || eventData == null
       || !(eventData instanceof CustomField)) {
     log.warn("Received unexpected event with data of " + eventData);
     return;
   }
   EventObservable event = (EventObservable) o;
   CustomField customField = (CustomField) eventData;
   Map<String, List<CustomField>> customFieldsListByEntityName =
       (Map<String, List<CustomField>>)
           Context.getConfiguration()
               .lookupConfigurationEntry(
                   customField.getEntityName(),
                   ConfigurationRegistry.CUSTOM_FIELD_LIST_BY_ENTITY_NAME_MAP);
   Map<String, Map<String, CustomField>> customFieldsMapByEntityName =
       (Map<String, Map<String, CustomField>>)
           Context.getConfiguration()
               .lookupConfigurationEntry(
                   customField.getEntityName(),
                   ConfigurationRegistry.CUSTOM_FIELD_MAP_BY_ENTITY_NAME_MAP);
   List<CustomField> fieldList = customFieldsListByEntityName.get(customField.getEntityName());
   Map<String, CustomField> fieldMap =
       customFieldsMapByEntityName.get(customField.getEntityName());
   if (event.getType() == ObservationEventType.CUSTOM_FIELD_ADD_EVENT) {
     log.debug(
         "A new custom field was added; we need to update the in-memory registry: " + customField);
     fieldList.add(customField);
     fieldMap.put(customField.getFieldName(), customField);
   } else if (event.getType() == ObservationEventType.CUSTOM_FIELD_UPDATE_EVENT) {
     log.debug(
         "A custom field was updated; we need to update the in-memory registry: " + customField);
     boolean found = false;
     for (CustomField item : fieldList) {
       if (item.getFieldName().equals(customField.getFieldName())) {
         found = true;
         item.setConfigurationParameters(customField.getConfigurationParameters());
         item.setSourceFieldName(customField.getSourceFieldName());
         item.setTransformationFunctionName(customField.getTransformationFunctionName());
         log.debug(
             "As a result of an update custom field event, update field "
                 + item
                 + " in the list.");
       }
     }
     if (!found) {
       log.warn(
           "Received an event to update an existing custom field but the field is not found in the registry.");
     }
     fieldMap.put(customField.getFieldName(), customField);
   } else if (event.getType() == ObservationEventType.CUSTOM_FIELD_DELETE_EVENT) {
     log.debug(
         "A new custom field was deleted; we need to update the in-memory registry: "
             + customField);
     CustomField foundField = null;
     for (CustomField item : fieldList) {
       if (item.getFieldName().equals(customField.getFieldName())) {
         foundField = item;
       }
     }
     if (foundField != null) {
       fieldList.remove(foundField);
       log.debug(
           "As a result of a delete custom field event, deleted field "
               + foundField
               + " from the list.");
     }
     fieldMap.remove(customField.getFieldName());
   }
 }