|
|
@ -58,16 +58,17 @@ import javax.ws.rs.Produces;
|
|
|
|
import javax.ws.rs.core.Context;
|
|
|
|
import javax.ws.rs.core.Context;
|
|
|
|
import javax.ws.rs.core.MediaType;
|
|
|
|
import javax.ws.rs.core.MediaType;
|
|
|
|
import javax.ws.rs.core.Response;
|
|
|
|
import javax.ws.rs.core.Response;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.Calendar;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@API(name = "doormanager", version = "1.0.0", context = "/doormanager")
|
|
|
|
@API(name = "doormanager", version = "1.0.0", context = "/doormanager")
|
|
|
|
@DeviceType(value = "doormanager")
|
|
|
|
@DeviceType(value = "doormanager")
|
|
|
|
public class DoorManagerControllerService {
|
|
|
|
public class DoorManagerControllerService {
|
|
|
|
|
|
|
|
|
|
|
|
private static final DoorManagerDAO DOOR_MANAGER_DAO = new DoorManagerDAO();
|
|
|
|
private static final DoorManagerDAO DOOR_MANAGER_DAO = new DoorManagerDAO();
|
|
|
|
@Context //injected response proxy supporting multiple thread
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static Log log = LogFactory.getLog(DoorManagerControllerService.class);
|
|
|
|
private static Log log = LogFactory.getLog(DoorManagerControllerService.class);
|
|
|
|
private HttpServletResponse response;
|
|
|
|
private HttpServletResponse response;
|
|
|
@ -76,6 +77,8 @@ public class DoorManagerControllerService {
|
|
|
|
|
|
|
|
|
|
|
|
private PrivilegedCarbonContext ctx;
|
|
|
|
private PrivilegedCarbonContext ctx;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Context //injected response proxy supporting multiple thread
|
|
|
|
|
|
|
|
|
|
|
|
private UserStoreManager getUserStoreManager() throws UserStoreException {
|
|
|
|
private UserStoreManager getUserStoreManager() throws UserStoreException {
|
|
|
|
String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
|
|
|
|
String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
|
|
|
|
PrivilegedCarbonContext.startTenantFlow();
|
|
|
|
PrivilegedCarbonContext.startTenantFlow();
|
|
|
@ -144,7 +147,7 @@ public class DoorManagerControllerService {
|
|
|
|
@FormParam("policy") String policy,
|
|
|
|
@FormParam("policy") String policy,
|
|
|
|
@FormParam("cardNumber") String cardNumber,
|
|
|
|
@FormParam("cardNumber") String cardNumber,
|
|
|
|
@FormParam("userName") String userName,
|
|
|
|
@FormParam("userName") String userName,
|
|
|
|
@Context HttpServletResponse response){
|
|
|
|
@Context HttpServletResponse response) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (userName != null && cardNumber != null && deviceId != null) {
|
|
|
|
if (userName != null && cardNumber != null && deviceId != null) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -163,6 +166,7 @@ public class DoorManagerControllerService {
|
|
|
|
claims.put("http://wso2.org/claims/lock/cardnumber", cardNumber);
|
|
|
|
claims.put("http://wso2.org/claims/lock/cardnumber", cardNumber);
|
|
|
|
userStoreManager.setUserClaimValues(userName, claims, null);
|
|
|
|
userStoreManager.setUserClaimValues(userName, claims, null);
|
|
|
|
//TODO: Add content to dto
|
|
|
|
//TODO: Add content to dto
|
|
|
|
|
|
|
|
response.setStatus(Response.Status.OK.getStatusCode());
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
response.setStatus(Response.Status.NOT_FOUND.getStatusCode());
|
|
|
|
response.setStatus(Response.Status.NOT_FOUND.getStatusCode());
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -170,8 +174,7 @@ public class DoorManagerControllerService {
|
|
|
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
log.error(e);
|
|
|
|
log.error(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
else {
|
|
|
|
|
|
|
|
response.setStatus(Response.Status.BAD_REQUEST.getStatusCode());
|
|
|
|
response.setStatus(Response.Status.BAD_REQUEST.getStatusCode());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -326,14 +329,14 @@ public class DoorManagerControllerService {
|
|
|
|
@Context HttpServletResponse response) {
|
|
|
|
@Context HttpServletResponse response) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
int lockerCurrentState;
|
|
|
|
int lockerCurrentState;
|
|
|
|
if(state.toUpperCase().equals("LOCK")){
|
|
|
|
if (state.toUpperCase().equals("LOCK")) {
|
|
|
|
lockerCurrentState = 0;
|
|
|
|
lockerCurrentState = 0;
|
|
|
|
}else{
|
|
|
|
} else {
|
|
|
|
lockerCurrentState = 1;
|
|
|
|
lockerCurrentState = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SensorDataManager.getInstance().setSensorRecord(deviceId, "door_locker_state",
|
|
|
|
SensorDataManager.getInstance().setSensorRecord(deviceId, "door_locker_state",
|
|
|
|
String.valueOf(lockerCurrentState), Calendar.getInstance().getTimeInMillis());
|
|
|
|
String.valueOf(lockerCurrentState), Calendar.getInstance().getTimeInMillis());
|
|
|
|
doorManagerMQTTConnector.sendCommandViaMQTT(owner, deviceId,"DoorManager:", state.toUpperCase());
|
|
|
|
doorManagerMQTTConnector.sendCommandViaMQTT(owner, deviceId, "DoorManager:", state.toUpperCase());
|
|
|
|
response.setStatus(Response.Status.OK.getStatusCode());
|
|
|
|
response.setStatus(Response.Status.OK.getStatusCode());
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
log.error(e);
|
|
|
|
log.error(e);
|
|
|
|