@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()); }