Link to home
Start Free TrialLog in
Avatar of yankeebushsoftware
yankeebushsoftwareFlag for United States of America

asked on

Can someone comment what this if statements are doing in this method?

Can someone comment what this if statements are doing in this method?
public Attribute[] saveLab(Lab lab) throws ManagementSupportException {
             // creating "request" object using service's method
            TEServiceStub.SaveLab request = new TEServiceStub.SaveLab();

            TEServiceStub.AttributeArray array = new TEServiceStub.AttributeArray();
            List<TEServiceStub.Attribute> attrs = new ArrayList<TEServiceStub.Attribute>();

            if(lab.getId() > 0) {
                  TEServiceStub.Attribute attr = new TEServiceStub.Attribute();
                  attr.setName("LAB_ID");
                  attr.setValue(String.valueOf(lab.getId()));
                  attrs.add(attr);
            }

            if(lab.getDescription() != null && lab.getDescription().length() > 0) {
                  TEServiceStub.Attribute attr = new TEServiceStub.Attribute();
                  attr.setName("DESCRIPTION");
                  attr.setValue(lab.getDescription());
                  attrs.add(attr);
            }

            if(lab.getLocation() != null && lab.getLocation().length() > 0) {
                  TEServiceStub.Attribute attr = new TEServiceStub.Attribute();
                  attr.setName("LOCATION");
                  attr.setValue(lab.getLocation());
                  attrs.add(attr);
            }

            if(lab.getOwner() != null && lab.getOwner().length() > 0) {
                  TEServiceStub.Attribute attr = new TEServiceStub.Attribute();
                  attr.setName("OWNER");
                  attr.setValue(lab.getOwner());
                  attrs.add(attr);
            }
            array.setAttributes((TEServiceStub.Attribute[]) attrs.toArray());

            request.setAttributes(array);
            // declaring "response" object
            TEServiceStub.SaveLabResponse response = null;
            try {
                  // invoking web service's method
                  response = stub.saveLab(request);
            } catch (RemoteException e) {
                  logger.warn("Fail to call TEService :" + e);
                  throw new ManagementSupportException("Fail to call TEService :" + e);
            }
            // processing "response" object
            if(!response.getStatus().getSuccess()) {
                  logger.warn("TEService return failure while call saveLab()");
                  throw new ManagementSupportException("TEService return failure while call saveLab()");
            }

            return cast(response.getAttributes());
      }
ASKER CERTIFIED SOLUTION
Avatar of elfe69
elfe69
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial