private void checkDraftStatusIs(final Draft.Status status, final Draft draft) {
   checkState(
       status.equals(draft.status()),
       "expected '%s' service draft status, but got '%s'",
       status,
       draft.status());
 }
 private void updateCustomerStatusOf(
     final Optional<Draft> customerDraftOptional,
     final Optional<Draft> agreementDraftOptional,
     final Draft serviceDraft,
     final Handle handle) {
   final Map<String, Object> customerUpdate = Maps.newHashMap();
   final long customerId;
   final Service service = new Service(serviceDraft);
   if (customerDraftOptional.isPresent() && agreementDraftOptional.isPresent()) {
     customerId = customerDraftOptional.get().entityId();
     final Draft agreementDraft = agreementDraftOptional.get();
     final Agreement agreement = new Agreement(agreementDraft);
     if ("PL".equals(agreementDraft.entitySpate())) {
       final Object symbol = "PL-" + (agreementDraft.entityId() - 200000);
       customerUpdate.put("symbol", symbol);
     }
     final Object variable = agreement.number();
     customerUpdate.put("lastly_billed", service.periodStart().dayOfMonth().withMaximumValue());
     customerUpdate.put("status", 20);
     customerUpdate.put("variable", variable);
   } else {
     customerId = service.customerId();
   }
   customerUpdate.put("customer_status", "ACTIVE");
   customerUpdate.put("is_active", true);
   updateRecord(CUSTOMERS_TABLE, customerId, customerUpdate, handle);
 }
Exemple #3
0
 public Customer(Draft draft) {
   checkArgument(
       Draft.Entity.CUSTOMERS.equals(draft.entity()),
       "expected CUSTOMERS draft, but got %s",
       draft.entity());
   this.id = new CustomerId(draft.entityId());
   this.props = propsFromDraft(draft);
   this.record = recordFromProps();
 }
 private void insertCustomerOf(final Draft draft, final Handle handle) {
   log.debug("adding new customer '{}' from draft '{}'", draft.entityId(), draft.id().value());
   final Customer customer = new Customer(draft);
   final Map<String, Object> record = Maps.newHashMap(customer.record());
   final DateTime now = DateTime.now();
   record.put("inserted_on", now);
   record.put("updated", now);
   final long historyId = insertCustomerAuditOf(draft, handle);
   record.put("history_id", historyId);
   insertRecordWithoutKey(CUSTOMERS_TABLE, record, handle);
 }
Exemple #5
0
 private Map<String, Object> propsFromDraft(final Draft draft) {
   final Map<String, Object> props = Maps.newLinkedHashMap();
   props.put("id", draft.entityId());
   final ValueMap data = valueMapOf(draft.data());
   final boolean isBusiness = "2".equals(data.get("customer_type").asString());
   if (isBusiness) {
     props.put("name", data.getRaw("supplementary_name"));
     props.put("nameExtra", data.getRaw("representative"));
   } else {
     props.put(
         "name",
         Joiner.on(" ")
             .skipNulls()
             .join(data.get("surname").asStringOr(null), data.get("name").asStringOr(null)));
     props.put("nameExtra", "");
   }
   props.put(
       "addressStreet",
       streetAddress(
           data.getRaw("street"),
           data.getRaw("descriptive_number"),
           data.getRaw("orientation_number")));
   props.put("addressTown", data.getRaw("town"));
   props.put("addressPostalCode", data.getRaw("postal_code"));
   props.put("addressCountryId", data.get("country").asLong());
   props.put("contactName", data.getRaw("contact_name"));
   props.put("contactEmail", data.getRaw("email"));
   props.put("contactPhone", data.getRaw("phone"));
   props.put("publicId", data.getRaw("public_id"));
   if (isBusiness) {
     props.put(
         "taxId",
         data.get("dic")
             .asStringValueOr(
                 data.get("public_id").asStringValueOr("" + System.currentTimeMillis())));
   } else {
     props.put("taxId", "");
   }
   props.put("otherInfo", data.getRaw("info"));
   return Collections.unmodifiableMap(props);
 }
 private long insertCustomerAuditOf(final Draft draft, final Handle handle) {
   final long auditId = nextValOf(AUDIT_ITEM_ID_SEQ, handle);
   final long historyId = lastValueOf(AUDIT_TABLE, "history_id", handle) + 1;
   final Map<String, Object> record =
       ImmutableMap.<String, Object>builder()
           .put("id", auditId)
           .put("history_id", historyId)
           .put("history_type_label_id", 41L) // customer audit label id
           .put("user_id", 2L) // system user
           .put("time_stamp", DateTime.now())
           .put("field_name", "name")
           .put("old_value", Optional.absent())
           .put("new_value", draft.entityName())
           .build();
   insertRecordWithoutKey(AUDIT_TABLE, record, handle);
   return historyId;
 }
 private void insertAgreementOf(final Draft draft, final Handle handle) {
   log.debug("adding new agreement '{}' from draft '{}'", draft.entityId(), draft.id().value());
   final Agreement agreement = new Agreement(draft);
   insertRecordWithoutKey(AGREEMENTS_TABLE, agreement.record(), handle);
 }
 private void insertServiceOf(final Draft draft, final Handle handle) {
   log.debug("adding new service '{}' from draft '{}'", draft.entityId(), draft.id().value());
   final Service service = new Service(draft);
   insertRecordWithoutKey(SERVICES_TABLE, service.record(), handle);
 }
 private void checkDraftEntityIs(final Draft.Entity entity, final Draft draft) {
   checkState(
       entity.equals(draft.entity()), "expected '%s' draft, but got '%s'", entity, draft.entity());
 }