use of com.remswork.project.alice.exception.SubjectException in project classify-system by anverliedoit.
the class SubjectServiceImpl method updateSubjectById.
@Override
public Subject updateSubjectById(final long id, final Subject newSubject) throws SubjectException {
try {
return new AsyncTask<String, Subject, Subject>() {
@Override
protected Subject doInBackground(String... args) {
try {
String link = "".concat(domain).concat("/").concat(baseUri).concat("/").concat(payload).concat("/").concat(String.valueOf(id)).concat("?departmentId=");
Gson gson = new Gson();
URL url = new URL(link);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestMethod("PUT");
httpURLConnection.setRequestProperty("Content-Type", "application/json");
httpURLConnection.setRequestProperty("Accept", "application/json");
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true);
OutputStream os = httpURLConnection.getOutputStream();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
writer.write(gson.toJson(newSubject));
writer.flush();
writer.close();
httpURLConnection.connect();
if (httpURLConnection.getResponseCode() == 200) {
InputStream inputStream = httpURLConnection.getInputStream();
String jsonData = "";
int data;
while ((data = inputStream.read()) != -1) {
jsonData += (char) data;
}
return gson.fromJson(jsonData, Subject.class);
} else if (httpURLConnection.getResponseCode() == 400) {
InputStream inputStream = httpURLConnection.getInputStream();
String jsonData = "";
int data;
while ((data = inputStream.read()) != -1) {
jsonData += (char) data;
}
Message message = gson.fromJson(jsonData, Message.class);
Log.i("ServiceTAG", "Service : Subject");
Log.i("ServiceTAG", "Status : " + message.getStatus());
Log.i("ServiceTAG", "Type : " + message.getType());
Log.i("ServiceTAG", "Message : " + message.getMessage());
return null;
} else
throw new SubjectException("Server Error");
} catch (SubjectException e) {
e.printStackTrace();
return null;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
}.execute((String) null).get();
} catch (InterruptedException e) {
e.printStackTrace();
return null;
} catch (ExecutionException e) {
e.printStackTrace();
return null;
}
}
use of com.remswork.project.alice.exception.SubjectException in project classify-system by anverliedoit.
the class SubjectServiceImpl method getSubjectList.
@Override
public List<Subject> getSubjectList() throws SubjectException {
final List<Subject> subjectList = new ArrayList<>();
try {
return new AsyncTask<String, List<Subject>, List<Subject>>() {
@Override
protected List<Subject> doInBackground(String... args) {
try {
String link = "".concat(domain).concat("/").concat(baseUri).concat("/").concat(payload);
URL url = new URL(link);
Gson gson = new Gson();
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestMethod("GET");
httpURLConnection.setRequestProperty("Content-Type", "application/json");
httpURLConnection.setRequestProperty("Accept", "application/json");
httpURLConnection.connect();
if (httpURLConnection.getResponseCode() == 200) {
InputStream inputStream = httpURLConnection.getInputStream();
String jsonData = "";
int data;
while ((data = inputStream.read()) != -1) {
jsonData += (char) data;
}
JSONArray jsonArray = new JSONArray(jsonData);
for (int ctr = 0; ctr < jsonArray.length(); ctr++) {
subjectList.add(gson.fromJson(jsonArray.get(ctr).toString(), Subject.class));
}
return subjectList;
} else if (httpURLConnection.getResponseCode() == 404) {
InputStream inputStream = httpURLConnection.getInputStream();
String jsonData = "";
int data;
while ((data = inputStream.read()) != -1) {
jsonData += (char) data;
}
Message message = gson.fromJson(jsonData, Message.class);
Log.i("ServiceTAG", "Service : Subject");
Log.i("ServiceTAG", "Status : " + message.getStatus());
Log.i("ServiceTAG", "Type : " + message.getType());
Log.i("ServiceTAG", "Message : " + message.getMessage());
return subjectList;
} else
throw new SubjectException("Server Error");
} catch (SubjectException e) {
e.printStackTrace();
return null;
} catch (IOException e) {
e.printStackTrace();
return null;
} catch (JSONException e) {
e.printStackTrace();
return null;
}
}
}.execute((String) null).get();
} catch (InterruptedException e) {
e.printStackTrace();
return null;
} catch (ExecutionException e) {
e.printStackTrace();
return null;
}
}
use of com.remswork.project.alice.exception.SubjectException in project classify-system by anverliedoit.
the class SubjectServiceImpl method getSubjectListByStudentId.
@Override
public List<Subject> getSubjectListByStudentId(final long studentId) throws SubjectException {
final List<Subject> subjectList = new ArrayList<>();
try {
return new AsyncTask<String, List<Subject>, List<Subject>>() {
@Override
protected List<Subject> doInBackground(String... args) {
try {
String link = "".concat(domain).concat("/").concat(baseUri).concat("/").concat(payload).concat("/").concat("1").concat("?studentId=").concat(String.valueOf(studentId));
URL url = new URL(link);
Gson gson = new Gson();
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestMethod("GET");
httpURLConnection.setRequestProperty("Content-Type", "application/json");
httpURLConnection.setRequestProperty("Accept", "application/json");
httpURLConnection.connect();
if (httpURLConnection.getResponseCode() == 200) {
InputStream inputStream = httpURLConnection.getInputStream();
String jsonData = "";
int data;
while ((data = inputStream.read()) != -1) {
jsonData += (char) data;
}
JSONArray jsonArray = new JSONArray(jsonData);
for (int ctr = 0; ctr < jsonArray.length(); ctr++) {
subjectList.add(gson.fromJson(jsonArray.get(ctr).toString(), Subject.class));
}
return subjectList;
} else if (httpURLConnection.getResponseCode() == 404) {
InputStream inputStream = httpURLConnection.getInputStream();
String jsonData = "";
int data;
while ((data = inputStream.read()) != -1) {
jsonData += (char) data;
}
Message message = gson.fromJson(jsonData, Message.class);
Log.i("ServiceTAG", "Service : Subject");
Log.i("ServiceTAG", "Status : " + message.getStatus());
Log.i("ServiceTAG", "Type : " + message.getType());
Log.i("ServiceTAG", "Message : " + message.getMessage());
return subjectList;
} else
throw new SubjectException("Server Error");
} catch (SubjectException e) {
e.printStackTrace();
return null;
} catch (IOException e) {
e.printStackTrace();
return null;
} catch (JSONException e) {
e.printStackTrace();
return null;
}
}
}.execute((String) null).get();
} catch (InterruptedException e) {
e.printStackTrace();
return null;
} catch (ExecutionException e) {
e.printStackTrace();
return null;
}
}
use of com.remswork.project.alice.exception.SubjectException in project classify-system by anverliedoit.
the class SubjectViewActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.teacher_activity_view_subject_datails);
try {
intent = getIntent();
long subjectId = intent.getExtras().getLong("subjectId");
subject = subjectService.getSubjectById(subjectId);
teacher = new TeacherHelper(this).loadUser().get();
new Thread(new Runnable() {
@Override
public void run() {
init();
}
}).start();
} catch (SubjectException e) {
e.printStackTrace();
}
}
use of com.remswork.project.alice.exception.SubjectException in project classify-system by anverliedoit.
the class TeacherViewActivity method init.
private void init() {
txtName = (TextView) findViewById(R.id.txtv_fullname);
txtDept = (TextView) findViewById(R.id.txtv_dept);
btnBack = (Button) findViewById(R.id.add_backsubject);
rView = (RecyclerView) findViewById(R.id.recyclerview_view_subject);
try {
SubjectAdapter subjectAdapter = new SubjectAdapter(this, subjectService.getSubjectListByTeacherIdUnique(teacher.getId()));
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
rView.setAdapter(subjectAdapter);
rView.setLayoutManager(layoutManager);
rView.setItemAnimator(new DefaultItemAnimator());
txtName.setText(teacher.getFirstName() + " " + teacher.getMiddleName().substring(0, 1) + ". " + teacher.getLastName());
txtDept.setText(teacher.getDepartment() != null ? teacher.getDepartment().getName() : "None");
btnBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
finish();
}
});
} catch (SubjectException e) {
e.printStackTrace();
}
}
Aggregations