void createService(ExternalEvent event, Map<String, Object> serviceData) {
    Service svc = serviceDao.getServiceByExternalId(event.getAccountId(), event.getExternalId());
    if (svc != null) {
      return;
    }

    Stack stack = getStack(event);
    if (stack == null) {
      log.info("Can't process service event. Could not get or create stack. Event: [{}]", event);
      return;
    }

    Map<String, Object> service = new HashMap<String, Object>();
    if (serviceData != null) {
      service.putAll(serviceData);
    }
    service.put(ObjectMetaDataManager.ACCOUNT_FIELD, event.getAccountId());
    service.put(FIELD_STACK_ID, stack.getId());

    try {
      String create =
          objectProcessManager.getStandardProcessName(StandardProcess.CREATE, Service.class);
      String activate =
          objectProcessManager.getStandardProcessName(StandardProcess.ACTIVATE, Service.class);
      ProcessUtils.chainInData(service, create, activate);
      resourceDao.createAndSchedule(Service.class, service);
    } catch (ProcessCancelException e) {
      log.info(
          "Create and activate process cancelled for service with account id {}and external id {}",
          event.getAccountId(),
          event.getExternalId());
    }
  }
  void updateService(ExternalEvent event, Map<String, Object> serviceData) {
    Service svc = serviceDao.getServiceByExternalId(event.getAccountId(), event.getExternalId());
    if (svc == null) {
      log.info(
          "Unable to find service while attempting to update. Returning. Service external id: [{}], account id: [{}]",
          event.getExternalId(),
          event.getAccountId());
      return;
    }

    Map<String, Object> fields = DataUtils.getFields(svc);
    Map<String, Object> updates = new HashMap<String, Object>();
    for (Map.Entry<String, Object> resourceField : serviceData.entrySet()) {
      String fieldName = resourceField.getKey();
      Object newFieldValue = resourceField.getValue();
      Object currentFieldValue = fields.get(fieldName);
      if (ObjectUtils.hasWritableProperty(svc, fieldName)) {
        Object property = ObjectUtils.getProperty(svc, fieldName);
        if (newFieldValue != null && !newFieldValue.equals(property) || property == null) {
          updates.put(fieldName, newFieldValue);
        }
      } else if ((newFieldValue != null && !newFieldValue.equals(currentFieldValue))
          || currentFieldValue != null) {
        updates.put(fieldName, newFieldValue);
      }
    }

    if (!updates.isEmpty()) {
      objectManager.setFields(svc, updates);
      resourceDao.updateAndSchedule(svc);
    }
  }
 public ProjectMember createProjectMember(Account project, Member member) {
   Map<Object, Object> properties = new HashMap<>();
   properties.put(PROJECT_MEMBER.PROJECT_ID, project.getId());
   properties.put(PROJECT_MEMBER.ACCOUNT_ID, project.getId());
   properties.put(PROJECT_MEMBER.NAME, member.getName());
   properties.put(PROJECT_MEMBER.EXTERNAL_ID, member.getExternalId());
   properties.put(PROJECT_MEMBER.EXTERNAL_ID_TYPE, member.getExternalIdType());
   properties.put(PROJECT_MEMBER.ROLE, member.getRole());
   return resourceDao.create(
       ProjectMember.class, objectManager.convertToPropertiesFor(ProjectMember.class, properties));
 }
 @Override
 public Account createProject(String name, String description) {
   Map<Object, Object> properties = new HashMap<>();
   if (name != null) {
     properties.put(ACCOUNT.NAME, name);
   }
   if (description != null) {
     properties.put(ACCOUNT.DESCRIPTION, description);
   }
   properties.put(ACCOUNT.KIND, ProjectConstants.TYPE);
   return resourceDao.createAndSchedule(
       Account.class, objectManager.convertToPropertiesFor(Account.class, properties));
 }
 @Override
 public Account createAccount(String name, String kind, String externalId, String externalType) {
   Account account = getAccountByExternalId(externalId, externalType);
   if (account != null) {
     throw new ClientVisibleException(ResponseCodes.UNAUTHORIZED);
   }
   Map<Object, Object> properties = new HashMap<>();
   if (StringUtils.isNotEmpty(name)) {
     properties.put(ACCOUNT.NAME, name);
   }
   if (StringUtils.isNotEmpty(kind)) {
     properties.put(ACCOUNT.KIND, kind);
   }
   if (StringUtils.isNotEmpty(externalId)) {
     properties.put(ACCOUNT.EXTERNAL_ID, externalId);
   }
   if (StringUtils.isNotEmpty(externalType)) {
     properties.put(ACCOUNT.EXTERNAL_ID_TYPE, externalType);
   }
   return resourceDao.createAndSchedule(
       Account.class, objectManager.convertToPropertiesFor(Account.class, properties));
 }