Last active
December 2, 2015 09:57
-
-
Save panayotkulchev/f431a905eaa8487bd8aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//ping?task=transformUsersAddress | |
if ("transformUsersAddress".equals(task)) { | |
List<String> usersWithAddress = Lists.newArrayList(); | |
List<UserEntity> users = Lists.newArrayList(datastore.get().find().type(UserEntity.class).now()); | |
for (UserEntity each : users) { | |
UserAddressEntity address = each.getAddress(); | |
if (address != null) { | |
boolean hasAddress = !Strings.isNullOrEmpty(address.getApartmentNumber()) || | |
!Strings.isNullOrEmpty(address.getBlockName()) || | |
!Strings.isNullOrEmpty(address.getCity()) || | |
!Strings.isNullOrEmpty(address.getCityType()) || | |
!Strings.isNullOrEmpty(address.getEntrance()) || | |
!Strings.isNullOrEmpty(address.getFloor()) || | |
!Strings.isNullOrEmpty(address.getPostCode()) || | |
!Strings.isNullOrEmpty(address.getResidentialAreaName()) || | |
!Strings.isNullOrEmpty(address.getResidentialAreaType()) || | |
!Strings.isNullOrEmpty(address.getStreet()) || | |
!Strings.isNullOrEmpty(address.getStreetType()) || | |
!Strings.isNullOrEmpty(address.getTelephone()); | |
if (hasAddress) { | |
usersWithAddress.add(each.getId()); | |
} | |
} | |
} | |
writer.println("Transformation count: "+ usersWithAddress.size()); | |
for (String each : usersWithAddress){ | |
final UserEntity user = datastore.get().load().type(UserEntity.class).id(each).now(); | |
final UserAddressEntity address = user.getAddress(); | |
String streetNumber = !Strings.isNullOrEmpty(address.getStreetNumber())?"№"+address.getStreetNumber()+" ":""; | |
String entrance = !Strings.isNullOrEmpty(address.getEntrance())?"вх."+address.getEntrance()+" ":""; | |
String floor = !Strings.isNullOrEmpty(address.getFloor())?"ет."+address.getFloor()+" ":""; | |
String apartmentNo = !Strings.isNullOrEmpty(address.getApartmentNumber())?"ап."+address.getApartmentNumber()+" ":""; | |
String blok = !Strings.isNullOrEmpty(address.getBlockName())?"бл."+address.getBlockName()+" ":""; | |
String telephone = !Strings.isNullOrEmpty(address.getTelephone())?"тел."+address.getTelephone()+" ":""; | |
String postCode = !Strings.isNullOrEmpty(address.getPostCode())? address.getPostCode()+" ":""; | |
String cityType = !Strings.isNullOrEmpty(address.getCityType())? address.getCityType()+".":""; | |
String city = !Strings.isNullOrEmpty(address.getCity())? address.getCity()+" ":""; | |
String residentialAreaType = !Strings.isNullOrEmpty(address.getResidentialAreaType())? address.getResidentialAreaType()+".":""; | |
String residentialArea = !Strings.isNullOrEmpty(address.getResidentialAreaName())? address.getResidentialAreaName()+" ":""; | |
String streeType = !Strings.isNullOrEmpty(address.getStreetType())? address.getStreetType()+".":""; | |
String street = !Strings.isNullOrEmpty(address.getStreet())? address.getStreet()+" ":""; | |
String addressLine = postCode + cityType + city + residentialAreaType + residentialArea + streeType + | |
street + streetNumber + entrance + floor + apartmentNo + blok + telephone; | |
user.setAddressLine(addressLine); | |
datastore.get().store(user); | |
} | |
writer.println("Address transformation finished"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment