Advertisement
Guest User

Untitled

a guest
Jan 15th, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.40 KB | None | 0 0
  1. package javier.loyaltynetwork.model;
  2. import com.datastax.driver.mapping.annotations.Column;
  3. import com.datastax.driver.mapping.annotations.Frozen;
  4. import com.datastax.driver.mapping.annotations.FrozenValue;
  5. import com.datastax.driver.mapping.annotations.PartitionKey;
  6. import com.datastax.driver.mapping.annotations.Table;
  7. import com.google.common.base.Objects;
  8. import javier.loyaltynetwork.databaseApi.cassandra.model.*;
  9. import java.util.HashSet;
  10. import java.util.UUID;
  11. /**
  12.  * Created by JXT0589 on 12/31/2015.
  13.  */
  14. @Table(keyspace = "loyalty_network", name = "users")
  15. public class User
  16. {
  17.     @PartitionKey private UUID id;
  18.     private String name;
  19.     @Column(name = "hashed_password")
  20.     private String hashedPassword;
  21.     private String mission;
  22.     @FrozenValue
  23.     private HashSet<EntityRef> affiliations;
  24.     @Frozen
  25.     private EntityRef reference;
  26.     public User()
  27.     {
  28.     }
  29.     public User(UUID newId, String newName, String newHashedPassword, String newMission, HashSet<EntityRef> newAffiliations)
  30.     {
  31.         id = newId;
  32.         name = newName;
  33.         hashedPassword = newHashedPassword;
  34.         mission = newMission;
  35.         affiliations = newAffiliations;
  36.         reference = new EntityRef(id, name, "user");
  37.     }
  38.     //Getters
  39.     public UUID getId()
  40.     {
  41.         return id;
  42.     }
  43.     public String getName()
  44.     {
  45.         return name;
  46.     }
  47.     public String getHashedPassword()
  48.     {
  49.         return hashedPassword;
  50.     }
  51.     public HashSet<EntityRef> getAffiliations()
  52.     {
  53.         return affiliations;
  54.     }
  55.     public String getMission()
  56.     {
  57.         return mission;
  58.     }
  59.     public EntityRef getReference()
  60.     {
  61.         return reference;
  62.     }
  63.     //Setters
  64.     public void setName(String newName)
  65.     {
  66.         name = newName;
  67.         reference = new EntityRef(id, name, "user");
  68.     }
  69.     public void setMission(String newMission)
  70.     {
  71.         mission = newMission;
  72.     }
  73.     public void setHashedPassword(String newPassword)
  74.     {
  75.         hashedPassword = newPassword;
  76.     }
  77.         public void setId(UUID newId)
  78.     {
  79.         id = newId;
  80.         }
  81.         public void setAffiliations(HashSet<EntityRef> newAffiliations)
  82.         {
  83.                 affiliations = newAffiliations;
  84.         }
  85.         public void setReference(EntityRef newRef)
  86.         {
  87.                 reference = newRef;
  88.         }
  89.         public void generateEntityRef()
  90.         {
  91.                 reference = new EntityRef(id, name, "user");
  92.         }
  93.     //Affiliations modifications
  94.     public void addAffilitation(EntityRef newReference)
  95.     {
  96.         if(affiliations == null)
  97.         {
  98.             affiliations = new HashSet<EntityRef>();
  99.         }
  100.         affiliations.add(newReference);
  101.     }
  102.     public void removeAffiliation(EntityRef reference)
  103.     {
  104.         if(affiliations != null)
  105.         {
  106.             affiliations.remove(reference);
  107.         }
  108.     }
  109.     @Override
  110.     public boolean equals(Object object)
  111.     {
  112.         if( object instanceof User)
  113.         {
  114.             User otherUser = (User) object;
  115.             return Objects.equal(id, otherUser.getId());
  116.         }
  117.         else return false;
  118.     }
  119.     @Override
  120.     public int hashCode()
  121.     {
  122.         return Objects.hashCode(id);
  123.     }
  124.     public UserByNameAndHashedPassword toUserByNameAndHashedPassword()
  125.     {
  126.         return new UserByNameAndHashedPassword(id, name, hashedPassword, mission, affiliations);
  127.     }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement