S++Business systems language
DEMO SOURCE · SPP / APP / PHYRead the book

customer.spp

customer/customer.spp

Download original file · Petstore source contents

1domain customer;23Entity Person {4    business("Customer-domain subject registration number") String customerNumber;5    String name;6    String email;7    String address;8}910Contract SubjectRegistrationAgreement {11    Person subject;12}1314Contract SubjectProfileAgreement {15    Person subject;16    String name;17    String email;18    String address;19}2021Role RegisteredSubject {22}2324take Person as RegisteredSubject {25    takeall;26}2728Scenario serial readRegisteredSubject(RegisteredSubject) {29    findRegisteredSubject;30}3132atomic check checkSubjectFacts(Person) {33    require(Person.name != null && Person.name != "", "SUBJECT_NAME_REQUIRED");34    require(Person.email != null && Person.email != "", "SUBJECT_EMAIL_REQUIRED");35    require(Person.address != null && Person.address != "", "SUBJECT_ADDRESS_REQUIRED");36}3738atomic check checkSubjectAbsent(Person) {39    require(!Person, "SUBJECT_EXISTS");40}4142atomic calculate prepareSubjectRegistration(Person, SubjectRegistrationAgreement) {43    SubjectRegistrationAgreement.subject = Person;44}4546atomic calculate applySubjectProfile(Person, SubjectProfileAgreement) {47    Person.name = SubjectProfileAgreement.name;48    Person.email = SubjectProfileAgreement.email;49    Person.address = SubjectProfileAgreement.address;50    SubjectProfileAgreement.subject = Person;51}5253Scenario serial registerSubject(Person, SubjectRegistrationAgreement) {54    checkSubjectFacts;55    prepareSubjectRegistration;56    findPerson;57    checkSubjectAbsent;58    transaction {59        insertPerson;60    }61}6263Scenario serial updateSubjectProfile(Person, SubjectProfileAgreement) {64    findPerson;65    identify(Person);66    applySubjectProfile;67    checkSubjectFacts;68    transaction {69        updatePerson;70    }71}7273atomic calculate configureMerchantSubject(Person) {74    Person.customerNumber = "MERCHANT-001";75    Person.name = "Pet shop merchant";76    Person.email = "merchant@example.test";77    Person.address = "Pet Lane shop, Demo City";78}7980Scenario serial initializeCustomerDomain(Person, SubjectRegistrationAgreement) {81    configureMerchantSubject;82    prepareSubjectRegistration;83    findPerson;84    if (!Person) {85        checkSubjectFacts;86        transaction {87            insertPerson;88        }89    }90}