Search in sources :

Example 16 with SubjectException

use of com.remswork.project.alice.exception.SubjectException in project classify-system by anverliedoit.

the class Teacher_Activity_Teacher_Profile method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    TeacherServiceImpl teacherService = new TeacherServiceImpl();
    Teacher teacher;
    try {
        teacher = teacherService.getTeacherById(getIntent().getExtras().getLong("teacherId"));
    } catch (Exception e) {
        e.printStackTrace();
        teacher = new Teacher();
    }
    setContentView(R.layout.teacher_activity_view_teacher_profile);
    txtvName = (TextView) findViewById(R.id.txtv_fullname);
    txtvDept = (TextView) findViewById(R.id.txtv_dept);
    buttonback = (Button) findViewById(R.id.add_backsubject);
    recyclerView = (RecyclerView) findViewById(R.id.recyclerview_view_subject);
    SubjectServiceImpl subjectService = new SubjectServiceImpl();
    SubjectAdapter subjectAdapter = null;
    try {
        subjectAdapter = new SubjectAdapter(this, subjectService.getSubjectListByTeacherId(teacher.getId()));
    } catch (SubjectException e) {
        e.printStackTrace();
    }
    LinearLayoutManager layoutManager = new LinearLayoutManager(this);
    recyclerView.setAdapter(subjectAdapter);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    txtvName.setText(teacher.getFirstName() + " " + teacher.getMiddleName().substring(0, 1) + ". " + teacher.getLastName());
    txtvDept.setText(teacher.getDepartment() != null ? teacher.getDepartment().getName() : "None");
    buttonback.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            finish();
        }
    });
}
Also used : SubjectServiceImpl(com.remswork.project.alice.service.impl.SubjectServiceImpl) Teacher(com.remswork.project.alice.model.Teacher) SubjectAdapter(com.lieverandiver.thesisproject.adapter.SubjectAdapter) SubjectException(com.remswork.project.alice.exception.SubjectException) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) SubjectException(com.remswork.project.alice.exception.SubjectException) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) TeacherServiceImpl(com.remswork.project.alice.service.impl.TeacherServiceImpl)

Example 17 with SubjectException

use of com.remswork.project.alice.exception.SubjectException in project classify-system by anverliedoit.

the class Teacher_Activity_View_Subject_Datails method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.teacher_activity_view_subject_datails);
    try {
        subject = new SubjectServiceImpl().getSubjectById(getIntent().getExtras().getLong("subjectId"));
    } catch (SubjectException e) {
        e.printStackTrace();
    }
    textViewMidtermPercent = (TextView) findViewById(R.id.midterm_percent_sub_view);
    textViewMidtermPercent = (TextView) findViewById(R.id.finals_percent_sub_view);
    recyclerViewMidterm = (RecyclerView) findViewById(R.id.midterm_recycleview);
    recyclerViewFinals = (RecyclerView) findViewById(R.id.finals_recycleview);
    linearLayoutm = (LinearLayout) findViewById(R.id.midterm_setting);
    linearLayoutf = (LinearLayout) findViewById(R.id.finals_setting);
    name = (TextView) findViewById(R.id.a_class_f_view_subject_name);
    code = (TextView) findViewById(R.id.a_class_f_view_subject_code);
    desc = (TextView) findViewById(R.id.a_class_f_view_subject_desc);
    unit = (TextView) findViewById(R.id.a_class_f_view_subject_unit);
    toggleButtonM = (ToggleButton) findViewById(R.id.toggle_midview);
    toggleButtonF = (ToggleButton) findViewById(R.id.toggle_finview);
    recyclerViewMidterm.setVisibility(View.GONE);
    recyclerViewFinals.setVisibility(View.GONE);
    toggleButtonM.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                recyclerViewMidterm.setVisibility(View.VISIBLE);
            } else {
                recyclerViewMidterm.setVisibility(View.GONE);
            }
        }
    });
    toggleButtonF.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                recyclerViewFinals.setVisibility(View.VISIBLE);
            } else {
                recyclerViewFinals.setVisibility(View.GONE);
            }
        }
    });
    name.setText(subject.getName());
    code.setText(subject.getCode());
    desc.setText(subject.getDescription());
    unit.setText(subject.getUnit() + "");
    try {
        Formula formula = new FormulaHelper(this).getFormula("1-midterm");
        if (formula != null && formula.getSubject() != null) {
            if (formula.getSubject().getId() == subject.getId()) {
                recyclerViewMidterm.setVisibility(View.VISIBLE);
                String[] key = new String[6];
                key[0] = formula.getActivityPercentage() + "%";
                key[1] = formula.getAssignmentPercentage() + "%";
                key[2] = formula.getAttendancePercentage() + "%";
                key[3] = formula.getExamPercentage() + "%";
                key[4] = formula.getProjectPercentage() + "%";
                key[5] = formula.getQuizPercentage() + "%";
                List<String> datas = new ArrayList<>();
                for (String s : key) datas.add(s);
                CriteriaAdapter criteriaAdapter = new CriteriaAdapter(this, datas);
                LinearLayoutManager layoutManager = new LinearLayoutManager(this);
                layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
                recyclerViewMidterm.setAdapter(criteriaAdapter);
                recyclerViewMidterm.setLayoutManager(layoutManager);
                recyclerViewMidterm.setItemAnimator(new DefaultItemAnimator());
            }
        }
    } catch (GradingFactorException e) {
        e.printStackTrace();
    }
    linearLayoutm.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            Intent intent = new Intent(Teacher_Activity_View_Subject_Datails.this, Teacher_GradingFactor_Activity_Midterm.class);
            intent.putExtra("subjectId", subject.getId());
            startActivity(intent);
            finish();
        }
    });
    linearLayoutf.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            Intent intent = new Intent(Teacher_Activity_View_Subject_Datails.this, Teacher_GradingFactor_Activity_Finals.class);
            startActivity(intent);
            finish();
        }
    });
}
Also used : GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) ArrayList(java.util.ArrayList) SubjectException(com.remswork.project.alice.exception.SubjectException) Intent(android.content.Intent) FormulaHelper(com.lieverandiver.thesisproject.helper.FormulaHelper) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) Formula(com.remswork.project.alice.model.Formula) CriteriaAdapter(com.lieverandiver.thesisproject.adapter.CriteriaAdapter) SubjectServiceImpl(com.remswork.project.alice.service.impl.SubjectServiceImpl) CompoundButton(android.widget.CompoundButton)

Example 18 with SubjectException

use of com.remswork.project.alice.exception.SubjectException in project classify-system by anverliedoit.

the class SubjectController method addSubject.

@RequestMapping(value = "add", method = RequestMethod.POST)
public String addSubject(@RequestParam("name") String name, @RequestParam("code") String code, @RequestParam("description") String description, @RequestParam("unit") int unit, ModelMap modelMap) {
    try {
        Subject subject = new Subject(name, code, description, unit);
        subjectService.addSubject(subject);
        List<Subject> subjectList = subjectService.getSubjectList();
        modelMap.put("subjectList", subjectList);
        return "subject";
    } catch (SubjectException e) {
        e.printStackTrace();
        return "error";
    }
}
Also used : SubjectException(com.remswork.project.alice.exception.SubjectException) Subject(com.remswork.project.alice.model.Subject) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 19 with SubjectException

use of com.remswork.project.alice.exception.SubjectException in project classify-system by anverliedoit.

the class SubjectServiceImpl method deleteSubjectById.

@Override
public Subject deleteSubjectById(long id) throws SubjectException {
    try {
        StringBuilder uri = new StringBuilder();
        uri.append(targetProperties.getDomain());
        uri.append("/");
        uri.append(targetProperties.getBaseUri());
        uri.append("/");
        uri.append(payload);
        uri.append("/");
        uri.append(id);
        Client client = ClientBuilder.newClient();
        WebTarget target = client.target(uri.toString());
        Builder builder = target.request();
        builder.accept("application/json");
        Response response = builder.delete();
        if (response.getStatus() == 200) {
            return (Subject) response.readEntity(Subject.class);
        } else if (response.getStatus() == 400) {
            Message message = (Message) response.readEntity(Message.class);
            throw new SubjectServiceException(message.getMessage());
        } else
            throw new SubjectServiceException("The request might invalid or server is down");
    } catch (SubjectServiceException e) {
        throw new SubjectException(e.getMessage());
    }
}
Also used : Response(javax.ws.rs.core.Response) Message(com.remswork.project.alice.model.support.Message) ClientBuilder(javax.ws.rs.client.ClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) SubjectException(com.remswork.project.alice.exception.SubjectException) WebTarget(javax.ws.rs.client.WebTarget) SubjectServiceException(com.remswork.project.alice.web.service.exception.SubjectServiceException) Client(javax.ws.rs.client.Client) Subject(com.remswork.project.alice.model.Subject)

Example 20 with SubjectException

use of com.remswork.project.alice.exception.SubjectException in project classify-system by anverliedoit.

the class SubjectServiceImpl method getSubjectByScheduleId.

@Override
public Subject getSubjectByScheduleId(long scheduleId) throws SubjectException {
    try {
        StringBuilder uri = new StringBuilder();
        uri.append(targetProperties.getDomain());
        uri.append("/");
        uri.append(targetProperties.getBaseUri());
        uri.append("/");
        uri.append(payload);
        Client client = ClientBuilder.newClient();
        WebTarget target = client.target(uri.toString());
        Response response = target.queryParam("scheduleId", scheduleId).request().get();
        if (response.getStatus() == 200) {
            return (Subject) response.readEntity(Subject.class);
        } else if (response.getStatus() == 404) {
            Message message = (Message) response.readEntity(Message.class);
            throw new SubjectServiceException(message.getMessage());
        } else
            throw new SubjectServiceException("The request might invalid or server is down");
    } catch (SubjectServiceException e) {
        throw new SubjectException(e.getMessage());
    }
}
Also used : Response(javax.ws.rs.core.Response) Message(com.remswork.project.alice.model.support.Message) SubjectException(com.remswork.project.alice.exception.SubjectException) WebTarget(javax.ws.rs.client.WebTarget) SubjectServiceException(com.remswork.project.alice.web.service.exception.SubjectServiceException) Client(javax.ws.rs.client.Client) Subject(com.remswork.project.alice.model.Subject)

Aggregations

SubjectException (com.remswork.project.alice.exception.SubjectException)44 Message (com.remswork.project.alice.model.support.Message)27 Subject (com.remswork.project.alice.model.Subject)23 AsyncTask (android.os.AsyncTask)10 Gson (com.google.gson.Gson)10 SubjectDaoException (com.remswork.project.alice.dao.exception.SubjectDaoException)10 IOException (java.io.IOException)10 InputStream (java.io.InputStream)10 HttpURLConnection (java.net.HttpURLConnection)10 URL (java.net.URL)10 ArrayList (java.util.ArrayList)10 ExecutionException (java.util.concurrent.ExecutionException)10 Session (org.hibernate.Session)10 SubjectServiceException (com.remswork.project.alice.web.service.exception.SubjectServiceException)9 Client (javax.ws.rs.client.Client)9 WebTarget (javax.ws.rs.client.WebTarget)9 Response (javax.ws.rs.core.Response)9 SubjectResourceLinks (com.remswork.project.alice.resource.links.SubjectResourceLinks)8 Query (org.hibernate.Query)7 List (java.util.List)6