コード例 #1
0
  public boolean updateBrand(Brand to) {
    try {
      Long id = to.getId();
      System.out.println("id: " + id);
      Brand po = SpringUtil.getBrandManager().getBrand(id);
      //    		String bkn = po.getKeyName();
      //    		String fkn = null;
      //    		String fid = null;
      //    		DSFile newFile = null, oldFile = null;
      MyPropertyUtil.copySimpleProperties(po, to);
      //    		if(to.getLogoFile()==null) {
      //    			// no new logofile, do nothing
      //    		}
      //    		else {
      //    			oldFile = po.getLogoFile();
      //        		newFile = to.getLogoFile();
      //    			fkn = DataStoreUtils.genKeyName(newFile);
      //    			fid = KeyFactory.keyToString(new KeyFactory.Builder("Brand",bkn).addChild("DSFile",
      // fkn).getKey());
      //    			newFile.setKeyName(fkn);
      //    			po.setLogoFileId(fid);
      //    			po.setLogoFile(newFile);
      //    			boolean suc = txdelete(oldFile);
      //    		}

      SpringUtil.getBrandManager().saveBrand(po);
      Long res = po.getId();
      return true;
    } catch (Exception e) {
      e.printStackTrace();
      throw new RuntimeException(e);
    }
  }
コード例 #2
0
  public boolean updateGoods(Goods to) {
    try {
      Long id = to.getId();
      System.out.println("id: " + id);
      Goods po = SpringUtil.getGoodsManager().getGoods(id);

      System.out.println("1) size of po.gallery: " + po.getGalleries().size());

      //    		String goodskn = po.getKeyName();

      MyPropertyUtil.copySimpleProperties(po, to);
      // TODO image/thumb

      Set<Gallery> toGalleries = to.getGalleries();
      for (Gallery gallery : toGalleries) {
        if (gallery.getId() != null || gallery.getId() < 0) {
          // existing gallery
          for (Gallery gpo : po.getGalleries()) {
            if (gpo.getId().equals(gallery.getId())) {
              gpo.setDescription(gallery.getDescription());
              break;
            }
          }
          //					dao.update(gallery);
          //					gallery.setImageFileId(gallery.getImageFile().getPkId());
        } else {
          // new gallery
          //					String gkn = DataStoreUtils.genKeyName(gallery);
          //					gallery.setKeyName(gkn);
          //					DSFile file = gallery.getImageFile();
          //					String fkn = DataStoreUtils.genKeyName(file);
          //					file.setKeyName(fkn);
          //					String fid = KeyFactory.keyToString(new
          // KeyFactory.Builder("Goods",goodskn).addChild(GoodsGallery.class.getSimpleName(),
          // gkn).addChild("DSFile", fkn).getKey());
          //					gallery.setImageFileId(fid);
          //
          //					DSFile thumbfile = gallery.getThumbFile();
          //					String tfkn = DataStoreUtils.genKeyName(thumbfile);
          //					String tfid = KeyFactory.keyToString(new
          // KeyFactory.Builder("Goods",goodskn).addChild(GoodsGallery.class.getSimpleName(),
          // gkn).addChild("DSFile", tfkn).getKey());
          //					thumbfile.setKeyName(tfkn);
          //					gallery.setThumbFileId(tfid);
          //
          //					gallery.setLongId(UUIDLongGenerator.newUUID());
          po.getGalleries().add(gallery);
        }
      }

      System.out.println("2) size of po.gallery: " + po.getGalleries().size());

      Set<Gallery> galleries = po.getGalleries();
      if (galleries.size() > 0) {
        Gallery gallery = (Gallery) (galleries.iterator().next());
        po.setImage(gallery.getImageUrl());
        po.setThumb(gallery.getThumbUrl());
      } else {
        po.setImage(null);
      }

      po.getAttributes().clear();
      Set<GoodsAttribute> gts = to.getAttributes();
      for (GoodsAttribute gt : gts) {
        //				String gkn = DataStoreUtils.genKeyName(gt);
        //				gt.setKeyName(gkn);
        //				gt.setLongId(UUIDLongGenerator.newUUID());
        po.getAttributes().add(gt);
      }

      System.out.println("System.out.println(updateResponse);");
      SpringUtil.getGoodsManager().saveGoods(po);

      //			GoogleBaseUtil gbUtil = new
      // GoogleBaseUtil(SpringUtil.getShopConfigManager().getCachedShopConfig("en"));
      //			String token = gbUtil.authenticate();
      //			gbUtil.buildDataItem(po);
      //			String updateResponse = gbUtil.updateItem( token , po.getGoogleBaseDataId());
      //			System.out.println(updateResponse);

      return true;
    } catch (Exception e) {
      e.printStackTrace();
      throw new RuntimeException(e);
    }
  }