Search in sources :

Example 11 with PersonType

use of org.talend.types.test.library.common._1.PersonType in project tesb-rt-se by Talend.

the class LibraryServerImpl method seekBookInBasement.

@Override
public void seekBookInBasement(SearchFor body) {
    System.out.println("****************************************************************************");
    System.out.println("*** seekBookInBasement request (Request-Callback operation) was received ***");
    System.out.println("****************************************************************************");
    showSeekBookInBasementRequest(body);
    CallContext ctx = CallContext.getCallContext(wsContext.getMessageContext());
    System.out.println("Info from CallContext:");
    System.out.println("- Call ID is " + ctx.getCallId());
    /**
     ** Storing Call Context ***
     */
    System.out.println("Storing CallContext:");
    CallContextStore<CallContext> ccs = new CallContextStore<CallContext>();
    String callContextKey;
    try {
        callContextKey = ccs.saveObject(ctx);
        System.out.println("- callContext saved with key: " + callContextKey);
    } catch (Exception e) {
        callContextKey = null;
        System.out.println("Auxiliary Storage Service seems to be unavailable.");
        System.out.println("Proceeding without storing the CallContext.");
    }
    if (callContextKey != null) {
        /**
         ** Restoring Call Context ***
         */
        System.out.println("Restoring CallContext:");
        ctx = ccs.getStoredObject(callContextKey);
        System.out.println("- callContext restored");
        System.out.println("Info from restored CallContext:");
        System.out.println("- Call ID is " + ctx.getCallId());
        /**
         ** Remove Call context **
         */
        ccs.removeStoredObject(callContextKey);
    }
    List<String> authorsLastNames = body.getAuthorLastName();
    if (authorsLastNames != null && authorsLastNames.size() > 0) {
        String authorsLastName = authorsLastNames.get(0);
        if (authorsLastName != null && authorsLastName.length() > 0 && !("Stripycat".equalsIgnoreCase(authorsLastName) || "Morillo".equalsIgnoreCase(authorsLastName))) {
            SeekBookError e = prepareException("No book available from author " + authorsLastName);
            System.out.println("No book available from author " + authorsLastName);
            System.out.println("\nSending business fault (SeekBook error) with parameters:");
            Utils.showSeekBookError(e);
            LibraryConsumer libraryConsumer = ctx.createCallbackProxy(LibraryConsumer.class);
            libraryConsumer.seekBookInBasementFault(e.getFaultInfo());
            if (callContextKey != null) {
                /**
                 ** Removing Call Context ***
                 */
                System.out.println("Removing CallContext:");
                ccs.removeStoredObject(callContextKey);
                System.out.println("- callContext removed");
            }
            return;
        }
    }
    ListOfBooks result = new ListOfBooks();
    BookType book1 = new BookType();
    if (authorsLastNames.contains("Stripycat")) {
        book1 = new BookType();
        result.getBook().add(book1);
        PersonType author = new PersonType();
        book1.getAuthor().add(author);
        author.setFirstName("John");
        author.setLastName("Stripycat");
        Calendar dateOfBirth = new GregorianCalendar(202, Calendar.MAY, 17);
        author.setDateOfBirth(dateOfBirth.getTime());
        book1.getTitle().add("Hunting basement inhabitants");
        book1.getPublisher().add("Dusty Edition");
        book1.setYearPublished("2013");
    }
    if (authorsLastNames.contains("Morillo")) {
        BookType book = new BookType();
        result.getBook().add(book);
        PersonType author = new PersonType();
        book.getAuthor().add(author);
        author.setFirstName("David A.");
        author.setLastName("Morillo");
        Calendar dateOfBirth = new GregorianCalendar(1970, Calendar.JANUARY, 1);
        author.setDateOfBirth(dateOfBirth.getTime());
        book.getTitle().add("The book about software");
        book.getPublisher().add("Frosty Edition");
        book.setYearPublished("2006");
    }
    System.out.println("Book(s) is found:");
    showSeekBookResponse(result);
    ctx.setupCallbackProxy(callbackResponseClient);
    callbackResponseClient.seekBookInBasementResponse(result);
    if (authorsLastNames.contains("Stripycat")) {
        book1.getTitle().set(0, "Hunting more basement inhabitants");
        book1.setYearPublished("2014");
        result.getBook().clear();
        result.getBook().add(book1);
    }
    showSeekBookResponse(result);
    ctx.setupCallbackProxy(callbackResponseClient);
    callbackResponseClient.seekBookInBasementResponse(result);
    if (callContextKey != null) {
        /**
         ** Removing Call Context ***
         */
        System.out.println("Removing CallContext:");
        ccs.removeStoredObject(callContextKey);
        System.out.println("- callContext removed");
    }
    try {
        Thread.sleep(1000);
        libraryPublisher.publishNewBooksNotifications();
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
}
Also used : LibraryConsumer(org.talend.services.demos.library._1_0.LibraryConsumer) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) PersonType(org.talend.types.demos.library.common._1.PersonType) CallContext(org.talend.esb.mep.requestcallback.feature.CallContext) CallContextStore(org.talend.esb.mep.requestcallback.impl.callcontext.CallContextStore) ListOfBooks(org.talend.types.demos.library.common._1.ListOfBooks) BookType(org.talend.types.demos.library.common._1.BookType) SeekBookError(org.talend.services.demos.library._1_0.SeekBookError)

Example 12 with PersonType

use of org.talend.types.test.library.common._1.PersonType in project tesb-rt-se by Talend.

the class LibraryServerImpl method seekBook.

@Override
public ListOfBooks seekBook(SearchFor body) throws SeekBookError {
    System.out.println("***************************************************************");
    System.out.println("*** seekBook request (Request-Response operation) is received *");
    System.out.println("***************************************************************");
    showSeekBookRequest(body);
    List<String> authorsLastNames = body.getAuthorLastName();
    if (authorsLastNames != null && authorsLastNames.size() > 0) {
        String authorsLastName = authorsLastNames.get(0);
        if (authorsLastName != null && authorsLastName.length() > 0 && !"Icebear".equalsIgnoreCase(authorsLastName)) {
            SeekBookError e = prepareException("No book available from author " + authorsLastName);
            System.out.println("No book available from author " + authorsLastName);
            System.out.println("\nSending business fault (SeekBook error) with parameters:");
            throw e;
        }
    }
    ListOfBooks result = new ListOfBooks();
    BookType book = new BookType();
    result.getBook().add(book);
    PersonType author = new PersonType();
    book.getAuthor().add(author);
    author.setFirstName("Jack");
    author.setLastName("Icebear");
    Calendar dateOfBirth = new GregorianCalendar(101, Calendar.JANUARY, 2);
    author.setDateOfBirth(dateOfBirth.getTime());
    book.getTitle().add("Survival in the Arctic");
    book.getPublisher().add("Frosty Edition");
    book.setYearPublished("2010");
    System.out.println("Book(s) is found:");
    showSeekBookResponse(result);
    return result;
}
Also used : BookType(org.talend.types.test.library.common._1.BookType) SeekBookError(org.talend.services.test.library._1_0.SeekBookError) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) PersonType(org.talend.types.test.library.common._1.PersonType) ListOfBooks(org.talend.types.test.library.common._1.ListOfBooks)

Example 13 with PersonType

use of org.talend.types.test.library.common._1.PersonType in project tesb-rt-se by Talend.

the class LibraryServerImpl method seekBook.

@Override
public ListOfBooks seekBook(SearchFor body) throws SeekBookError {
    System.out.println("***************************************************************");
    System.out.println("*** seekBook request (Request-Response operation) is received *");
    System.out.println("***************************************************************");
    showSeekBookRequest(body);
    List<String> authorsLastNames = body.getAuthorLastName();
    if (authorsLastNames != null && authorsLastNames.size() > 0) {
        String authorsLastName = authorsLastNames.get(0);
        if (authorsLastName != null && authorsLastName.length() > 0 && !"Icebear".equalsIgnoreCase(authorsLastName)) {
            SeekBookError e = prepareException("No book available from author " + authorsLastName);
            System.out.println("No book available from author " + authorsLastName);
            System.out.println("\nSending business fault (SeekBook error) with parameters:");
            throw e;
        }
    }
    ListOfBooks result = new ListOfBooks();
    BookType book = new BookType();
    result.getBook().add(book);
    PersonType author = new PersonType();
    book.getAuthor().add(author);
    author.setFirstName("Jack");
    author.setLastName("Icebear");
    Calendar dateOfBirth = new GregorianCalendar(101, Calendar.JANUARY, 2);
    author.setDateOfBirth(dateOfBirth.getTime());
    book.getTitle().add("Survival in the Arctic");
    book.getPublisher().add("Frosty Edition");
    book.setYearPublished("2010");
    System.out.println("Book(s) is found:");
    showSeekBookResponse(result);
    return result;
}
Also used : BookType(org.talend.types.test.library.common._1.BookType) SeekBookError(org.talend.services.test.library._1_0.SeekBookError) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) PersonType(org.talend.types.test.library.common._1.PersonType) ListOfBooks(org.talend.types.test.library.common._1.ListOfBooks)

Example 14 with PersonType

use of org.talend.types.test.library.common._1.PersonType in project ddf by codice.

the class RegistryPackageTypeHelperTest method testGetPersonsFromRegistryObjectList.

@Test
public void testGetPersonsFromRegistryObjectList() throws Exception {
    RegistryObjectListType registryObjectList = ((RegistryPackageType) registryObject).getRegistryObjectList();
    List<PersonType> persons = rptHelper.getPersons(registryObjectList);
    assertPersons(persons);
}
Also used : RegistryObjectListType(oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryObjectListType) RegistryPackageType(oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryPackageType) PersonType(oasis.names.tc.ebxml_regrep.xsd.rim._3.PersonType) Test(org.junit.Test)

Example 15 with PersonType

use of org.talend.types.test.library.common._1.PersonType in project ddf by codice.

the class RegistryPackageTypeHelperTest method assertPersons.

private void assertPersons(List<PersonType> persons) {
    // Values from xml file
    int expectedPersonsSize = 3;
    int expectedSize = 1;
    String expectedFirstName = "john";
    String expectedMiddleName = "middleName";
    String expectedLastname = "doe";
    String expectedCity = "Phoenix";
    String expectedCountry = "USA";
    String expectedPostalCode = "85037";
    String expectedState = "AZ";
    String expectedStreet = "1234 Some Street";
    String expectedAreaCode = "111";
    String expectedNumber = "111-1111";
    String expectedExtension = "1234";
    String expectedCountryCode = "country";
    String expectedPhoneType = "cell phone";
    String expectedEmail = "emailaddress@something.com";
    assertThat(persons, hasSize(expectedPersonsSize));
    PersonType person = persons.get(0);
    assertThat(person.isSetPersonName(), is(true));
    assertPersonName(person.getPersonName(), expectedFirstName, expectedMiddleName, expectedLastname);
    assertThat(person.isSetAddress(), is(true));
    List<PostalAddressType> addresses = person.getAddress();
    assertThat(addresses, hasSize(expectedSize));
    assertAddress(addresses.get(0), expectedCity, expectedCountry, expectedPostalCode, expectedState, expectedStreet);
    assertThat(person.isSetTelephoneNumber(), is(true));
    List<TelephoneNumberType> phoneNumbers = person.getTelephoneNumber();
    assertThat(phoneNumbers, hasSize(expectedSize));
    assertPhoneNumbers(phoneNumbers.get(0), expectedAreaCode, expectedNumber, expectedExtension, expectedCountryCode, expectedPhoneType);
    assertThat(person.isSetEmailAddress(), is(true));
    assertThat(person.getEmailAddress(), hasSize(expectedSize));
    List<EmailAddressType> emailAddresses = person.getEmailAddress();
    assertThat(emailAddresses.get(0).getAddress(), is(equalTo(expectedEmail)));
}
Also used : TelephoneNumberType(oasis.names.tc.ebxml_regrep.xsd.rim._3.TelephoneNumberType) PersonType(oasis.names.tc.ebxml_regrep.xsd.rim._3.PersonType) EmailAddressType(oasis.names.tc.ebxml_regrep.xsd.rim._3.EmailAddressType) PostalAddressType(oasis.names.tc.ebxml_regrep.xsd.rim._3.PostalAddressType)

Aggregations

PersonType (oasis.names.tc.ebxml_regrep.xsd.rim._3.PersonType)10 Calendar (java.util.Calendar)8 GregorianCalendar (java.util.GregorianCalendar)8 OrganizationType (oasis.names.tc.ebxml_regrep.xsd.rim._3.OrganizationType)5 SeekBookError (org.talend.services.test.library._1_0.SeekBookError)5 BookType (org.talend.types.test.library.common._1.BookType)5 ListOfBooks (org.talend.types.test.library.common._1.ListOfBooks)5 PersonType (org.talend.types.test.library.common._1.PersonType)5 ExtrinsicObjectType (oasis.names.tc.ebxml_regrep.xsd.rim._3.ExtrinsicObjectType)4 ServiceType (oasis.names.tc.ebxml_regrep.xsd.rim._3.ServiceType)4 BookType (org.talend.types.demos.library.common._1.BookType)4 PersonType (org.talend.types.demos.library.common._1.PersonType)4 AssociationType1 (oasis.names.tc.ebxml_regrep.xsd.rim._3.AssociationType1)3 RegistryObjectListType (oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryObjectListType)3 RegistryObjectType (oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryObjectType)3 RegistryPackageType (oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryPackageType)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 SeekBookError (org.talend.services.demos.library._1_0.SeekBookError)2