⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shopownerbean.java

📁 噶额外噶外骨骼感广泛高热感 就 啊啊
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
   * @param <b>shopID</b> - ID of the shop whose details have to be queried
   * @param <b>langID</b> - Language in which the details have to be queried
   * @return <b>Shop</b>  - Details of the shop
   * @throws <b>ShopException</b> if the shop details cannot be queried
   * @throws <b>RemoteException</b> container error
   */
  public Shop getShopDetails(String shopID, String langID) throws ShopException {

    // Check if the shop has been specified
    if( shopID == null || "".equals(shopID.trim()) ) {
      throw new ShopException("Insufficient information", "error.shop.shopnull");          
    }
    // Check if the language in which shop details are required has been specified
    if( langID == null || "".equals(langID.trim()) ) {
      throw new ShopException("Insufficient information", "error.shop.langnull");          
    }
  
    Shop  shopInfo = new Shop();  // Value object to hold shop information
    try {
      // Look up the shop bean
      ShopLocalHome shopHome   = getShopLocalHome();
      ShopLocal     shop       = shopHome.findByPrimaryKey( shopID );

      // Populate the value object with shop information
      shopInfo.setId(shopID);
      shopInfo.setCategoryId(shop.getCatID());
      shopInfo.setRegDate(shop.getRegDate());
      shopInfo.setStatus(shop.getStatus());
      shopInfo.setUserName(shop.getOwnerName());

      // Get the shop details
      Iterator detailsIter = shop.getShopDetails().iterator();
      List details = new ArrayList(1);
      while(detailsIter.hasNext() ) {
        /* If the language in which the shop details are match the language
           specified then populate the value object with shop details */
        ShopDetailLocal shopDetail = (ShopDetailLocal)detailsIter.next();
        if( shopDetail.getLangID().equals(langID)) {
          details.add(new ShopDetail(langID, shopDetail.getShopName(), shopDetail.getDescription()));
          shopInfo.setShopDetails(details);
          break;
        }  
      }
    } catch( Exception ex ) {
      ex.printStackTrace();
      throw new ShopException( "Unable to get shop information because " + 
                               ex.getMessage(), "error.shop.retrieval" );
    }
    return shopInfo;  
  }

  /**
   * This business method processes a discontinuance request for a shop
   * @param <b>shopID</b> - ID of the shop which has to be discontinued
   * @param <b>reason</b> - Reason for the discontinuance
   * @param <b>langID</b> - Language in which the reason for discontinuance 
   *                        is specified
   * @throws <b>ShopException</b> if the shop cannot be discontinued
   * @throws <b>RemoteException</b> container error
   */
  public void discontinueShop( String shopID, String reason, String langID ) 
                               throws ShopException {

    // Check if the shop ID has been specified                               
    if( shopID == null || "".equals(shopID.trim()) ) {
      throw new ShopException("Insufficient information", "error.shop.shopnull");          
    }

    // Check if the reason of discontinuance has been specified    
    if( reason == null || "".equals(reason.trim()) ) {
      throw new ShopException("Reason not specified", "error.shop.reasonnull");          
    }

    /* Check if the language in which the reason for discontinuance is given has
       been specified */
    if( langID == null || "".equals(langID.trim())) {
      throw new ShopException("Insufficient information", "error.shop.langnull");          
    }

    try {

      // Check if there are any pending orders for the given shop.   
      ProductOrderLocalHome orderHome = getOrderLocalHome();
      Collection orders = orderHome.findPendingOrdersForShop( shopID );
      
      // Shop can be discontinued only if there are no orders pending.                           
      if( orders.size() > 0 ) {
        throw new ShopException("Cannot discontinue shops as there are orders " +
                                "pending on it","error.shop.pendingorders");          
      }

      // No pending orders - proceed with discontinuance
      ShopLocalHome shopHome = getShopLocalHome();
      ShopLocal shop = shopHome.findByPrimaryKey(shopID);
        
      // Set the status of the shop as discontinued
      shop.setStatus(Constants.DISCONTINUED);
      
      ShopDetailLocal shopDetail = null;      
      String          shopName   = null;
      Collection      shopsList  = shop.getShopDetails();

      /* Loop through the shop Details and set the reason as shop description
         for the record with matching language */ 
      for( Iterator shopsIter = shopsList.iterator(); shopsIter.hasNext(); ) {
        shopDetail = (ShopDetailLocal)shopsIter.next();
        if( shopDetail.getLangID().equals(langID) ) {
          shopName = shopDetail.getShopName();     
          shopDetail.remove(); 
          break;                    
        }
      } 
      ShopDetailLocalHome shopDetailHome = getShopDetailLocalHome();
      shopsList = new ArrayList();
      shopsList.add(shopDetailHome.create( shopID, langID, shopName, reason));
      shop.setShopDetails(shopsList);

      // Lookup the shop owner information to change user role
      CustomerLocalHome home = getCustomerLocalHome();
      CustomerLocal user = home.findByPrimaryKey( shop.getOwnerName() );
      user.setRole("shopuser");

      // Send notification to admin
      StringBuffer mailBody = new StringBuffer();

      // Load the property file to send the notification in the appropriate language 
      Properties emailMessages = Utilities.loadParams("EmailMessages", langID );
          
      // Append the mail body with proper contents.
      mailBody.append( emailMessages.getProperty("owner.email.greeting" ) );
      mailBody.append( emailMessages.getProperty("owner.email.message" ) );
      mailBody.append( emailMessages.getProperty("user.email.shopname" ) );
      mailBody.append( shopName + "\n" );
      mailBody.append( emailMessages.getProperty("owner.email.requestmessage" ) );
      mailBody.append( "\n" + shop.getOwner() );
         
      // Create the mail content object.
      MailContent mailContent = new MailContent();
      mailContent.setFrom( user.getEmail() );
      mailContent.setTo( getAdminEmail() );
      mailContent.setSubject( emailMessages.getProperty("owner.email.discontinuesubject" ) );
      mailContent.setBody( mailBody.toString() );

      Mailer.sendMail(mailContent);
    } catch( Exception ex ) {
      if( ex instanceof ShopException )
        throw new ShopException("Cannot discontinue shops as there are orders " +
                                "pending on it","error.shop.pendingorders");          
      else
        throw new ShopException( "Unable to discontinue shop because " + 
                                 ex.getMessage(),"error.shop.discontinuation" );
    }
  }

  /**
   * This business method retrieves the shop ID owned by the specified user
   * @param <b>userName</b> - username of the shop owner
   * @return <b>String</b>  - ID of the shop
   * @throws <b>ShopException</b> if the shop information cannot be retrieved
   * @throws <b>RemoteException</b> container error
   */
  public String getShopForUser(String userName) throws ShopException {

    // Check if the shop owner name has been specified
    if( userName== null || "".equals(userName.trim()) ) {
      throw new ShopException("UserName not specified", "error.shop.usernull");
    }
    
    String shopID = null;
    try {
      // Locate the shop for the username specified
      ShopLocalHome shopHome   = getShopLocalHome();
      Collection shops = shopHome.findShopForUser(userName);

      // If shop found, get the ID of the shop else form an appropriate message
      if( shops != null && shops.size() > 0 ) {
        shopID = ((ShopLocal)shops.iterator().next()).getId();
      } else {
        shopID = "No shops found for user";
      }
    } catch( Exception ex ) {
      throw new ShopException( "Unable to get shop for user because " + 
                               ex.getMessage(),"error.shop.retrieval" );
    }
    return shopID;
  }

  /*
   * Returns the local home for Item entity
   */  
  private ItemLocalHome getItemLocalHome() {
    return (ItemLocalHome)ServiceLocator.getLocator().getService( "java:comp/env/ejb/ItemLocal" );
  }

  /*
   * Returns the local home for ItemDetail entity
   */  
  private ItemDetailLocalHome getItemDetailLocalHome() {
    return (ItemDetailLocalHome)ServiceLocator.getLocator().getService( "java:comp/env/ejb/ItemDetailLocal" );
  }

  /*
   * Returns the local home for Order entity
   */  
  private ProductOrderLocalHome getOrderLocalHome() {
    return (ProductOrderLocalHome)ServiceLocator.getLocator().getService( "java:comp/env/ejb/OrderLocal" );
  }  

 /*
   * Returns the local home for Order item entity
   */  
  private OrderItemLocalHome getOrderItemLocalHome() {
    return (OrderItemLocalHome)ServiceLocator.getLocator().getService( "java:comp/env/ejb/OrderItemLocal" );
  }  


  /*
   * Returns the local home for Item Attribute entity
   */  
  private ItemAttributeLocalHome getItemAttributeLocalHome() {
    return (ItemAttributeLocalHome)ServiceLocator.getLocator().getService( "java:comp/env/ejb/ItemAttributeLocal" );
  }  

  /*
   * Returns the local home for Sub Category entity
   */  
  private SubCategoryLocalHome getSubCategoryLocalHome() {
    return (SubCategoryLocalHome)ServiceLocator.getLocator().getService( "java:comp/env/ejb/SubCategoryLocal" );
  }  

  /*
   * Returns the local home for Shop entity
   */  
  private ShopLocalHome getShopLocalHome() {
    return (ShopLocalHome)ServiceLocator.getLocator().getService( "java:comp/env/ejb/ShopLocal" );
  }  

  /*
   * Returns the local home for Shop Detail entity
   */  
  private ShopDetailLocalHome getShopDetailLocalHome() {
    return (ShopDetailLocalHome)ServiceLocator.getLocator().getService( "java:comp/env/ejb/ShopDetailLocal" );
  } 

  /*
   * Returns the local home for User entity
   */  
  private CustomerLocalHome getCustomerLocalHome() {
    return (CustomerLocalHome)ServiceLocator.getLocator().getService( "java:comp/env/ejb/UserLocal" );
  }

  /*
   * Returns the local home for Inventory entity
   */  
  private InventoryLocalHome getInventoryLocalHome() {
    return (InventoryLocalHome)ServiceLocator.getLocator().getService( "java:comp/env/ejb/InventoryLocal" );
  }    
  
  /*
   * Returns the email id of the VSM administrator or null if it cannot be found
   */  
  private String getAdminEmail() {
    try {
      // find user home,
      CustomerLocalHome home = getCustomerLocalHome();
      // find the ADMIN entity and return the email id
      return home.findByPrimaryKey( "admin" ).getEmail();
    }
    catch( Exception ex ) {
      ex.printStackTrace();
      return null;
    }
  }    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -