Пример #1
0
 public List<Model.Property> listProperties() {
   List<Model.Property> properties = new ArrayList<Model.Property>();
   Set<Field> fields = new LinkedHashSet<Field>();
   Class<?> tclazz = clazz;
   while (!tclazz.equals(Object.class)) {
     Collections.addAll(fields, tclazz.getDeclaredFields());
     tclazz = tclazz.getSuperclass();
   }
   for (Field f : fields) {
     int mod = f.getModifiers();
     if (Modifier.isTransient(mod) || Modifier.isStatic(mod)) {
       continue;
     }
     if (f.isAnnotationPresent(Transient.class)) {
       continue;
     }
     if (f.isAnnotationPresent(NoBinding.class)) {
       NoBinding a = f.getAnnotation(NoBinding.class);
       List<String> values = Arrays.asList(a.value());
       if (values.contains("*")) {
         continue;
       }
     }
     Model.Property mp = buildProperty(f);
     if (mp != null) {
       properties.add(mp);
     }
   }
   return properties;
 }
Пример #2
0
  public static User create(final AuthUser authUser) {
    final User user = new User();
    user.roles =
        Collections.singletonList(SecurityRole.findByRoleName(controllers.Application.USER_ROLE));
    // user.permissions = new ArrayList<UserPermission>();
    // user.permissions.add(UserPermission.findByValue("printers.edit"));
    user.active = true;
    user.lastLogin = new Date();
    user.linkedAccounts = Collections.singletonList(LinkedAccount.create(authUser));

    if (authUser instanceof EmailIdentity) {
      final EmailIdentity identity = (EmailIdentity) authUser;
      // Remember, even when getting them from FB & Co., emails should be
      // verified within the application as a security breach there might
      // break your security as well!
      user.email = identity.getEmail();
      user.emailValidated = false;
    }

    if (authUser instanceof NameIdentity) {
      final NameIdentity identity = (NameIdentity) authUser;
      final String name = identity.getName();
      if (name != null) {
        user.name = name;
      }
    }

    if (authUser instanceof FirstLastNameIdentity) {
      final FirstLastNameIdentity identity = (FirstLastNameIdentity) authUser;
      final String firstName = identity.getFirstName();
      final String lastName = identity.getLastName();
      if (firstName != null) {
        user.firstName = firstName;
      }
      if (lastName != null) {
        user.lastName = lastName;
      }
    }

    user.save();
    // Ebean.saveManyToManyAssociations(user, "roles");
    // Ebean.saveManyToManyAssociations(user, "permissions");
    return user;
  }
 /** @return an unmodifiable list of cells containing dead points (aka dead cells) */
 public List<Cell> getDeadCells() {
   ArrayList<Cell> deadCells = new ArrayList<Cell>();
   int row, col;
   for (DeadPoint dp : deadPoints) {
     row = getCorrespondingRow(dp.getY());
     col = getCorrespondingCol(dp.getX());
     if (valid(row, col)) deadCells.add(cellContainer[row][col]);
   }
   return Collections.unmodifiableList(deadCells);
 }
Пример #4
0
 public static Set<Field> getModelFields(Class<?> clazz) {
   Set<Field> fields = new LinkedHashSet<Field>();
   Class<?> tclazz = clazz;
   while (!tclazz.equals(Object.class)) {
     // Only add fields for mapped types
     if (tclazz.isAnnotationPresent(Entity.class)
         || tclazz.isAnnotationPresent(MappedSuperclass.class))
       Collections.addAll(fields, tclazz.getDeclaredFields());
     tclazz = tclazz.getSuperclass();
   }
   return fields;
 }
Пример #5
0
  /**
   * pull request의 모든 코멘트 정보를 가져오고 시간순으로 정렬 후 반환한다. (코멘트 + 코드코멘트 + 이벤트 )
   *
   * @return
   */
  @Transient
  public List<TimelineItem> getTimelineComments() {
    List<CommitComment> commitComment = computeCommitCommentReplies(getCommitComments());

    List<TimelineItem> timelineComments = new ArrayList<>();
    timelineComments.addAll(comments);
    timelineComments.addAll(commitComment);
    timelineComments.addAll(pullRequestEvents);

    Collections.sort(timelineComments, TimelineItem.ASC);

    return timelineComments;
  }
Пример #6
0
 @Override
 @JsonIgnore
 public Collection<? extends GrantedAuthority> getAuthorities() {
   Set<Role> roles = this.getRoles();
   if (roles == null) {
     return Collections.emptyList();
   }
   Set<GrantedAuthority> authorities = new HashSet<GrantedAuthority>();
   for (Role role : roles) {
     authorities.add(new SimpleGrantedAuthority(role.name()));
   }
   return authorities;
 }
Пример #7
0
 private void saveAndCascade(boolean willBeSaved) {
   this.willBeSaved = willBeSaved;
   if (avoidCascadeSaveLoops.get().contains(this)) {
     return;
   } else {
     avoidCascadeSaveLoops.get().add(this);
     if (willBeSaved) {
       PlayPlugin.postEvent("JPASupport.objectUpdated", this);
     }
   }
   // Cascade save
   try {
     Set<Field> fields = new HashSet<Field>();
     Class clazz = this.getClass();
     while (!clazz.equals(JPABase.class)) {
       Collections.addAll(fields, clazz.getDeclaredFields());
       clazz = clazz.getSuperclass();
     }
     for (Field field : fields) {
       field.setAccessible(true);
       if (Modifier.isTransient(field.getModifiers())) {
         continue;
       }
       boolean doCascade = false;
       if (field.isAnnotationPresent(OneToOne.class)) {
         doCascade = cascadeAll(field.getAnnotation(OneToOne.class).cascade());
       }
       if (field.isAnnotationPresent(OneToMany.class)) {
         doCascade = cascadeAll(field.getAnnotation(OneToMany.class).cascade());
       }
       if (field.isAnnotationPresent(ManyToOne.class)) {
         doCascade = cascadeAll(field.getAnnotation(ManyToOne.class).cascade());
       }
       if (field.isAnnotationPresent(ManyToMany.class)) {
         doCascade = cascadeAll(field.getAnnotation(ManyToMany.class).cascade());
       }
       if (doCascade) {
         Object value = field.get(this);
         if (value == null) {
           continue;
         }
         if (value instanceof PersistentMap) {
           if (((PersistentMap) value).wasInitialized()) {
             for (Object o : ((Map) value).values()) {
               if (o instanceof JPABase) {
                 ((JPABase) o).saveAndCascade(willBeSaved);
               }
             }
           }
           continue;
         }
         if (value instanceof PersistentCollection) {
           if (((PersistentCollection) value).wasInitialized()) {
             for (Object o : (Collection) value) {
               if (o instanceof JPABase) {
                 ((JPABase) o).saveAndCascade(willBeSaved);
               }
             }
           }
           continue;
         }
         if (value instanceof HibernateProxy && value instanceof JPABase) {
           if (!((HibernateProxy) value).getHibernateLazyInitializer().isUninitialized()) {
             ((JPABase) ((HibernateProxy) value).getHibernateLazyInitializer().getImplementation())
                 .saveAndCascade(willBeSaved);
           }
           continue;
         }
         if (value instanceof JPABase) {
           ((JPABase) value).saveAndCascade(willBeSaved);
           continue;
         }
       }
     }
   } catch (Exception e) {
     throw new UnexpectedException("During cascading save()", e);
   }
 }
Пример #8
0
 @XmlElement
 public List<Specialty> getSpecialties() {
   List<Specialty> sortedSpecs = new ArrayList<Specialty>(getSpecialtiesInternal());
   PropertyComparator.sort(sortedSpecs, new MutableSortDefinition("name", true, true));
   return Collections.unmodifiableList(sortedSpecs);
 }
 public List<Pet> getPets() {
   List<Pet> sortedPets = new ArrayList<Pet>(getPetsInternal());
   return Collections.unmodifiableList(sortedPets);
 }
Пример #10
0
 public List<Visit> getVisits() {
   List<Visit> sortedVisits = new ArrayList<Visit>(getVisitsInternal());
   PropertyComparator.sort(sortedVisits, new MutableSortDefinition("date", false, false));
   return Collections.unmodifiableList(sortedVisits);
 }
Пример #11
0
 /**
  * @return
  * @see models.AbstractPosting#getComments()
  */
 @Transient
 public List<? extends Comment> getComments() {
   Collections.sort(comments, Comment.comparator());
   return comments;
 }