@Override
  public void deleteStagedModel(String uuid, long groupId, String className, String extraData)
      throws PortalException {

    Group group = GroupLocalServiceUtil.getGroup(groupId);

    Address address =
        AddressLocalServiceUtil.fetchAddressByUuidAndCompanyId(uuid, group.getCompanyId());

    if (address != null) {
      AddressLocalServiceUtil.deleteAddress(address);
    }
  }
  @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);
  }
  public static Address addAddress(Organization organization) throws Exception {

    return AddressLocalServiceUtil.addAddress(
        organization.getUserId(),
        organization.getModelClassName(),
        organization.getOrganizationId(),
        RandomTestUtil.randomString(),
        RandomTestUtil.randomString(),
        RandomTestUtil.randomString(),
        RandomTestUtil.randomString(),
        RandomTestUtil.randomString(),
        RandomTestUtil.nextLong(),
        RandomTestUtil.randomLong(),
        _getListTypeId(ListTypeConstants.ORGANIZATION_ADDRESS),
        false,
        false,
        new ServiceContext());
  }
  @Test
  public void testActionableDynamicQuery() throws Exception {
    final IntegerWrapper count = new IntegerWrapper();

    ActionableDynamicQuery actionableDynamicQuery =
        AddressLocalServiceUtil.getActionableDynamicQuery();

    actionableDynamicQuery.setPerformActionMethod(
        new ActionableDynamicQuery.PerformActionMethod() {
          @Override
          public void performAction(Object object) {
            Address address = (Address) object;

            Assert.assertNotNull(address);

            count.increment();
          }
        });

    actionableDynamicQuery.performActions();

    Assert.assertEquals(count.getValue(), _persistence.countAll());
  }
 public List<Address> getAddresses() throws SystemException {
   return AddressLocalServiceUtil.getAddresses(
       getCompanyId(), Contact.class.getName(), getContactId());
 }