Tutorial 07 - Creating a landing report locally and storing it in the eLandings database

Third party developers have the ability to create landing reports within their own applications. Locally created landing reports can then be submitted to the eLandings database for storage.

In this tutorial we will look at how one might create a landing report in code and than submit it to the eLandings database.

For the completed code see ElandingsClient.zip

In this code example we will be working primarily in ElandingsClient.java - This is in an effort to keep the example relatively simple. In a production situation, much of this work could be done within a LandingReportWrapper.java

Within ElandingsClient.java, create the method

public void createAndUploadLandingReport() throws JAXBException, DatatypeConfigurationException {
  //Create an empty object to hold all of our landing report information
  LandingReport landingReport = new LandingReport();
}

The LandingReport object is one of the generated objects created from the landingreport.xsd file.

Whenever you create a landing report, you will need to get a landingReportId from the elandings database. For each CFEC permit associated with the landing report, you will need to get a fish ticket number from the elandings database. In our example, we will define one CFEC permit so we will only need to get one fish ticket number.

WARNING: Landing Report Id's and Fish Ticket Numbers can be reserved in batches and stored locally for later use. Care must be taken to avoid in inappropriate reuse of these numbers. Each landing report must have a unique landing report number. Each CFEC permit on a landing report must have a unique fish ticket number. If a number is used on one landing report and then later used on another landing report. The first landing report will be overwritten in an unpredictable manner.

To get a landing report id from the elandings database and assign it to our new landingReport object:

//Get a Landing Report ID from the eLandings database
  String landingReportNumberXML = svc.getReportNumbers("amarx", "A_marx", "2.3", "1");
  NumberInfoWrapper lr = new NumberInfoWrapper(landingReportNumberXML, unmarshaller);
  System.out.println("From elandings, reserved for my use - landing report id " + lr.getInfo().getLandingReportId().get(0).getValue().toString());

  //Store the landing report id in your local landingReport object
  LandingReportId lrId = new LandingReportId();
  lrId.setValue(lr.getInfo().getLandingReportId().get(0).getValue());
  landingReport.setLandingReportId(lrId);

To get a fish ticket Number from the elandings database:

//In order to get a fish ticket number, we need a legal operation id for the user.
   //One way to get a legal operation id is from the processorUserInfo
   String processorUserInfoXML = svc.getUserInfo("amarx", "A_marx", "2.3");
   ProcessorUserInfoWrapper userInfoWrapper = new ProcessorUserInfoWrapper(processorUserInfoXML, unmarshaller);

   //A user has many operationIds, so you may need to iterate over the list of operations to find the one you want.
   BigInteger operationId = userInfoWrapper.getUserInfo().getProcessorUser().get(0).getDefaultOperationId().getValue();

   //Get a Fish Ticket Number from the eLandings database
   String fishTicketNumberXML = svc.getFishTicketNumbers("amarx", "A_marx", "2.3", operationId.toString(), "1");

   //Get a fish ticket number from the eLandings database
   NumberInfoWrapper ft = new NumberInfoWrapper(fishTicketNumberXML, unmarshaller);
   System.out.println("From elandings, reserved for my use - fish ticket number " + ft.getInfo().getFishTicketNumber().get(0).getValue().toString());

   String ftNumber = ft.getInfo().getFishTicketNumber().get(0).getValue().toString();

We will store the fish ticket number in our landingReport object later when we create a permit_item.

Next we will fill out some of the landingReport data:

   TypeOfLandingReport typeOfLandingReport = new TypeOfLandingReport();
   typeOfLandingReport.setValue("B");//Salmon Landing Report Type
   landingReport.setTypeOfLandingReport(typeOfLandingReport);

   SchemaVersion schemaVersion = new SchemaVersion();
   schemaVersion.setValue(new BigDecimal(2.3));
   landingReport.setSchemaVersion(schemaVersion);

   landingReport.setDataEntryUser("amarx");
   landingReport.setLastChangeUser("amarx");

   DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
   SimpleDateFormat slashFmt = new SimpleDateFormat("MM/dd/yyyy");
   Date calendarDate = null;
   XMLGregorianCalendar dateArg = null;
   try {
       calendarDate = slashFmt.parse("01/20/2010");
       Calendar date = new GregorianCalendar();
       date.setTimeInMillis(calendarDate.getTime());

       dateArg = (null == date) ? null : datatypeFactory.newXMLGregorianCalendar((GregorianCalendar) date);
   } catch (ParseException ex) {
       Logger.getLogger(ElandingsClient.class.getName()).log(Level.SEVERE, null, ex);
   }

   landingReport.setDataEntrySubmitDate(dateArg);
   landingReport.setLastChangeDate(dateArg);

Every landing report has a header object. We will create that object and populate it next:

   Header header = new Header();
   DateFishingBegan dateFishingBegan = new DateFishingBegan();
   dateFishingBegan.setValue(dateArg);
   header.setDateFishingBegan(dateFishingBegan);

   header.setDateFishingEnded(dateArg);

   DateOfLanding dateOfLanding = new DateOfLanding();
   dateOfLanding.setValue(dateArg);
   header.setDateOfLanding(dateOfLanding);

   DaysFished daysFished = new DaysFished();
   daysFished.setValue(BigInteger.valueOf(1));
   header.setDaysFished(daysFished);

   Vessel vessel = new Vessel();
   vessel.setValue(BigInteger.valueOf(538));
   vessel.setName("Garbage Name");//This value will be replaced on save by the name associated with the vessel number in the database.
   header.setVessel(vessel);

   CrewSize crewSize = new CrewSize();
   crewSize.setValue(BigInteger.valueOf(4));
   header.setCrewSize(crewSize);

   ObserversOnboard observersOnboard = new ObserversOnboard();
   observersOnboard.setValue(BigInteger.ZERO);
   header.setObserversOnboard(observersOnboard);

   PortOfLanding portOfLanding = new PortOfLanding();
   portOfLanding.setValue("JNU");
   header.setPortOfLanding(portOfLanding);

   Gear gear = new Gear();
   gear.setValue(BigInteger.valueOf(4));
        header.setGear(gear);

   ProcCodeOwner procCodeOwner = new ProcCodeOwner();
   ProcCode procCode = new ProcCode();
   procCode.setValue("F1234");
   procCodeOwner.setProcCode(procCode);
   header.setProcCodeOwner(procCodeOwner);

   PartialDelivery partialDelivery = new PartialDelivery();
   partialDelivery.setValue(false);
   header.setPartialDelivery(partialDelivery);

   LastDeliveryForTrip lastDeliveryForTrip = new LastDeliveryForTrip();
   lastDeliveryForTrip.setValue(true);
   header.setLastDeliveryForTrip(lastDeliveryForTrip);

   MultipleIfqPermits multipleIfqPermits = new MultipleIfqPermits();
   multipleIfqPermits.setValue(false);
   header.setMultipleIfqPermits(multipleIfqPermits);

   ManualIfqReport manualIfqReport = new ManualIfqReport();
   manualIfqReport.setValue(false);
   header.setManualIfqReport(manualIfqReport);

   NearestBayOrHeadland nearestBayOrHeadland = new NearestBayOrHeadland();
   nearestBayOrHeadland.setValue("Icy Point");
   header.setNearestBayOrHeadland(nearestBayOrHeadland);

   FederalProcessorNumber federalProcessorNumber = new FederalProcessorNumber();
   federalProcessorNumber.setValue(BigInteger.valueOf(12345));
   header.setFederalProcessorNumber(federalProcessorNumber);

   RegisteredBuyerNumber registeredBuyerNumber = new RegisteredBuyerNumber();
   registeredBuyerNumber.setValue(BigInteger.valueOf(123456));
   header.setRegisteredBuyerNumber(registeredBuyerNumber);

   RegisteredCrabReceiverNumber registeredCrabReceiverNumber = new RegisteredCrabReceiverNumber();
   registeredCrabReceiverNumber.setValue(BigInteger.valueOf(123456));
   header.setRegisteredCrabReceiverNumber(registeredCrabReceiverNumber);

   ChillType chillType = new ChillType();
   chillType.setValue("RSW");
   header.setChillType(chillType);

   RswTemp rswTemp = new RswTemp();
   rswTemp.setValue(BigDecimal.valueOf(33.2));
   header.getRswTemp().add(rswTemp);
   //System.out.println("Temperature "+ header.getRswTemp().get(0).getValue().toString());

   DockDelivery dockDelivery = new DockDelivery();
   dockDelivery.setValue(false);
   header.setDockDelivery(dockDelivery);

   DualPermit dualPermit = new DualPermit();
   dualPermit.setValue(false);
   header.setDualPermit(dualPermit);

A user may define a stat area within a stat_area_worksheet on the header or on the individual line items later on. In this example, we will create a stat_area_worksheet and apply it to the header:

   StatAreaWorksheet statAreaWorksheet = new StatAreaWorksheet();
   StatArea statArea = new StatArea();
   statArea.setValue(BigInteger.valueOf(10110));
   statAreaWorksheet.setStatArea(statArea);
   Percent statAreaPercent = new Percent();
   statAreaPercent.setValue(BigInteger.valueOf(100));
   statAreaWorksheet.setPercent(statAreaPercent);

   header.getStatAreaWorksheet().add(statAreaWorksheet);

Every landing report header has one or more CFEC permits associated with it. In this example we will use one CFEC permit. We will store the fish ticket number, that we got above from the eLandings database, in the permitWorksheet item now:

   PermitWorksheet permitWorksheet = new PermitWorksheet();
   CfecPermit cfecPermit = new CfecPermit();

   Fishery fishery = new Fishery();
   fishery.setValue("S04D");
   cfecPermit.setFishery(fishery);

   PermitNumber permitNumber = new PermitNumber();
   permitNumber.setValue("00127E");
   cfecPermit.setPermitNumber(permitNumber);

   YearSeq yearSeq = new YearSeq();
   yearSeq.setValue("1101Q");
   cfecPermit.setYearSeq(yearSeq);

   permitWorksheet.setCfecPermit(cfecPermit);

   MagStripeRead magStripeRead = new MagStripeRead();
   magStripeRead.setValue(false);
   permitWorksheet.setMagStripeRead(magStripeRead);

   ManagementProgram managementProgram = new ManagementProgram();
   Program program = new Program();
   program.setValue("OA");
   managementProgram.setProgram(program);
   permitWorksheet.setManagementProgram(managementProgram);

   Percent percent = new Percent();
   percent.setValue(BigInteger.valueOf(100));
   permitWorksheet.setPercent(percent);

   FishTicketNumber fishTicketNumber = new FishTicketNumber();
   fishTicketNumber.setValue(ftNumber);
   permitWorksheet.setFishTicketNumber(fishTicketNumber);

   header.getPermitWorksheet().add(permitWorksheet);

Now that we have a complete header object, we will put it in our landingReport object

landingReport.setHeader(header);

Next we will create a line item on for the landingReport:

   LineItem lineItem = new LineItem();
   lineItem.setFishTicketNumber(fishTicketNumber);
//We could set the stat area for a specific line item by doing the following
//        StatArea statArea = new StatArea();
//        statArea.setValue(BigInteger.valueOf(10110));
//        lineItem.setStatArea(statArea);

   Species species = new Species();
   species.setValue(BigInteger.valueOf(450));
   lineItem.setSpecies(species);

   ConditionCode conditionCode = new ConditionCode();
   conditionCode.setValue(BigInteger.ONE);
   lineItem.setConditionCode(conditionCode);

   Weight weight = new Weight();
   weight.setValue(BigDecimal.valueOf(1000.0));
   lineItem.setWeight(weight);

   Count count = new Count();
   count.setValue(BigDecimal.valueOf(200.0));
   lineItem.setCount(count);

   DispositionCode dispositionCode = new DispositionCode();
   dispositionCode.setValue(BigInteger.valueOf(60));
   lineItem.setDispositionCode(dispositionCode);

In some cases, users wish to set the grading and pricing information on a line item. There can be zero or more grading items:

   ProductItem productItem = new ProductItem();
   ItemNumber itemNumber = new ItemNumber();
   itemNumber.setValue(BigInteger.valueOf(1));
   productItem.setItemNumber(itemNumber);

   Price price = new Price();
   price.setValue(BigDecimal.valueOf(1.23));
   productItem.setPrice(price);

   ProductCode productCode = new ProductCode();
   productCode.setValue(BigInteger.valueOf(23));
   productItem.setProductCode(productCode);

   ProductType productType = new ProductType();
   productType.setValue("P");
   productItem.setProductType(productType);

   SizeGrade sizeGrade = new SizeGrade();
   sizeGrade.setValue("Bright");
   productItem.setSizeGrade(sizeGrade);
   productItem.setWeight(weight);

   lineItem.getProductItem().add(productItem);

Now that we have a line item, we can store it in the landingReport object:

   landingReport.getLineItem().add(lineItem);

In order to send a landingReport object to the webservice and to the database, we need to convert it to an XML string. We will use our LandingReportWrapper object to convert our LandingReport object into an XML string:

   LandingReportWrapper landingReportWrapper = new LandingReportWrapper();
   landingReportWrapper.setRpt(landingReport);

   String landingReportXML = landingReportWrapper.toXmlString(marshaller);

Finally we can send the landing report xml string to the web service to be validated and stored in the database.

   System.out.println();
   String landingReportXMLReturnedFromWS = svc.submitInitialLandingReport("amarx", "A_marx", "2.3", landingReportXML);
   System.out.println(landingReportXMLReturnedFromWS);

The web service will return a validated landing report back. Proper name attributes should be filled out for you on success. On failure, error messages will be included in the return xml string.