コード例 #1
0
  @Override
  protected void doImportStagedModel(PortletDataContext portletDataContext, Address address)
      throws Exception {

    long userId = portletDataContext.getUserId(address.getUserUuid());

    ServiceContext serviceContext = portletDataContext.createServiceContext(address);

    Address existingAddress =
        AddressLocalServiceUtil.fetchAddressByUuidAndCompanyId(
            address.getUuid(), portletDataContext.getCompanyId());

    Address importedAddress = null;

    if (existingAddress == null) {
      serviceContext.setUuid(address.getUuid());

      importedAddress =
          AddressLocalServiceUtil.addAddress(
              userId,
              address.getClassName(),
              address.getClassPK(),
              address.getStreet1(),
              address.getStreet2(),
              address.getStreet3(),
              address.getCity(),
              address.getZip(),
              address.getRegionId(),
              address.getCountryId(),
              address.getTypeId(),
              address.getMailing(),
              address.isPrimary(),
              serviceContext);
    } else {
      importedAddress =
          AddressLocalServiceUtil.updateAddress(
              existingAddress.getAddressId(),
              address.getStreet1(),
              address.getStreet2(),
              address.getStreet3(),
              address.getCity(),
              address.getZip(),
              address.getRegionId(),
              address.getCountryId(),
              address.getTypeId(),
              address.getMailing(),
              address.isPrimary());
    }

    portletDataContext.importClassedModel(address, importedAddress);
  }
コード例 #2
0
  @Test
  public void testDynamicQueryByPrimaryKeyExisting() throws Exception {
    Address newAddress = addAddress();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(Address.class, _dynamicQueryClassLoader);

    dynamicQuery.add(RestrictionsFactoryUtil.eq("addressId", newAddress.getAddressId()));

    List<Address> result = _persistence.findWithDynamicQuery(dynamicQuery);

    Assert.assertEquals(1, result.size());

    Address existingAddress = result.get(0);

    Assert.assertEquals(existingAddress, newAddress);
  }
コード例 #3
0
  @Test
  public void testDynamicQueryByProjectionExisting() throws Exception {
    Address newAddress = addAddress();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(Address.class, _dynamicQueryClassLoader);

    dynamicQuery.setProjection(ProjectionFactoryUtil.property("addressId"));

    Object newAddressId = newAddress.getAddressId();

    dynamicQuery.add(RestrictionsFactoryUtil.in("addressId", new Object[] {newAddressId}));

    List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);

    Assert.assertEquals(1, result.size());

    Object existingAddressId = result.get(0);

    Assert.assertEquals(existingAddressId, newAddressId);
  }
コード例 #4
0
  @Test
  public void testUpdateExisting() throws Exception {
    long pk = RandomTestUtil.nextLong();

    Address newAddress = _persistence.create(pk);

    newAddress.setMvccVersion(RandomTestUtil.nextLong());

    newAddress.setUuid(RandomTestUtil.randomString());

    newAddress.setCompanyId(RandomTestUtil.nextLong());

    newAddress.setUserId(RandomTestUtil.nextLong());

    newAddress.setUserName(RandomTestUtil.randomString());

    newAddress.setCreateDate(RandomTestUtil.nextDate());

    newAddress.setModifiedDate(RandomTestUtil.nextDate());

    newAddress.setClassNameId(RandomTestUtil.nextLong());

    newAddress.setClassPK(RandomTestUtil.nextLong());

    newAddress.setStreet1(RandomTestUtil.randomString());

    newAddress.setStreet2(RandomTestUtil.randomString());

    newAddress.setStreet3(RandomTestUtil.randomString());

    newAddress.setCity(RandomTestUtil.randomString());

    newAddress.setZip(RandomTestUtil.randomString());

    newAddress.setRegionId(RandomTestUtil.nextLong());

    newAddress.setCountryId(RandomTestUtil.nextLong());

    newAddress.setTypeId(RandomTestUtil.nextLong());

    newAddress.setMailing(RandomTestUtil.randomBoolean());

    newAddress.setPrimary(RandomTestUtil.randomBoolean());

    newAddress.setLastPublishDate(RandomTestUtil.nextDate());

    _addresses.add(_persistence.update(newAddress));

    Address existingAddress = _persistence.findByPrimaryKey(newAddress.getPrimaryKey());

    Assert.assertEquals(existingAddress.getMvccVersion(), newAddress.getMvccVersion());
    Assert.assertEquals(existingAddress.getUuid(), newAddress.getUuid());
    Assert.assertEquals(existingAddress.getAddressId(), newAddress.getAddressId());
    Assert.assertEquals(existingAddress.getCompanyId(), newAddress.getCompanyId());
    Assert.assertEquals(existingAddress.getUserId(), newAddress.getUserId());
    Assert.assertEquals(existingAddress.getUserName(), newAddress.getUserName());
    Assert.assertEquals(
        Time.getShortTimestamp(existingAddress.getCreateDate()),
        Time.getShortTimestamp(newAddress.getCreateDate()));
    Assert.assertEquals(
        Time.getShortTimestamp(existingAddress.getModifiedDate()),
        Time.getShortTimestamp(newAddress.getModifiedDate()));
    Assert.assertEquals(existingAddress.getClassNameId(), newAddress.getClassNameId());
    Assert.assertEquals(existingAddress.getClassPK(), newAddress.getClassPK());
    Assert.assertEquals(existingAddress.getStreet1(), newAddress.getStreet1());
    Assert.assertEquals(existingAddress.getStreet2(), newAddress.getStreet2());
    Assert.assertEquals(existingAddress.getStreet3(), newAddress.getStreet3());
    Assert.assertEquals(existingAddress.getCity(), newAddress.getCity());
    Assert.assertEquals(existingAddress.getZip(), newAddress.getZip());
    Assert.assertEquals(existingAddress.getRegionId(), newAddress.getRegionId());
    Assert.assertEquals(existingAddress.getCountryId(), newAddress.getCountryId());
    Assert.assertEquals(existingAddress.getTypeId(), newAddress.getTypeId());
    Assert.assertEquals(existingAddress.getMailing(), newAddress.getMailing());
    Assert.assertEquals(existingAddress.getPrimary(), newAddress.getPrimary());
    Assert.assertEquals(
        Time.getShortTimestamp(existingAddress.getLastPublishDate()),
        Time.getShortTimestamp(newAddress.getLastPublishDate()));
  }