@Transient @JsonIgnore public List<String> getAccessableBranch() throws Exception { if (NullEmptyChecker.isNullOrEmpty(accessableBranch)) { if (getDataAccessRestriction().equals(DataAccessRestriction.AllBranch.getVal())) { return null; } else if (getDataAccessRestriction().equals(DataAccessRestriction.Subordinate.getVal())) { Branch branch = branchRepo.find(getFidBranch()); System.out.println("branch = " + branch); accessableBranch.addAll(branch.getAllSubordinateId()); accessableBranch.add(getFidBranch()); } else if (getDataAccessRestriction().equals(DataAccessRestriction.SelfBranch.getVal())) { accessableBranch = Arrays.asList(getFidBranch()); } else { String[] accessItem = this.getAccessBranch().split(";"); for (int x = 0; x < accessItem.length; x++) { accessableBranch.add(accessItem[x]); } } } return accessableBranch; }
private Collection<GroupData> fetchGroupDataForUser( final User user, final boolean restrictToSuscribed) { final String ifConnectedColumns = "max(ifnull(USER_ID=:userId, false))>0, sum(ifnull(USER_ID=:userId AND LAST_VISIT<PUBLIC_MESSAGES.`DATE`, false))"; final Query query = entityManager.createNativeQuery( "select GROUPS.ID, name, count(DISTINCT GROUP_USER.USER_ID), " + (user != null ? ifConnectedColumns : " 0,0") + " from GROUPS left join GROUP_USER on GROUP_ID=ID " + " left join PUBLIC_MESSAGES on PUBLIC_MESSAGES.GROUP_ID=GROUP_USER.GROUP_ID " + (restrictToSuscribed ? " where GROUP_USER.USER_ID=:userId" : "") + " group by GROUPS.ID order by CREATION_DATE"); if (user != null) query.setParameter("userId", user.getId()); final List<Object[]> list = query.getResultList(); final Collection<GroupData> result = new ArrayList<GroupData>(list.size()); for (final Object[] o : list) result.add( new GroupData( ((Number) o[0]).longValue(), UserStringImpl.valueOf(String.valueOf(o[1])), ((Number) o[2]).longValue(), ((Number) o[3]).intValue() != 0, ((Number) o[4]).intValue())); return result; }
public static List<String> typesList() { List<String> theList = new ArrayList<String>(); for (IdentityDocType type : all()) { theList.add(type.identityDocTypeName); } return theList; }
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; }
/** * Generate license plates from a file. * * @param filename */ private void generateLicensePlates(String filename) { File licenseplatefile = getResourceFile(filename); BufferedReader in = null; try { in = new BufferedReader(new InputStreamReader(new FileInputStream(licenseplatefile))); } catch (FileNotFoundException ex) { Logger.getLogger(MovementsDAOImpl.class.getName()).log(Level.SEVERE, null, ex); } List<String> licensePlates = new ArrayList(); String line; try { while ((line = in.readLine()) != null) { licensePlates.add(line); } } catch (IOException ex) { Logger.getLogger(MovementsDAOImpl.class.getName()).log(Level.SEVERE, null, ex); } finally { try { in.close(); } catch (IOException ex) { Logger.getLogger(MovementsDAOImpl.class.getName()).log(Level.SEVERE, null, ex); } } itLicensePlates = licensePlates.iterator(); }
Field[] keyFields() { Class c = clazz; try { List<Field> fields = new ArrayList<Field>(); while (!c.equals(Object.class)) { for (Field field : c.getDeclaredFields()) { // TODO: add cashe field->isAnnotationPresent if (InternalCache.isEnableAnnotationPresent()) { if (InternalCache.isAnnotationPresent(Id.class, field) || InternalCache.isAnnotationPresent(EmbeddedId.class, field)) { field.setAccessible(true); fields.add(field); } } else { if (field.isAnnotationPresent(Id.class) || field.isAnnotationPresent(EmbeddedId.class)) { field.setAccessible(true); fields.add(field); } } } c = c.getSuperclass(); } final Field[] f = fields.toArray(new Field[fields.size()]); if (f.length == 0) { throw new UnexpectedException("Cannot get the object @Id for an object of type " + clazz); } return f; } catch (Exception e) { throw new UnexpectedException( "Error while determining the object @Id for an object of type " + clazz); } }
public String getFirstLatLng() { if (mapLocationList.size() == 0) { return "0,0"; } else { return mapLocationList.get(0).getLatitude() + ", " + mapLocationList.get(0).getLatitude(); } }
public static List<String> fioList() { List<String> theList = new ArrayList<String>(); for (Doctor doctor : allDoctors()) { theList.add(doctor.getFullName()); } return theList; }
public void addComment(Comment comment) { if (!comment.isCommentSet()) { List<Comment> commentList = getComments(); commentList.add(comment); comment.commentSet = true; } }
/** * Will return SiteResearchStaff having at least one active role provided in roleCodes parameter. * * @param roleCodes - roles to check * @return A list of SiteResearchStaff */ public List<SiteResearchStaff> findSiteResearchStaffByRoles(final String... roleCodes) { List<SiteResearchStaff> srsList = new ArrayList<SiteResearchStaff>(); for (SiteResearchStaff srs : getSiteResearchStaffs()) { if (srs.hasActiveRolesOfType(roleCodes)) srsList.add(srs); } return srsList; }
/** * Will return all the SiteResearchStaff which are currently active. * * @return the in active site research staff */ @Transient public List<SiteResearchStaff> getInActiveSiteResearchStaff() { List<SiteResearchStaff> srsList = new ArrayList<SiteResearchStaff>(); for (SiteResearchStaff srs : getSiteResearchStaffs()) { if (!srs.isActive()) srsList.add(srs); } return srsList; }
@Override public List<ICompetition> getCompetitions() { List<ICompetition> cl = new LinkedList<>(); for (Competition c : competitions) { cl.add(c); } return cl; }
public List<ServiceEntity> getServices() { if (services == null) { services = new HashSet<>(); } List<ServiceEntity> rtrn = new ArrayList<>(); rtrn.addAll(services); return rtrn; }
@Transient private List<ArticlePageEntityDTO> getPagesAsDTOs() { List<ArticlePageEntityDTO> pageDTOs = new ArrayList<>(); for (ArticlePage page : pages) { pageDTOs.add(page.toDTO()); } return pageDTOs; }
public List<Message> getRelatedMessage() { if (relatedMessage == null) { relatedMessage = new HashSet<>(); } List<Message> rtrn = new ArrayList<>(); rtrn.addAll(relatedMessage); return rtrn; }
/** * Persists a Audit * * @param object * @param persisted * @param auditingType */ public void audit(Object object, Object persisted, AuditingType auditingType) { try { if (isEntity(object)) { Field[] fields = object.getClass().getDeclaredFields(); Method[] methods = object.getClass().getDeclaredMethods(); Method.setAccessible(methods, true); Field.setAccessible(fields, true); AbstractAuditing auditing = Configuration.getAbstractAuditing(); auditing.setIdentifier(Long.valueOf(getId(object).toString())); auditing.setEntity(getEntityName(object.getClass())); auditing.setAuditingType(auditingType); auditing.setEventDate(new Date()); if (FacesContext.getCurrentInstance() != null) { auditing.setIp(FacesUtils.getIP()); } auditing.setAuditClass(object.getClass()); AbstractAuditingListener listener = Configuration.getAuditingListener(); if (listener != null) { listener.onSave(auditing); } List<AbstractMetadata> metadatas = null; boolean auditPersited = false; if (auditingType.equals(AuditingType.INSERT) || auditingType.equals(AuditingType.DELETE)) { entityManager.persist(auditing); metadatas = getMetadata(object, null, auditing); auditPersited = true; } else if (auditingType.equals(AuditingType.UPDATE)) { metadatas = getMetadata(object, persisted, auditing); if (metadatas != null && !metadatas.isEmpty()) { entityManager.persist(auditing); auditPersited = true; } } auditing.setMetadatas(metadatas); // add to context if (auditPersited == true) { AuditContext context = AuditContext.getCurrentInstance(); if (context != null) { context.setAuditing(object, auditing); } } if (metadatas != null && !metadatas.isEmpty()) { for (AbstractMetadata metadata : metadatas) { entityManager.persist(metadata); } } } } catch (Throwable t) { logger.log(Level.SEVERE, t.getMessage(), t); } }
/** * Get a vehicle by cartracker id from the cached list, if the vehicle does not exist it will be * created. * * @param cartrackerID * @return The found or newly created vehicle. */ @Override public Vehicle getOrCreateVehicleById(String cartrackerID) { Vehicle returnVehicle = null; Iterator<Vehicle> it = vehicles.iterator(); while (it.hasNext()) { Vehicle vehicle = it.next(); if (cartrackerID.equals(vehicle.getCarTrackerID())) { returnVehicle = vehicle; break; } } /* Vehicle does not exist, lets create a new one */ if (returnVehicle == null) { try { /* Also create a vehicle ownership */ GregorianCalendar registerdate = new GregorianCalendar(); registerdate.add(Calendar.YEAR, -3); VehicleOwnership vehicleOwnership = new VehicleOwnership(); vehicleOwnership.setContributeGPSData(true); vehicleOwnership.setRegistrationdate((GregorianCalendar) registerdate.clone()); vehicleOwnership.setRegistrationExperationDate(null); try { // create new user with incrementing name userDAO = new UserDAOImpl(emf); loginDAO = new LoginDAOImpl(em); UserDto user = userDAO.register( "user" + USER_ID++ + "name", "aidas123", "*****@*****.**"); MovementUser mUser = loginDAO.register(user.getUsername(), user.getEmail()); vehicleOwnership.setUser(mUser); } catch (UserSystemException ex) { Logger.getLogger(MovementsDAOImpl.class.getName()).log(Level.SEVERE, null, ex); } // create car returnVehicle = new Vehicle(cartrackerID); returnVehicle.setLicensePlate(itLicensePlates.next()); List<VehicleOwnership> owners = new ArrayList(); owners.add(vehicleOwnership); returnVehicle.setVehicleOwners(owners); em.persist(returnVehicle); vehicleOwnership.setVehicle(returnVehicle); em.persist(vehicleOwnership); Logger.getLogger(MovementsDAOImpl.class.getName()) .log(Level.WARNING, "Created new vehicle with ID" + cartrackerID); this.vehicles.add(returnVehicle); } catch (Exception ex) { Logger.getLogger(MovementsDAOImpl.class.getName()).log(Level.SEVERE, null, ex); } } return returnVehicle; }
public static List<MetaModule> createAll() { List<MetaModule> result = new ArrayList<MetaModule>(); for (Object oapp : MetaApplications.getMetaApplications()) { MetaApplication app = (MetaApplication) oapp; createDefaultMetaModules(app); createAdditionalMetaModules(app); result.addAll(app.getMetaModules()); } return result; }
@Override public void setCompetitions(List<ICompetition> competitions) { List<Competition> result = new LinkedList<>(); for (ICompetition d : competitions) { result.add((Competition) d); } this.competitions = result; }
/** * groupKey를 통해 같은 코멘트그룹을 반환한다. * * @param groupKey * @param codeComments * @return */ private List<CommitComment> commitCommentsGroupByKey( String groupKey, List<CommitComment> codeComments) { List<CommitComment> commitCommentGroups = new ArrayList<>(); for (CommitComment commitComment : codeComments) { if (commitComment.groupKey().equals(groupKey)) { commitCommentGroups.add(commitComment); } } return commitCommentGroups; }
@Override public void setTeamList(List<ITeam> teamList) { List<Team> result = new LinkedList<>(); for (ITeam d : teamList) { result.add((Team) d); } this.teamList = result; }
@XmlTransient @Override public List<ITeam> getTeamList() { List<ITeam> result = new LinkedList<>(); for (Team d : teamList) { result.add(d); } return result; }
public DataModel<Event> getMyEvents() { DataModel<Event> events = null; // Set<Event> myEvents = getSubscribedEvents(); // EventRegistry eventRegistry = EventRegistry.getCurrentInstance(); List<Event> myEventList = new ArrayList<Event>(); myEventList.addAll(myEvents); events = new ListDataModel<Event>(myEventList); return events; }
public static List<Room> findJoinedRoomsByUser(User user) { // ユーザが所属するルーム一覧の取得. // FIXME JOINとか使わないとどう考えてもだめだよー。HQLとJPAがわからないので一旦放置. List<Room> rooms = findAll(); List<Room> ret = new ArrayList<Room>(); for (Room room : rooms) { if (room.members.contains(user)) { ret.add(room); } } return ret; }
/** * 답글목록을 부모글의 필드로 재할당한다. * * <p>commentGroup은 등록일순으로 오름차순 정렬되어 있는 상태이며 목록의 첫번째 코멘트를 부모글로 판단한다. * * @param commentGroup * @return */ private List<CommitComment> reAssignReplyComments(Map<String, List<CommitComment>> commentGroup) { List<CommitComment> parentCommitComments = new ArrayList<>(); for (List<CommitComment> commitComments : commentGroup.values()) { CommitComment parentComment = commitComments.get(0); if (hasReply(commitComments)) { parentComment.replies = replies(commitComments); } parentCommitComments.add(parentComment); } return parentCommitComments; }
public Stock getStockByItem(int itemid) { // 用 商品編號 查出 該商品所在的某一貨架 Query query = XPersistence.getManager() .createQuery( "FROM Stock o WHERE o.item.oid = :itemid order by o.volume desc"); // JPQL query query.setParameter("itemid", itemid); List<Stock> beans = query.getResultList(); logger.debug("OrderPlaceDDAO.getStockByItem beans: " + beans); return beans.get(0); }
public void forgotPassword(final String email) throws UserNotFoundException, MailException { final Query query = entityManager.createQuery("select u from UserImpl u where u.email=:cryptedMail"); query.setParameter("cryptedMail", CipherHelper.cipher(email)); final List<UserImpl> list = query.getResultList(); if (list.isEmpty()) throw new UserNotFoundException(); for (final UserImpl user : list) { final String password = Helper.randomstring(); user.setPassword(password); MailSender.forgotPasswordMail(user.getName(), password, email); entityManager.merge(user); } }
public List<Group> getGroups() { List<Group> allGroups = Group.findAll(); List<Group> answer = new ArrayList<Group>(); for (Group g : allGroups) { for (User u : g.members) { if (u.equals(this)) { answer.add(g); break; } } } return answer; }
public Boulder untick(String name) { int i = 0; while (i < haveSent.size()) { if (haveSent.get(i).username.equals(name)) { haveSent.remove(i); this.update(); return this; } else { ++i; } } return null; }
/** * 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; }