public static void viewAd(String id) { Ad ad = Ad.findById(Long.parseLong(id)); List<Category> cats = Category.find("categorytype_id=?1 order by id", "1").fetch(); EntityManager entityManager = play.db.jpa.JPA.em(); List<BigInteger> bCounts = entityManager .createNativeQuery( "select count(*) as maxCount from Ad as a group by category_id order by maxCount") .getResultList(); int min = bCounts.get(0).intValue(); int max = bCounts.get(bCounts.size() - 1).intValue(); bCounts = entityManager .createNativeQuery( "select count(*) as maxCount from Ad as a group by category_id order by category_id ") .getResultList(); List<String> fonts = new ArrayList<String>(); for (int i = 0; i < bCounts.size(); i++) { BigInteger count = bCounts.get(i); int x = Ads.getFontSize(count.intValue(), min, max); fonts.add(String.valueOf(x)); } render(ad, fonts, min, max, cats); }
private static Comment makeNewComment(Resource target, User sender, String body) throws IssueNotFound, PostingNotFound { Comment comment; Long id = Long.valueOf(target.getId()); switch (target.getType()) { case ISSUE_POST: Issue issue = Issue.finder.byId(id); if (issue == null) { throw new IssueNotFound(id); } comment = new IssueComment(issue, sender, body); break; case BOARD_POST: Posting posting = Posting.finder.byId(id); if (posting == null) { throw new PostingNotFound(id); } comment = new PostingComment(posting, sender, body); break; default: throw new IllegalArgumentException("Unsupported resource type: " + target.getType()); } return comment; }
@Test public void label() { // Given Map<String, String> data = new HashMap<>(); data.put("category", "OS"); data.put("name", "linux"); User admin = User.findByLoginId("admin"); String user = "******"; String projectName = "projectYobi"; // When Result result = callAction( controllers.routes.ref.ProjectApp.attachLabel(user, projectName), fakeRequest(POST, routes.ProjectApp.attachLabel(user, projectName).url()) .withFormUrlEncodedBody(data) .withHeader("Accept", "application/json") .withSession(UserApp.SESSION_USERID, admin.id.toString())); // Then assertThat(status(result)).isEqualTo(CREATED); Iterator<Map.Entry<String, JsonNode>> fields = Json.parse(contentAsString(result)).getFields(); Map.Entry<String, JsonNode> field = fields.next(); Label expected = new Label(field.getValue().get("category").asText(), field.getValue().get("name").asText()); expected.id = Long.valueOf(field.getKey()); assertThat(expected.category).isEqualTo("OS"); assertThat(expected.name).isEqualTo("linux"); assertThat(Project.findByOwnerAndProjectName("yobi", "projectYobi").labels.contains(expected)) .isTrue(); }
public static void toubiao() { String username = session.get("username"); if (username != null) { User user = User.getByUserName(username); Profile profile = Profile.find("user.id=?", user.id).first(); String payStyle = params.get("payStyle"); String invoice = params.get("invoice"); String comments = params.get("comments"); String requestS = params.get("request"); Request request = Request.findById(Long.valueOf(requestS)); Toubiao toubiao = null; toubiao = Toubiao.find("request.id=? and profile.id=?", request.id, profile.id).first(); if (toubiao == null) { toubiao = new Toubiao(); } toubiao.profile = profile; toubiao.user = user; toubiao.request = request; toubiao.payStyle = payStyle; toubiao.invoice = invoice; toubiao.comments = comments; toubiao.again = false; toubiao.save(); String price = "0"; String price2 = "0"; String price3 = "0"; Baojia baojia = null; for (Specification spec : request.specifications) { price = params.get("price" + spec.id); price2 = params.get("price" + spec.id + "-2"); price3 = params.get("price" + spec.id + "-3"); baojia = Baojia.find("toubiao.id=? and specification.id=?", toubiao.id, spec.id).first(); if (baojia == null) { baojia = new Baojia(); baojia.toubiao = toubiao; baojia.specification = spec; } if (price != null && !"".equals(price) && !"0".equals(price)) baojia.price = Double.valueOf(price); if (price2 != null && !"".equals(price2) && !"0".equals(price2)) baojia.secondPrice = Double.valueOf(price2); if (price3 != null && !"".equals(price3) && !"0".equals(price3)) baojia.thirdPrice = Double.valueOf(price3); baojia.save(); if (!toubiao.baojias.contains(baojia)) { toubiao.baojias.add(baojia); toubiao.save(); } } } redirect("/"); }
public static void projects() { Long id = Long.parseLong(Session.current().get("user_id")); User u = User.findById(id); List<Project> projects = Project.find("owner = ?", u).fetch(); render(projects); }
public static void remove() { Long id = Long.valueOf(params.get("id")); Files files = Files.findById(id); if (files.image.getFile().exists()) { files.image.getFile().delete(); } files.delete(); renderText(""); }
@Transactional protected static ReviewComment saveReviewComment( Resource target, User sender, Content content, String messageID, Address[] allRecipients) throws MessagingException, IOException, NoSuchAlgorithmException { ReviewComment comment; CommentThread thread = CommentThread.find.byId(Long.valueOf(target.getId())); if (thread == null) { throw new IllegalArgumentException(); } comment = new ReviewComment(); comment.setContents(content.body); comment.author = new UserIdent(sender); comment.thread = thread; comment.save(); Map<String, Attachment> relatedAttachments = saveAttachments(content.attachments, comment.asResource()); if (new ContentType(content.type).match(MimeType.HTML)) { // replace cid with attachments comment.setContents(replaceCidWithAttachments(comment.getContents(), relatedAttachments)); comment.update(); } new OriginalEmail(messageID, comment.asResource()).save(); // Add the event if (thread.isOnPullRequest()) { addEvent( NotificationEvent.forNewComment(sender, thread.pullRequest, comment), allRecipients, sender); } else { try { String commitId; if (thread instanceof CodeCommentThread) { commitId = ((CodeCommentThread) thread).commitId; } else if (thread instanceof NonRangedCodeCommentThread) { commitId = ((NonRangedCodeCommentThread) thread).commitId; } else { throw new IllegalArgumentException(); } addEvent( NotificationEvent.forNewCommitComment(target.getProject(), comment, commitId, sender), allRecipients, sender); } catch (Exception e) { Logger.warn("Failed to send a notification", e); } } return comment; }
public static void removeProperty() { String id = params.get("id"); Prop p = Prop.findById(Long.valueOf(id)); List<Specification> specifications = Specification.em() .createQuery( "select r from Specification r join fetch r.properties s where s.id=" + Long.valueOf(id), Specification.class) .getResultList(); for (Specification spec : specifications) { spec.properties.remove(p); spec.save(); } if (p != null) p.delete(); renderText(id); }
public static void removeSpec() { String id = params.get("id"); Specification spec = Specification.findById(Long.valueOf(id)); List<Request> requests = Request.em() .createQuery( "select r from Request r join fetch r.specifications s where s.id=" + Long.valueOf(id), Request.class) .getResultList(); for (Request req : requests) { req.specifications.remove(spec); req.save(); } if (spec != null) spec.delete(); renderText(id); }
public static Result nutritionSchedule() { TDEERule tdeeRule = new TDEERule(); CalEatingRule calEatingRule = new CalEatingRule(); NutritionRule nuRule = new NutritionRule(); MeatRule meatRule = new MeatRule(); VegetableRule vegetableRule = new VegetableRule(); DrinkRule drinkRule = new DrinkRule(); User thisUser = User.findById(Long.parseLong(session("userId"))); double weight = thisUser.getWeight(); boolean isGain = thisUser.isGain(); double height = thisUser.getHeight(); if (weight == 0 || height == 0) { flash("error", "Please fill your information."); return redirect(routes.Profile.index()); } nuRule.setInput(weight, isGain); RulesEngine rulesEngine = aNewRulesEngine().withSilentMode(true).build(); rulesEngine.registerRule(nuRule); meatRule.setInput(true); vegetableRule.setInput(true); drinkRule.setInput(true); rulesEngine.registerRule(meatRule); rulesEngine.registerRule(vegetableRule); rulesEngine.registerRule(drinkRule); rulesEngine.fireRules(); List<Nutrition> nuList = nuRule.getResult(); List<RawMaterial> meatList = meatRule.getResult().getAll(); List<RawMaterial> vetList = vegetableRule.getResult().getAll(); List<RawMaterial> drinkList = drinkRule.getResult().getAll(); List<RawMaterial> rawMaterialList = new ArrayList<RawMaterial>(meatList); rawMaterialList.addAll(vetList); rawMaterialList.addAll(drinkList); List<String> tdees = new ArrayList<String>(); List<String> eatingCals = new ArrayList<String>(); RulesEngine rulesEngine_tdee = aNewRulesEngine().withSilentMode(true).build(); RulesEngine rulesEngine_cal = aNewRulesEngine().withSilentMode(true).build(); rulesEngine_tdee.registerRule(tdeeRule); rulesEngine_cal.registerRule(calEatingRule); for (int i = 0; i < 5; i++) { tdeeRule.setInput(weight, height, thisUser.getGender(), thisUser.getAge(), 1.2 + (i * 0.2)); rulesEngine_tdee.fireRules(); tdees.add(tdeeRule.getResult()); calEatingRule.setInput(Double.parseDouble(tdees.get(i)), isGain); rulesEngine_cal.fireRules(); eatingCals.add(calEatingRule.getResult()); } return ok(nutrition_schedule.render(nuList, rawMaterialList, tdees, eatingCals)); }
/** * Obtains the currently uploaded file from the session variable. * * @return uploaded file * @throws FileNotFoundException */ private static File getCurrentUpload() throws FileNotFoundException { String uploadFileId = session().get("uploadFileId"); UserUpload uploadFile = UserUpload.find.byId(Long.parseLong(uploadFileId)); File file = new File(uploadFile.absolutePath); if (!file.exists()) { throw new FileNotFoundException("Could not load input from file."); } return file; }
/** * 세션에 저장된 정보를 이용해서 사용자 객체를 생성한다 세션에 저장된 정보가 없다면 anonymous 객체가 리턴된다 * * @return 세션 정보 기준 조회된 사용자 객체 */ public static User currentUser() { String userId = session().get(SESSION_USERID); if (StringUtils.isEmpty(userId) || !StringUtils.isNumeric(userId)) { return User.anonymous; } User foundUser = User.find.byId(Long.valueOf(userId)); if (foundUser == null) { processLogout(); return User.anonymous; } return foundUser; }
public static void project(Long id) { Project project = Project.findById(id); Long UID = Long.parseLong(Session.current().get("user_id")); User u = User.findById(UID); if (project.canBeSeenBy(u)) { render(project); } else { projects(); } }
public static void zbAgain() { String id = params.get("toubiaoid"); String againComments = params.get("againComments"); Toubiao toubiao = Toubiao.findById(Long.valueOf(id)); toubiao.again = true; toubiao.againComments = againComments; toubiao.save(); Request req = toubiao.request; req.status = 2; req.save(); redirect("/vender/tblist?id=" + id); }
public static void createproject(String projectname, String projectdescription) { if (projectname != null && projectdescription != null) { Long id = Long.parseLong(Session.current().get("user_id")); User u = User.findById(id); Project p = new Project(projectname, projectdescription, u); p.save(); projects(); } else { render(); } }
/** * 세션 정보를 이용해서 사용자 객체를 가져온다. 세션 정보가 없거나 잘못된 정보라면 anonymous 객체를 반환한다. 잘못된 정보의 경우 세션 정보를 삭제한다. * * @return */ private static User getUserFromSession() { String userId = session().get(SESSION_USERID); if (userId == null) { return User.anonymous; } if (!StringUtils.isNumeric(userId)) { return invalidSession(); } User user = User.find.byId(Long.valueOf(userId)); if (user == null) { return invalidSession(); } return user; }
public static Admin getCurrentAdmin() { /** * get currently logged in admin for Candidate (CandidateController.java) + Office * (OfficeController.java) constructors via new logged_in_adminid written to session on admin * login */ String adminId = session.get("logged_in_adminid"); if (adminId == null) { return null; } Admin logged_in_admin = Admin.findById(Long.parseLong(adminId)); Logger.info("In Admin controller: Logged in admin is " + logged_in_admin.username); return logged_in_admin; }
/** * 사용자 정보 수정 * * @return */ @With(AnonymousCheckAction.class) @Transactional public static Result editUserInfo() { Form<User> userForm = new Form<>(User.class).bindFromRequest("name", "email"); String newEmail = userForm.data().get("email"); String newName = userForm.data().get("name"); User user = UserApp.currentUser(); if (StringUtils.isEmpty(newEmail)) { userForm.reject("email", "user.wrongEmail.alert"); } else { if (!StringUtils.equals(user.email, newEmail) && User.isEmailExist(newEmail)) { userForm.reject("email", "user.email.duplicate"); } } if (userForm.error("email") != null) { flash(Constants.WARNING, userForm.error("email").message()); return badRequest(edit.render(userForm, user)); } user.email = newEmail; user.name = newName; try { Long avatarId = Long.valueOf(userForm.data().get("avatarId")); if (avatarId != null) { Attachment attachment = Attachment.find.byId(avatarId); String primary = attachment.mimeType.split("/")[0].toLowerCase(); if (attachment.size > AVATAR_FILE_LIMIT_SIZE) { userForm.reject("avatarId", "user.avatar.fileSizeAlert"); } if (primary.equals("image")) { Attachment.deleteAll(currentUser().avatarAsResource()); attachment.moveTo(currentUser().avatarAsResource()); } } } catch (NumberFormatException ignored) { } Email.deleteOtherInvalidEmails(user.email); user.update(); return redirect( routes.UserApp.userInfo(user.loginId, DEFAULT_GROUP, DAYS_AGO, DEFAULT_SELECTED_TAB)); }
public static Result workoutSchedule() { ExerciseScheduleRule exSchRule = new ExerciseScheduleRule(); CardioRule caRule = new CardioRule(); User thisUser = User.findById(Long.parseLong(session("userId"))); int userWorkoutDays = thisUser.getUserWorkoutDays(); int age = thisUser.getAge(); boolean workoutIsIntense = thisUser.isWorkoutIsIntense(); boolean cardioIsIntense = thisUser.isCardioIsIntense(); String gender = thisUser.getGender(); if (userWorkoutDays == 0) { flash("error", "Please setting your plan."); return redirect(routes.Profile.index()); } exSchRule.setInput(userWorkoutDays, false, gender); caRule.setInput(age, false); RulesEngine rulesEngine = aNewRulesEngine().withSilentMode(true).build(); rulesEngine.registerRule(exSchRule); rulesEngine.registerRule(caRule); rulesEngine.fireRules(); List<Day> workoutScheduleList = exSchRule.getResult(); List<Cardio> cardiotScheduleList = caRule.getResult(); exSchRule.setInput(userWorkoutDays, true, gender); caRule.setInput(age, true); rulesEngine = aNewRulesEngine().withSilentMode(true).build(); rulesEngine.registerRule(exSchRule); rulesEngine.registerRule(caRule); rulesEngine.fireRules(); List<Day> workoutScheduleIntenseList = exSchRule.getResult(); List<Cardio> cardiotScheduleIntenseList = caRule.getResult(); return ok( workout_schedule.render( workoutScheduleList, cardiotScheduleList, cardioIsIntense, workoutScheduleIntenseList, cardiotScheduleIntenseList, thisUser.isGain())); }
/** * 프로젝트 제한을 두지 않고 전체 이슈를 대상으로 검색할 때 사용한다. * * @return ExpressionList<Issue> */ public ExpressionList<Issue> asExpressionList() { ExpressionList<Issue> el = Issue.finder.where(); if (assigneeId != null) { if (assigneeId.equals(User.anonymous.id)) { el.isNull("assignee"); } else { el.eq("assignee.user.id", assigneeId); } } if (authorId != null) { el.eq("authorId", authorId); } if (StringUtils.isNotBlank(filter)) { Junction<Issue> junction = el.disjunction(); junction.icontains("title", filter).icontains("body", filter); List<Object> ids = Issue.finder.where().icontains("comments.contents", filter).findIds(); if (!ids.isEmpty()) { junction.idIn(ids); } junction.endJunction(); } if (commentedCheck) { el.ge("numOfComments", AbstractPosting.NUMBER_OF_ONE_MORE_COMMENTS); } State st = State.getValue(state); if (st.equals(State.OPEN) || st.equals(State.CLOSED)) { el.eq("state", st); } if (orderBy != null) { el.orderBy(orderBy + " " + orderDir); } return el; }
public static void cambiarContrasenia() { String clave = params.get("clave"); Long coUsuario = Long.parseLong(params.get("coUsuario")); Map result = new HashMap(); String deUsuario = session.get("usuario"); VmdbUsuario usuario = VmdbUsuario.find("coUsuario = ? and stUsuario = '1'", coUsuario).first(); usuario.setDeClave(clave); usuario.setDaFechaModificacion(new Date()); usuario.setCoUsuarioModificacion(deUsuario); usuario.save(); /** Actualizar clave en Persona * */ VmdbPersona objPersona = VmdbPersona.findById(usuario.getVmdbPersona().getCoPersona()); objPersona.setDeClave(clave); objPersona.setCoUsuarioModificacion(deUsuario); objPersona.setDaFechaModificacion(new Date()); objPersona.save(); /** -----------------------------* */ result.put("status", 1); result.put("message", "Su clave fue actualizado correctamente"); JSONSerializer mapeo = new JSONSerializer(); renderJSON(mapeo.serialize(result)); }
public static User connectedUser() { String userId = session.get("logged"); return userId == null ? null : (User) User.findById(Long.parseLong(userId)); }
// TODO pull this out into something reusable static User current() { User current = null; String idString = session.get("user"); if (idString != null) current = User.findById(Long.parseLong(idString)); return current; }
public static void list( String search, int category, Integer size, Integer page, int firstPage, int lastPage) { List<Ad> ads = null; List<Category> cats = Category.find("categorytype_id=?1", "1").fetch(); EntityManager entityManager = play.db.jpa.JPA.em(); List<BigInteger> bCounts = entityManager .createNativeQuery( "select count(*) as maxCount from Ad as a group by category_id order by maxCount") .getResultList(); int min = bCounts.get(0).intValue(); int max = bCounts.get(bCounts.size() - 1).intValue(); bCounts = entityManager .createNativeQuery( "select count(*) as maxCount from Ad as a group by category_id order by category_id ") .getResultList(); List<String> fonts = new ArrayList<String>(); for (int i = 0; i < bCounts.size(); i++) { BigInteger count = bCounts.get(i); int x = Ads.getFontSize(count.intValue(), min, max); fonts.add(String.valueOf(x)); } int pagesCount = 0; page = page != null ? page : 1; if (search.trim().length() == 0) { Long l = null; if (category == 0) { ads = Ad.find("order by createDate desc").fetch(page, size); l = Ad.count(); } else { ads = Ad.find(" category_id=?1 order by createDate desc", category).fetch(page, size); l = Ad.count(" category_id=?1 ", category); } Long l2 = (l / 10); if ((l % 10) > 0) l2 = (long) (Math.floor(l2) + 1); pagesCount = Integer.valueOf(l2.intValue()); } else { search = search.toLowerCase(); Long l = null; if (category == 0) { ads = Ad.find( "(lower(headline) like ?1 OR lower(description) like ?2)", "%" + search + "%", "%" + search + "%") .fetch(page, size); l = Ad.count( "(lower(headline) like ?1 OR lower(description) like ?2)", "%" + search + "%", "%" + search + "%"); } else { ads = Ad.find( " category_id=?1 and (lower(headline) like ?2 OR lower(description) like ?3)", category, "%" + search + "%", "%" + search + "%") .fetch(page, size); l = Ad.count( "category_id=?1 and (lower(headline) like ?2 OR lower(description) like ?3)", category, "%" + search + "%", "%" + search + "%"); } Long l2 = (l / 10); if ((l % 10) > 0) l2 = (long) (Math.floor(l2) + 1); pagesCount = Integer.valueOf(l2.intValue()); } if ((lastPage - page) <= 2) { firstPage = page - 2; lastPage = page + 7; if (lastPage > pagesCount) lastPage = pagesCount; } else if ((page - firstPage) <= 2) { firstPage = page - 7; lastPage = page + 2; if (firstPage < 1) { firstPage = 1; lastPage = 10; } } if (lastPage > pagesCount) lastPage = pagesCount; render(ads, search, size, page, pagesCount, firstPage, lastPage, cats, fonts); }
public static void viewCambiarContrasenia() { Long coPersona = Long.parseLong(session.get("idPersona")); VmdbUsuario usuario = VmdbUsuario.find("vmdbPersona.coPersona = ? and stUsuario = '1'", coPersona).first(); render("Usuarios/editPassword.html", usuario); }
/** * 특정 프로젝트를 대상으로 검색 표현식을 만든다. * * @return ExpressionList<Issue> */ public ExpressionList<Issue> asExpressionList(Project project) { ExpressionList<Issue> el = Issue.finder.where(); if (project != null) { el.eq("project.id", project.id); } if (StringUtils.isNotBlank(filter)) { Junction<Issue> junction = el.disjunction(); junction.icontains("title", filter).icontains("body", filter); List<Object> ids = null; if (project == null) { ids = Issue.finder.where().icontains("comments.contents", filter).findIds(); } else { ids = Issue.finder .where() .eq("project.id", project.id) .icontains("comments.contents", filter) .findIds(); } if (!ids.isEmpty()) { junction.idIn(ids); } junction.endJunction(); } if (authorId != null) { if (authorId.equals(User.anonymous.id)) { el.isNull("authorId"); } else { el.eq("authorId", authorId); } } if (assigneeId != null) { if (assigneeId.equals(User.anonymous.id)) { el.isNull("assignee"); } else { el.eq("assignee.user.id", assigneeId); el.eq("assignee.project.id", project.id); } } if (milestoneId != null) { if (milestoneId.equals(Milestone.NULL_MILESTONE_ID)) { el.isNull("milestone"); } else { el.eq("milestone.id", milestoneId); } } if (commentedCheck) { el.ge("numOfComments", AbstractPosting.NUMBER_OF_ONE_MORE_COMMENTS); } State st = State.getValue(state); if (st.equals(State.OPEN) || st.equals(State.CLOSED)) { el.eq("state", st); } if (CollectionUtils.isNotEmpty(labelIds)) { el.add(LabelSearchUtil.createLabelSearchExpression(el.query(), labelIds)); } if (orderBy != null) { el.orderBy(orderBy + " " + orderDir); } return el; }
public static void save() throws Throwable { String username = params.get("username"); String name = params.get("name"); String password = params.get("password"); String[] materials = params.getAll("material"); String registration_number = params.get("registration_number"); String registration_assets = params.get("registration_assets"); String registration_assets_unit = params.get("registration_assets_unit"); String registration_address = params.get("registration_address"); String bank_name = params.get("bank_name"); String account_name = params.get("account_name"); String tfn = params.get("tfn"); String legal_person = params.get("legal_person"); String factory_name = params.get("factory_name"); String factory_address = params.get("factory_address"); String first_supply = params.get("first_supply"); String business_model = params.get("business_model"); String contact_name = params.get("contact_name"); String contact_job = params.get("contact_job"); String contact_phone = params.get("contact_phone"); String contact_email = params.get("contact_email"); String sales_name = params.get("sales_name"); String sales_job = params.get("sales_job"); String sales_phone = params.get("sales_phone"); String[] files = params.getAll("files"); User user = null; Material m = null; Files file = null; if (username != null && password != null && !"".equals(username) && !"".equals(password)) { user = User.find("username=?", username).first(); if (user == null) { user = new User(username, password, ApplicationRole.getByName("user")); user.save(); } Profile profile = Profile.find("user.id=?", user.id).first(); if (profile == null) { profile = new Profile(); profile.user = user; } if (materials != null) { for (String material_id : materials) { m = Material.find("id=?", Long.valueOf(material_id.trim())).first(); if (m != null) profile.materials.add(m); } } profile.name = name; profile.registration_number = registration_number; profile.registration_assets = registration_assets; profile.registration_address = registration_address; profile.registration_assets_unit = registration_assets_unit; profile.bank_name = bank_name; profile.account_name = account_name; profile.tfn = tfn; profile.legal_person = legal_person; profile.factory_name = factory_name; profile.factory_address = factory_address; profile.first_supply = first_supply; profile.business_model = business_model; profile.contact_name = contact_name; profile.contact_job = contact_job; profile.contact_phone = contact_phone; profile.contact_email = contact_email; profile.sales_name = sales_name; profile.sales_job = sales_job; profile.sales_phone = sales_phone; if (files != null) { for (String f : files) { file = Files.find("id=?", Long.valueOf(f)).first(); if (file != null) { profile.files.add(file); } } } profile.save(); } session.put("username", username); Secure.redirectToOriginalURL(); }
@Override public List<Component> getComponents( Long applicationId, Long componentId, Long instanceId, Long cloudId) { List<Component> result = new ArrayList<Component>(); List<Component> components = componentModelService.getAll(); List<Instance> instances = null; List<VirtualMachine> vms = null; List<ApplicationComponent> appComps = applicationComponentModelService.getAll(); for (Component component : components) { boolean suitable = false; if (applicationId != null) { for (ApplicationComponent ac : appComps) { if (ac.getComponent().getId().equals(componentId) && ac.getApplication().getId().equals(applicationId)) { suitable = true; } } } if (componentId != null) { if (componentId.equals(component.getId())) { suitable = suitable && true; } } if (instanceId != null) { if (instances == null) instances = instanceModelService.getAll(); boolean oneFits = false; for (Instance instance : instances) { if (isInstanceOf(instance, appComps, component)) { oneFits = true; } } if (oneFits) { suitable = suitable && true; } else { suitable = false; } } if (cloudId != null) { if (instances == null) instances = instanceModelService.getAll(); if (vms == null) vms = virtualMachineModelService.getAll(); boolean oneFits = false; for (Instance instance : instances) { if (isInstanceOf(instance, vms, cloudId)) { if (isInstanceOf(instance, appComps, component)) { oneFits = true; } } } if (oneFits) { suitable = suitable && true; } else { suitable = false; } } if (suitable) { result.add(component); } } return result; }