use of com.remswork.project.alice.web.service.exception.SectionServiceException in project classify-system by anverliedoit.
the class SectionServiceImpl method deleteSectionById.
@Override
public Section deleteSectionById(long id) throws SectionException {
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 (Section) response.readEntity(Section.class);
} else if (response.getStatus() == 400) {
Message message = (Message) response.readEntity(Message.class);
throw new SectionServiceException(message.getMessage());
} else
throw new SectionServiceException("The request might invalid or server is down");
} catch (SectionServiceException e) {
throw new SectionException(e.getMessage());
}
}
use of com.remswork.project.alice.web.service.exception.SectionServiceException in project classify-system by anverliedoit.
the class SectionServiceImpl method getSectionList.
@Override
public List<Section> getSectionList() throws SectionException {
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.request().get();
if (response.getStatus() == 200) {
return (List<Section>) response.readEntity(new GenericType<List<Section>>() {
});
} else if (response.getStatus() == 404) {
Message message = (Message) response.readEntity(Message.class);
throw new SectionServiceException(message.getMessage());
} else
throw new SectionServiceException("The request might invalid or server is down");
} catch (SectionServiceException e) {
throw new SectionException(e.getMessage());
}
}
use of com.remswork.project.alice.web.service.exception.SectionServiceException in project classify-system by anverliedoit.
the class SectionServiceImpl method updateSectionById.
@Override
public Section updateSectionById(long id, Section newSection, long departmentId) throws SectionException {
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.queryParam("departmentId", departmentId).request();
builder.accept("application/json");
Response response = builder.put(Entity.json(newSection));
if (response.getStatus() == 200) {
return (Section) response.readEntity(Section.class);
} else if (response.getStatus() == 400) {
Message message = (Message) response.readEntity(Message.class);
throw new SectionServiceException(message.getMessage());
} else
throw new SectionServiceException("The request might invalid or server is down");
} catch (SectionServiceException e) {
throw new SectionException(e.getMessage());
}
}
use of com.remswork.project.alice.web.service.exception.SectionServiceException in project classify-system by anverliedoit.
the class SectionServiceImpl method addSection.
@Override
public Section addSection(Section Section, long departmentId) throws SectionException {
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());
Builder builder = target.queryParam("departmentId", departmentId).request();
builder.accept("application/json");
Response response = builder.post(Entity.json(Section));
if (response.getStatus() == 201) {
return (Section) response.readEntity(Section.class);
} else if (response.getStatus() == 400) {
Message message = (Message) response.readEntity(Message.class);
throw new SectionServiceException(message.getMessage());
} else
throw new SectionServiceException("The request might invalid or server is down");
} catch (SectionServiceException e) {
throw new SectionException(e.getMessage());
}
}
use of com.remswork.project.alice.web.service.exception.SectionServiceException in project classify-system by anverliedoit.
the class SectionServiceImpl method getSectionById.
@Override
public Section getSectionById(long id) throws SectionException {
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());
Response response = target.request().get();
if (response.getStatus() == 200) {
return (Section) response.readEntity(Section.class);
} else if (response.getStatus() == 404) {
Message message = (Message) response.readEntity(Message.class);
throw new SectionServiceException(message.getMessage());
} else
throw new SectionServiceException("The request might invalid or server is down");
} catch (SectionServiceException e) {
throw new SectionException(e.getMessage());
}
}
Aggregations