public String getServletInfo() {
return "Chellow electricity billing and reporting.";
}
protected void checkPermissions(Invocation inv) throws HttpException {
HttpMethod method = inv.getMethod();
String pathInfo = inv.getRequest().getPathInfo();
if (method.equals(HttpMethod.GET)
&& (pathInfo.equals("/") || pathInfo.startsWith("/style/"))) {
return;
}
User user = inv.getUser();
if (user == null) {
user = ImplicitUserSource.getUser(inv);
}
if (user == null) {
try {
Long userCount = (Long) Hiber.session()
.createQuery("select count(*) from User user")
.uniqueResult();
if (userCount == null
|| userCount == 0
&& InetAddress.getByName(
inv.getRequest().getRemoteAddr())
.isLoopbackAddress()) {
return;
}
} catch (UnknownHostException e) {
throw new InternalException(e);
}
throw new UnauthorizedException();
}
UserRole role = user.getRole();
String roleCode = role.getCode();
if (roleCode.equals(UserRole.VIEWER)) {
if (pathInfo.startsWith("/reports/")
&& pathInfo.endsWith("/output/")
&& (method.equals(HttpMethod.GET) || method
.equals(HttpMethod.HEAD))) {
return;
}
} else if (roleCode.equals(UserRole.EDITOR)) {
return;
} else if (roleCode.equals(UserRole.PARTY_VIEWER)) {
if (method.equals(HttpMethod.GET) || method.equals(HttpMethod.HEAD)) {
Party party = user.getParty();
char marketRoleCode = party.getRole().getCode();
if (marketRoleCode == MarketRole.HHDC) {
Long hhdcContractId = inv.getLong("hhdc-contract-id");
if (!inv.isValid()) {