@Override
 protected void process(final ActivityInformation<MissionProcess> activityInformation) {
   final User user = Authenticate.getUser();
   final Person person = user.getPerson();
   final MissionProcess missionProcess = activityInformation.getProcess();
   missionProcess.unAllocateFunds(person);
 }
Exemplo n.º 2
0
  public ActionForward showTeacherCredits(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws NumberFormatException, FenixServiceException, ParseException {

    DynaActionForm teacherCreditsForm = (DynaActionForm) form;
    ExecutionSemester executionSemester =
        FenixFramework.getDomainObject((String) teacherCreditsForm.get("executionPeriodId"));

    Teacher requestedTeacher =
        FenixFramework.getDomainObject((String) teacherCreditsForm.get("teacherId"));

    User userView = Authenticate.getUser();
    Teacher loggedTeacher = userView.getPerson().getTeacher();

    if (requestedTeacher == null || loggedTeacher != requestedTeacher) {
      ActionMessages actionMessages = new ActionMessages();
      actionMessages.add("", new ActionMessage("message.invalid.teacher"));
      saveMessages(request, actionMessages);
      return mapping.findForward("teacher-not-found");
    }

    showLinks(request, executionSemester, RoleType.DEPARTMENT_MEMBER);
    getAllTeacherCredits(request, executionSemester, requestedTeacher);
    return mapping.findForward("show-teacher-credits");
  }
  public void execute(Summary summary, Professorship professorshipLogged)
      throws NotAuthorizedException {

    try {
      User userViewLogged = Authenticate.getUser();

      boolean executionCourseResponsibleLogged = professorshipLogged.isResponsibleFor();

      if (userViewLogged == null
          || userViewLogged.getPerson().getPersonRolesSet() == null
          || professorshipLogged == null) {
        throw new NotAuthorizedException("error.summary.not.authorized");
      }
      if (executionCourseResponsibleLogged
          && (summary.getProfessorship() != null
              && (!summary.getProfessorship().equals(professorshipLogged)))) {
        throw new NotAuthorizedException("error.summary.not.authorized");

      } else if (!executionCourseResponsibleLogged
          && (summary.getProfessorship() == null
              || (!summary.getProfessorship().equals(professorshipLogged)))) {
        throw new NotAuthorizedException("error.summary.not.authorized");
      }

    } catch (RuntimeException ex) {
      throw new NotAuthorizedException("error.summary.not.authorized");
    }
  }
Exemplo n.º 4
0
  private SupportRequestBean userInfoContextAppend(
      HttpServletRequest request, final StringBuilder exceptionInfo) {

    exceptionInfo.append("[UserLoggedIn] ");

    SupportRequestBean requestBean;
    String user;
    User userView = Authenticate.getUser();
    if (userView != null) {
      user = userView.getUsername();
      requestBean = SupportRequestBean.generateExceptionBean(userView.getPerson());
      MenuFunctionality selectedFunctionality =
          BennuPortalDispatcher.getSelectedFunctionality(request);
      if (selectedFunctionality != null) {
        requestBean.setSelectedFunctionality(selectedFunctionality);
      }
      setUserName(user);
      Set<RoleType> roles = new HashSet<RoleType>();
      for (Role role : userView.getPerson().getPersonRolesSet()) {
        roles.add(role.getRoleType());
      }
      setUserRoles(roles);
    } else {
      user = "******";
      requestBean = SupportRequestBean.generateExceptionBean(null);
    }
    exceptionInfo.append(user + "\n");
    return requestBean;
  }
 @Override
 public boolean isMember(User user) {
   if (user == null) {
     return false;
   }
   if (user.getPerson().getStudent() != null) {
     final Set<CompetenceCourse> competenceCourses = executionCourse.getCompetenceCourses();
     for (Registration registration : user.getPerson().getStudent().getRegistrationsSet()) {
       // students of any degree sharing the same competence of the given execution course
       for (StudentCurricularPlan studentCurricularPlan :
           registration.getStudentCurricularPlansSet()) {
         for (Enrolment enrolment : studentCurricularPlan.getEnrolmentsSet()) {
           CompetenceCourse competenceCourse =
               enrolment.getCurricularCourse().getCompetenceCourse();
           if (competenceCourses.contains(competenceCourse)) {
             return true;
           }
         }
       }
       // students attending the given execution course (most will be in the previous case but some
       // may not)
       if (registration.getAttendingExecutionCoursesFor().contains(executionCourse)) {
         return true;
       }
     }
   }
   return false;
 }
Exemplo n.º 6
0
 @Test
 @Atomic(mode = TxMode.READ)
 public void loggedCompression() {
   assertEquals(Group.logged(), Group.logged().grant(user1));
   assertEquals(Group.logged(), user1.groupOf().or(Group.logged()));
   assertEquals(user1.groupOf(), Group.logged().and(user1.groupOf()));
   assertEquals(user1.groupOf(), user1.groupOf().and(Group.logged()));
   assertEquals(Group.logged(), user1.groupOf().or(Group.logged()));
 }
 @Atomic
 public void createNewPeriod() {
   final User userView = Authenticate.getUser();
   if (userView != null && RoleType.MANAGER.isMember(userView.getPerson().getUser())) {
     if (title != null && title.hasContent() && start != null && end != null) {
       new GenericApplicationPeriod(title, description, start, end);
     }
   }
 }
Exemplo n.º 8
0
  public static Set<Sender> getAvailableSenders() {
    final User userView = Authenticate.getUser();

    final Set<Sender> senders = new TreeSet<Sender>(Sender.COMPARATOR_BY_FROM_NAME);
    for (final Sender sender : Bennu.getInstance().getUtilEmailSendersSet()) {
      if (sender.getMembers().isMember(userView)
          || (userView != null && userView.getPerson().hasRole(RoleType.MANAGER))) {
        senders.add(sender);
      }
    }

    return senders;
  }
  public void execute(String executionDegreeID, List<SituationName> situationNames)
      throws NotAuthorizedException {

    User id = Authenticate.getUser();
    if ((id != null
            && id.getPerson().getPersonRolesSet() != null
            && !containsRoleType(id.getPerson().getPersonRolesSet()))
        || (id != null
            && id.getPerson().getPersonRolesSet() != null
            && !hasPrivilege(id, executionDegreeID))
        || (id == null)
        || (id.getPerson().getPersonRolesSet() == null)) {
      throw new NotAuthorizedException();
    }
  }
Exemplo n.º 10
0
  @Override
  protected PhdThesisProcess executeActivity(
      PhdThesisProcess process, User userView, Object object) {

    final PhdThesisProcessBean bean = (PhdThesisProcessBean) object;

    if (bean.isToNotify()) {
      notifyJuryElements(process);
      sendAlertToJuryElement(
          process.getIndividualProgramProcess(),
          process.getPresidentJuryElement(),
          "message.phd.request.jury.reviews.external.access.jury.president.body");
    }

    if (process.getActiveState() != PhdThesisProcessStateType.WAITING_FOR_JURY_REPORTER_FEEDBACK) {
      process.createState(
          PhdThesisProcessStateType.WAITING_FOR_JURY_REPORTER_FEEDBACK, userView.getPerson(), "");
    }

    bean.setThesisProcess(process);
    if (process.getMeetingProcess() == null) {
      Process.createNewProcess(userView, PhdMeetingSchedulingProcess.class, bean);
    }

    return process;
  }
Exemplo n.º 11
0
 @Override
 public boolean isActive(final MissionProcess missionProcess, final User user) {
   return super.isActive(missionProcess, user)
       && missionProcess.hasAnyAllocatedFunds()
       && ((!missionProcess.hasAnyAuthorization() && !missionProcess.hasCommitmentNumber())
           || missionProcess.getIsCanceled().booleanValue())
       && missionProcess.isAccountingEmployee(user.getExpenditurePerson());
 }
  /**
   * @param id
   * @param argumentos
   * @return
   */
  private boolean hasPrivilege(User id, String executionDegreeID) {

    ExecutionDegree executionDegree = null;

    // Read The DegreeCurricularPlan
    try {

      executionDegree = FenixFramework.getDomainObject(executionDegreeID);

    } catch (Exception e) {
      return false;
    }

    if (executionDegree == null) {
      return false;
    }

    if (id.getPerson().hasRole(RoleType.MASTER_DEGREE_ADMINISTRATIVE_OFFICE)) {
      if (executionDegree
          .getDegreeCurricularPlan()
          .getDegree()
          .getDegreeType()
          .equals(DegreeType.MASTER_DEGREE)) {

        return true;
      }
      return false;
    }

    if (id.getPerson().hasRole(RoleType.COORDINATOR)) {
      // modified by Tânia Pousão
      Collection<Coordinator> coodinatorsList = executionDegree.getCoordinatorsListSet();
      if (coodinatorsList == null) {
        return false;
      }
      Iterator<Coordinator> listIterator = coodinatorsList.iterator();
      while (listIterator.hasNext()) {
        Coordinator coordinator = listIterator.next();

        if (coordinator.getPerson() == id.getPerson()) {
          return true;
        }
      }
    }
    return false;
  }
Exemplo n.º 13
0
 @BeforeClass
 @Atomic(mode = TxMode.WRITE)
 public static void setupUsers() {
   ManualGroupRegister.ensure();
   user1 = User.findByUsername("user1");
   if (user1 == null) {
     user1 = new User("user1", ManualGroupRegister.newProfile());
   }
 }
 public SortedSet<OutboundMobilityCandidacyContestGroup> getCandidacyContestGroupSet(
     final OutboundMobilityCandidacyPeriod period) {
   final User user = Authenticate.getUser();
   if (AcademicAuthorizationGroup.get(AcademicOperationType.MANAGE_MOBILITY_OUTBOUND)
       .isMember(user)) {
     return period.getOutboundMobilityCandidacyContestGroupSet();
   }
   final SortedSet<OutboundMobilityCandidacyContestGroup> result =
       new TreeSet<OutboundMobilityCandidacyContestGroup>();
   if (user != null && user.getPerson() != null) {
     for (final OutboundMobilityCandidacyContestGroup group :
         user.getPerson().getOutboundMobilityCandidacyContestGroupSet()) {
       if (hasContestForPeriod(period, group)) {
         result.add(group);
       }
     }
   }
   return result;
 }
 @Override
 public boolean isMember(User user) {
   if (user == null || user.getPerson().getCoordinatorsSet().isEmpty()) {
     return false;
   }
   for (Coordinator coordinator : user.getPerson().getCoordinatorsSet()) {
     ExecutionDegree executionDegree = coordinator.getExecutionDegree();
     if (executionDegree.getExecutionYear().isCurrent()) {
       if (degreeType != null && degreeType != executionDegree.getDegree().getDegreeType()) {
         continue;
       }
       if (degree != null && !executionDegree.getDegree().equals(degree)) {
         continue;
       }
       return true;
     }
   }
   return false;
 }
Exemplo n.º 16
0
  public static boolean hasAvailableSender() {
    final User userView = Authenticate.getUser();
    if (userView != null) {
      if (userView.getPerson().hasRole(RoleType.MANAGER)) {
        return true;
      }

      final Person person = userView.getPerson();
      if (person != null && !person.getMessagesSet().isEmpty()) {
        return true;
      }

      for (final Sender sender : Bennu.getInstance().getUtilEmailSendersSet()) {
        if (sender.allows(userView)) {
          return true;
        }
      }
    }
    return false;
  }
Exemplo n.º 17
0
 private static CgdCard findCardFor(
     final User user, final int year, final boolean createIfNotExists) {
   final CgdCard card =
       user.getCgdCardSet()
           .stream()
           .filter(c -> c.getCgdCardCounter().getYear() == year)
           .findAny()
           .orElse(null);
   return card == null && createIfNotExists
       ? CgdCardCounter.findCounterForYear(year).createNewSerialNumber(user)
       : card;
 }
  public ActionForward showPaymentsForEvent(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response) {

    final Event event = getEvent(request);
    request.setAttribute("event", event);

    if (!StringUtils.isEmpty(event.getCreatedBy())) {
      User responsible = User.findByUsername(event.getCreatedBy());
      request.setAttribute("responsible", responsible.getPerson());
    }

    if (event.isOpen()) {
      request.setAttribute("entryDTOs", event.calculateEntries());
      request.setAttribute("accountingEventPaymentCodes", event.getNonProcessedPaymentCodes());
    }

    return mapping.findForward("showPaymentsForEvent");
  }
  private static boolean isAllowedToManageProcess(
      DegreeChangeIndividualCandidacyProcess process, User userView) {
    Set<AcademicProgram> programs =
        AcademicAuthorizationGroup.getProgramsForOperation(
            userView.getPerson(), AcademicOperationType.MANAGE_INDIVIDUAL_CANDIDACIES);

    if (process == null || process.getCandidacy() == null) {
      return false;
    }

    return programs.contains(process.getCandidacy().getSelectedDegree());
  }
 private boolean isVisible(PartyContact contact) {
   boolean publicSpace =
       true; // because this is a homepage. When this logic is exported to a more proper place
             // remember to pass this as an argument.
   if (!Authenticate.isLogged() && publicSpace && contact.getVisibleToPublic().booleanValue()) {
     return true;
   }
   if (Authenticate.isLogged()) {
     User user = Authenticate.getUser();
     Person reader = user.getPerson();
     if (reader.hasRole(RoleType.CONTACT_ADMIN).booleanValue()
         || reader.hasRole(RoleType.MANAGER).booleanValue()
         || reader.hasRole(RoleType.DIRECTIVE_COUNCIL).booleanValue()) {
       return true;
     }
     if (reader.hasRole(RoleType.EMPLOYEE).booleanValue()
         && contact.getVisibleToEmployees().booleanValue()) {
       return true;
     }
     if (reader.hasRole(RoleType.TEACHER).booleanValue()
         && contact.getVisibleToTeachers().booleanValue()) {
       return true;
     }
     if (reader.hasRole(RoleType.STUDENT).booleanValue()
         && contact.getVisibleToStudents().booleanValue()) {
       return true;
     }
     if (reader.hasRole(RoleType.ALUMNI).booleanValue()
         && contact.getVisibleToAlumni().booleanValue()) {
       return true;
     }
     if (contact.getVisibleToPublic()) {
       return true;
     }
   }
   return false;
 }
Exemplo n.º 21
0
  @Override
  protected PhdProgramCandidacyProcess executeActivity(
      PhdProgramCandidacyProcess process, User userView, Object object) {
    final PhdProgramCandidacyProcessStateBean bean = (PhdProgramCandidacyProcessStateBean) object;
    process.createState(
        PhdProgramCandidacyProcessState.REJECTED, userView.getPerson(), bean.getRemarks());

    AlertService.alertAcademicOffice(
        process.getIndividualProgramProcess(),
        AcademicOperationType.VIEW_PHD_CANDIDACY_ALERTS,
        "message.phd.alert.candidacy.reject.subject",
        "message.phd.alert.candidacy.reject.body");

    return process;
  }
Exemplo n.º 22
0
 private static void createEnrolments(
     User userView,
     MasterDegreeCandidate masterDegreeCandidate,
     StudentCurricularPlan studentCurricularPlan) {
   Collection<CandidateEnrolment> candidateEnrolments =
       masterDegreeCandidate.getCandidateEnrolments();
   ExecutionSemester executionSemester = ExecutionSemester.readActualExecutionSemester();
   for (CandidateEnrolment candidateEnrolment : candidateEnrolments) {
     new Enrolment(
         studentCurricularPlan,
         candidateEnrolment.getCurricularCourse(),
         executionSemester,
         EnrollmentCondition.FINAL,
         userView.getUsername());
   }
 }
Exemplo n.º 23
0
  @POST
  @Produces(JSON_UTF8)
  @Path("disconnectMissionProcess")
  public Response disconnectMissionProcess(
      @QueryParam("processNumber") String processNumber,
      @QueryParam("hostname") String hostname,
      @QueryParam("remoteProcessNumber") String remoteProcessNumber,
      @QueryParam("username") String username,
      @QueryParam("access_token") String access_token) {

    checkToken(access_token);
    login(User.findByUsername(username));
    try {
      final Mission mission = findMission(remoteProcessNumber);
      if (mission == null) {
        return respondWithError(Status.BAD_REQUEST, "bad.mission.number");
      } else {
        final MissionProcess missionProcess = mission.getMissionProcess();

        final RemoteMissionSystem remoteMissionSystem = RemoteMissionSystem.find(hostname);
        if (remoteMissionSystem == null) {
          return respondWithError(Status.NOT_ACCEPTABLE, "remote.host.not.configured");
        }

        for (final RemoteMissionProcess remoteMissionProcess :
            missionProcess.getRemoteMissionProcessSet()) {
          if (remoteMissionProcess.getRemoteMissionSystem() == remoteMissionSystem
              && remoteMissionProcess.getProcessNumber().equals(processNumber)) {
            final DisassociateMissionProcessActivity activity =
                (DisassociateMissionProcessActivity)
                    missionProcess.getActivity(DisassociateMissionProcessActivity.class);
            final DisassociateMissionProcessActivityInfo information =
                activity.getActivityInformation(missionProcess);
            information.setRemoteMissionProcess(remoteMissionProcess);
            information.setConnect(false);
            activity.execute(information);
          }
        }

        return Response.ok().build();
      }
    } finally {
      logout();
    }
  }
Exemplo n.º 24
0
  @POST
  @Produces(JSON_UTF8)
  @Path("connectMissionProcess")
  public Response connectMissionProcess(
      @QueryParam("processNumber") String processNumber,
      @QueryParam("externalId") String externalId,
      @QueryParam("hostname") String hostname,
      @QueryParam("remoteProcessNumber") String remoteProcessNumber,
      @QueryParam("username") String username,
      @QueryParam("access_token") String access_token) {

    checkToken(access_token);
    try {
      login(User.findByUsername(username));
      final Mission mission = findMission(remoteProcessNumber);
      if (mission == null) {
        return respondWithError(Status.BAD_REQUEST, "bad.mission.number");
      } else {
        final MissionProcess missionProcess = mission.getMissionProcess();

        final RemoteMissionSystem remoteMissionSystem = RemoteMissionSystem.find(hostname);
        if (remoteMissionSystem == null) {
          return respondWithError(Status.NOT_ACCEPTABLE, "remote.host.not.configured");
        }

        final AssociateMissionProcessActivity activity =
            (AssociateMissionProcessActivity)
                missionProcess.getActivity(AssociateMissionProcessActivity.class);
        final AssociateMissionProcessActivityInfo information =
            activity.getActivityInformation(missionProcess);
        information.setProcessNumber(processNumber);
        information.setExternalId(externalId);
        information.setRemoteMissionSystem(remoteMissionSystem);
        information.setConnect(false);
        activity.execute(information);

        final JsonObject obj = new JsonObject();
        obj.addProperty("processID", missionProcess.getProcessNumber());
        obj.addProperty("externalId", missionProcess.getExternalId());
        return Response.ok().entity(gson.toJson(obj)).build();
      }
    } finally {
      logout();
    }
  }
Exemplo n.º 25
0
  // change to put
  @PUT
  @Produces(JSON_UTF8)
  @Path("cancelFundAllocation")
  public String cancelFundAllocation(
      @QueryParam("processID") String processID,
      @QueryParam("userID") String userID,
      @QueryParam("access_token") String access_token) {
    checkToken(access_token);
    login(User.findByUsername(userID));
    try {
      WorkflowSystem ws = WorkflowSystem.getInstance();
      Set<WorkflowProcess> processes = ws.getProcessesSet();
      for (WorkflowProcess workflowProcess : processes) {
        if (workflowProcess.getProcessNumber() != null) {
          if (workflowProcess.getProcessNumber().equals(processID)) {
            WorkflowActivity<WorkflowProcess, ActivityInformation<WorkflowProcess>>
                cancelAcquisitionRequest =
                    workflowProcess.getActivity(
                        DeleteAfterTheFactAcquisitionProcess.class.getSimpleName());

            if (cancelAcquisitionRequest == null) { // is not after the fact
              cancelAcquisitionRequest =
                  workflowProcess.getActivity(CancelAcquisitionRequest.class.getSimpleName());
            }
            try {
              cancelAcquisitionRequest.execute(
                  new ActivityInformation<WorkflowProcess>(
                      workflowProcess, cancelAcquisitionRequest));
            } catch (Exception e) {
              throw newApplicationError(Status.NOT_ACCEPTABLE, "cancelation_not_acceptable");
            }
            JsonObject obj = new JsonObject();
            obj.addProperty("status", Status.OK.toString());
            return gson.toJson(obj);
          }
        }
      }
      // No process was found
      throw newApplicationError(Status.NOT_FOUND, "resource_not_found");
    } finally {
      logout();
    }
  }
Exemplo n.º 26
0
  @Override
  protected PhdProgramCandidacyProcess executeActivity(
      PhdProgramCandidacyProcess process, User userView, Object object) {

    final PhdIndividualProgramProcess mainProcess = process.getIndividualProgramProcess();
    if (mainProcess.getPhdProgram() == null) {
      throw new DomainException(
          "error.phd.candidacy.PhdProgramCandidacyProcess.RequestCandidacyReview.invalid.phd.program");
    }

    final PhdProgramCandidacyProcessStateBean bean = (PhdProgramCandidacyProcessStateBean) object;
    process.createState(
        PhdProgramCandidacyProcessState.PENDING_FOR_COORDINATOR_OPINION,
        userView.getPerson(),
        bean.getRemarks());

    if (bean.getGenerateAlert()) {
      AlertService.alertCoordinators(mainProcess, subject(), body(mainProcess));
    }

    return process;
  }
 private Department getPersonDepartment() {
   final User userView = getUserView();
   final Person person = userView == null ? null : userView.getPerson();
   final Employee employee = person == null ? null : person.getEmployee();
   return employee == null ? null : employee.getCurrentDepartmentWorkingPlace();
 }
Exemplo n.º 28
0
  @POST
  @Produces(JSON_UTF8)
  @Path("allocateFunds")
  public Response allocateFunds(
      @QueryParam("supplierID") String supplierID,
      @QueryParam("value") String value,
      @QueryParam("valueVat") String valueVAT,
      @QueryParam("cpvCode") String cpvcode,
      @QueryParam("goodsOrService") String goodsOrServices,
      @QueryParam("description") String description,
      @QueryParam("userID") String userID,
      @QueryParam("access_token") String access_token) {

    checkToken(access_token);
    login(User.findByUsername(userID));
    try {

      AfterTheFactAcquisitionProcessBean bean = new AfterTheFactAcquisitionProcessBean();

      Set<Supplier> suppliers = Bennu.getInstance().getSuppliersSet();
      Supplier supplier = null;

      for (Supplier sup : suppliers) {
        if (sup.getExternalId().equals(supplierID)) {
          supplier = sup;
          break;
        }
      }
      if (supplier == null) {
        return respondWithError(Status.NOT_FOUND, "supplier.not.found");
      }

      bean.setSupplier(supplier);
      bean.setAfterTheFactAcquisitionType(AfterTheFactAcquisitionType.PURCHASE);

      Money itemValue = new Money(value);
      bean.setValue(itemValue);

      double VAT = Double.parseDouble(valueVAT);
      bean.setVatValue(new BigDecimal(VAT));

      bean.setYear(new LocalDate().getYear());
      bean.setDescription(description);
      bean.setClassification(AcquisitionItemClassification.valueOf(goodsOrServices.toUpperCase()));
      CPVReference cpvReference = CPVReference.getCPVCode(cpvcode);
      if (cpvReference == null) {
        return respondWithError(Status.NOT_FOUND, "cpv.reference.not.found");
      }
      bean.setCpvReference(cpvReference);

      AfterTheFactAcquisitionProcess process;

      try {
        process = AfterTheFactAcquisitionProcess.createNewAfterTheFactAcquisitionProcess(bean);
      } catch (DomainException e) {
        throw newApplicationError(Status.PRECONDITION_FAILED, "precondition_failed");
      }

      JsonObject obj = new JsonObject();
      obj.addProperty("processID", process.getProcessNumber());
      return Response.ok().entity(gson.toJson(obj)).build();
    } finally {
      logout();
    }
  }
 @Override
 public boolean isMember(User user) {
   return user != null
       && user.getPerson() != null
       && !user.getPerson().getProfessorshipsSet().isEmpty();
 }
Exemplo n.º 30
0
 private static boolean isSelfPerson(Party person) {
   final User userView = Authenticate.getUser();
   return userView.getPerson() != null && userView.getPerson().equals(person);
 }