Struts 2 Custom Validator issue - struts2

I have an Action for CRUD operations and 3 custom validators.
Two of the validators work correctly, but the other one does not. It handles correctly the validation, and returns the appropriate errors, but if there are no errors, the workflow does not complete, it never reaches the Action. It is as if it is stuck in the validator. There are no errors in the log file. If I remove the validator, the Action is reached.
I am not sure what I am doing wrong, and I would appreciate any help.

package com.timesheet.validator;
import java.util.Map;
import com.timesheet.action.TimeSheetAction;
import com.timesheet.util.TimeSheetClient;
import com.timesheet.util.TimeSheetHolder;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.validator.ValidationException;
import com.opensymphony.xwork2.validator.validators.ValidatorSupport;
public class TimeSheetSubmission extends ValidatorSupport{
#Override
public void validate(Object arg0) throws ValidationException {
// TODO Auto-generated method stub
Map session = ActionContext.getContext().getSession();
TimeSheetAction act = (TimeSheetAction)ActionContext.getContext().getActionInvocation().getAction();
TimeSheetClient client = act.getClient();
if(session.get("holder") != null){
TimeSheetHolder holder = (TimeSheetHolder)session.get("holder");
if(!(excessTime(holder) && lessTime(holder))){
client.cleanUp();
addActionError(arg0);
return;
}else{
client.cleanUp();
return;
}
}
}
public boolean lessTime(TimeSheetHolder holder){
boolean done = true;
TimeSheetHolder.Day day = holder.dailyHours();
switch(day){
case Mon: setMessageKey("timeSheet.mon.less.hours");
done = false;
break;
case Tue: done = false;
setMessageKey("timeSheet.tue.less.hours");
break;
case Wed: done = false;
setMessageKey("timeSheet.wed.less.hours");
break;
case Thu: done = false;
setMessageKey("timeSheet.thu.less.hours");
break;
case Fri: done = false;
setMessageKey("timeSheet.fri.less.hours");
break;
default: break;
}
return done;
}
public boolean excessTime(TimeSheetHolder holder){
boolean done = true;
TimeSheetHolder.Day day = holder.moreTime();
switch(day){
case Mon: setMessageKey("timeSheet.mon.excess.hours");
done = false;
break;
case Tue: done = false;
setMessageKey("timeSheet.tue.excess.hours");
break;
case Wed: done = false;
setMessageKey("timeSheet.wed.excess.hours");
break;
case Thu: done = false;
setMessageKey("timeSheet.thu.excess.hours");
break;
case Fri: done = false;
setMessageKey("timeSheet.fri.excess.hours");
break;
default: break;
}
return done;
}
}

Related

Parsing serial data from sim900 module esp32

So lately I've been messing around with the idea of making my own cellphone nothing spectacular, just a basic one with touchscreen and basic functions call message calendar contacts list and the ability to connect to the internet and provide weather information via an api call..
The module Im using for gsm and GPRS communications is the popular sim900 module. I can communicate I can make calls I can do everything. But in stuck on a maybe (if not impossible to overcome) difficult roadblock.. You see sim900 module when receives a call transmits through the serial port the "RING" command followed by the "+CLIP.... (caller Id stuff)". OK I'm receiving that and I am breaking it down and accepting the command and all fine it works. But here comes the situation.. I want to read the battery capacity that is left (AT+CBC) and the gsm signal strength (AT+CSQ) all fine I'm sending those 2 commands at a fixed interval of like 3 seconds for the signal 10 for the battery. But now when a call comes it might overlap with the incoming response from trying to read the battery.. Let's say that I asked the module what is the battery level. Then the module will respond by sending "+CBC: (and battery level)" then let's say at the same exact time I receive a call.. Then all the data on the serial port just gets messed up and nothing is working.. My code is pretty rough and definitely the parsing section is awful but I'm more concerned that the parsing is not the problem. And the problem is the conflicting incoming data.. Is there any way of solving this problem? Or any other advice of where to look and how to approach the problem?
Every command from the gsm is delimited by the 0D0A sequence (CRLF)
Bellow is an example code from what i am doing
//for parsing
String incomStr;
String FirstStr;
String SecondStr;
String ThirdStr;
String FourthStr;
String FifthStr;
String SixthStr;
int strcount;
char incomChar;
boolean flagz = false;
//parsing
void getIncomingCommand() {
if (Gsm.available()) {
incomChar = Gsm.read();
//check to see if 0D0A if yes split the string
if ((incomChar == 0x0D) | flagz) {
flagz = true;
if (incomChar == 0x0A) {
switch (strcount) {
case 0:
FirstStr = incomStr;
incomStr = "";
strcount++;
flagz = false;
break;
case 1:
SecondStr = incomStr;
incomStr = "";
strcount++;
flagz = false;
break;
case 2:
ThirdStr = incomStr;
incomStr = "";
strcount++;
flagz = false;
break;
case 3:
FourthStr = incomStr;
incomStr = "";
strcount++;
flagz = false;
break;
case 4:
FifthStr = incomStr;
incomStr = "";
strcount++;
flagz = false;
break;
case 5:
SixthStr = incomStr;
incomStr = "";
strcount++;
flagz = false;
break;
default:
strcount++;
flagz = false;
incomStr = "";
}
}
} else {
incomStr += incomChar;
}
}
}
void clearIncomingCommand() {
FirstStr = "";
SecondStr = "";
ThirdStr = "";
FourthStr = "";
FifthStr = "";
SixthStr = "";
strcount = 0;
}
int getSignalLvl() {
char tempchar;
String tempstr;
Gsm.print("AT+CSQ");
Gsm.write(0x0D);
Gsm.write(0x0A);
delay(180);
while (Gsm.available()) {
tempchar = Gsm.read();
tempstr += tempchar;
}
return tempstr.substring(16, tempstr.indexOf(",")).toInt();
}
String getTime() {
char tempchar;
String tempstr;
Gsm.print("AT+CCLK?");
Gsm.write(0x0D);
Gsm.write(0x0A);
delay(180);
while (Gsm.available()) {
tempchar = Gsm.read();
tempstr += tempchar;
}
return tempstr.substring(tempstr.indexOf(",") + 1, tempstr.lastIndexOf(":"));
}
void setup() {
//start serial port
Serial.begin(115200);
//start the gsm port
Gsm.begin(9600, SERIAL_8N1, 32, 33);
strcount = 0;
updateTime(getTime());
delay(200);
updateSignal(getSignalLvl());
}
void loop() {
//stuff inside here will only be called / run only every X amount of time
// X = SECONDS/1000;
if ((millis() - lastupdate) >= 60000) {
updateTime(getTime());
lastupdate = millis();
}
getIncomingCommand();
if (SecondStr == "RING" & FourthStr.substring(0, 5) == "+CLIP") {
Serial.print("SomeOne is calling!! Number: ");
Serial.println(FourthStr.substring(8, 21));
Serial.println(phoneNums[i]);
Serial.println(FourthStr.substring(8, 21));
callerPhone = FourthStr.substring(8, 21);
clearIncomingCommand();
//important change state only once!
if (!change_state) {
came_from = state ;
change_state = 1;
}
Serial.print("coming from: ");
Serial.println(came_from);
state = 4;
flag = 0;
}
else if (SecondStr == "NO CARRIER") {
Serial.println("CALL ENDED");
clearIncomingCommand();
if (state == 3) {
state = 5;
flag = 0;
} else if (state == 4) {
state = came_from;
flag = 0;
}
change_state = 0;
}
else if (SecondStr == "MO RING") {
Serial.println("CALLING...");
clearIncomingCommand();
}
else if (SecondStr == "MO CONNECTED") {
Serial.println("CALL CONNECTED");
clearIncomingCommand();
if (state == 2) {
state = 3;
flag = 0;
}
} else if (FourthStr == "OK" | ThirdStr == "OK") {
Serial.println("Recieved ok clearing buffers");
clearIncomingCommand();
}
}

Alertify.js notification's callback not fired

I've got some issues making a callback to be invoked. I prefix that I've followed this link but it won't work right now.
What I need to do is that at the notification click a new page is opened. At the current time, even a simple alert is not shown.
My code is the following
switch (obj.Status) {
//case "OK":
// {
// alertify.message(obj.Message, timeout);
// break;
// }
case "KO":
{
alertify.message(obj.Message, timeout);
alertify.callback = function () {
//if(isClicked)
// alert('notification dismissed by user');
//else
alert('notification auto-dismissed');
};
break;
"Warn":
// {
// alertify.warning(obj.Message, timeout);
// break;
// }
}
What am I doing wrong?
Thanks
UPDATE #1
I'm still facing issue passing a value "downstair"
Consider this snippet
chat.client.updateNotifications = function (message) {
var obj = JSON.parse(message);
var guid = obj.RequestId;
var notify = function(level, msg) {
var func;
switch (level) {
case "success":
func = alertify.success;
break;
case "error":
func = alertify.error;
break;
case "warn":
func = alertify.warn;
break;
}
var m = func(msg, timeout);
m.id = guid;
m.callback = function(isClicked) {
if (isClicked) {
var url = '<%=Url.Action("Index","Import",new {id = -1})%>';
url.replace("-1", this.id);
// alert(url);
window.open(url, "target=_blank");
}
}
}
I got null as id, outside the callback it's ok, what am I doing wrong?
Thanks again
In reference to the provided link, the callback is a property of the returned notification object (not alertify)
//this call returns a notification object.
var msg = alertify.message('Open up your web console', 10);
//set the callback on the notification object.
msg.callback = function (isClicked) {
if(isClicked)
console.log('notification dismissed by user');
else
console.log('notification auto-dismissed');
};

How to handle error cases in Biometric authentication for iOS in Xamarin?

if (context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out AuthError)){
var replyHandler = new LAContextReplyHandler((success, error) => {
this.InvokeOnMainThread(()=> {
if(success)
{
Console.WriteLine("You logged in!");
PerformSegue("AuthenticationSegue", this);
}
else
{
// Show fallback mechanism here
}
});
});
context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, myReason, replyHandler);
};
I want to handle the error cases in the else condition based on the type of error.
You can obtain the failure code from the NSError returned and process it against the LAStatus codes:
switch (error.Code)
{
case (long)LAStatus.AuthenticationFailed:
~~~
break;
case (long)LAStatus.UserCancel:
~~~
break;
~~~
default:
break;
}
LAStatus (with the deprecations stripped out):
public enum LAStatus : long
{
Success,
AuthenticationFailed = -1L,
UserCancel = -2L,
UserFallback = -3L,
SystemCancel = -4L,
PasscodeNotSet = -5L,
AppCancel = -9L,
InvalidContext = -10L,
BiometryNotAvailable = -6L,
BiometryNotEnrolled = -7L,
BiometryLockout = -8L,
NotInteractive = -1004L
}
For descriptions of the various codes, you can use LAError.Code:
https://developer.apple.com/documentation/localauthentication/laerror.code

How to create custom field in Jira which can do a multiplication of two other ones?

I need to create a field which can do a multiplication of severity and priority. I've found how to create a field, I know I must add a script to Description section. But the problem is that I can't figure out how to get these two fields for the operation. Probably it should be something like this:
<!-- ##Formula:
return (issue.getSeverity() * issue.getPriority())
-->
You can use the free plugin Jira Misc Custom Fields that provides a field named "Calculated Number Field".
If you need more complex operations you can try the powerful Jira Script Runner plugin and use the Scripted field: by using the Groovy language you can create even the most complex calculations.
Here I have two fields, one custom, and one system. So it looks like this:
<!-- ##Formula:
int severityValue = 0;
int priorityValue = 0;
if(issue.get("priority").getName() == null) return 0;
if(issue.get("customfield_12006") == null) return 0;
String severity = issue.get("customfield_12006");
String priority = issue.get("priority").getName();
switch(severity) {
case "S1": {
severityValue = 5;
break;
}
case "S2": {
severityValue = 4;
break;
}
case "S3": {
severityValue = 3;
break;
}
case "S4": {
severityValue = 2;
break;
}
case "S5": {
severityValue = 1;
break;
}
}
switch(priority) {
case "Blocker": {
priorityValue = 5;
break;
}
case "Critical": {
priorityValue = 4;
break;
}
case "Major": {
priorityValue = 3;
break;
}
case "Minor": {
priorityValue = 2;
break;
}
case "Trivial": {
priorityValue = 1;
break;
}
}
return (severityValue * priorityValue)
-->
You can get issue id this way: "https://base_jira_url/rest/api/2/field".

IOS Photon Cloud SDK getRoomList function doesn't work

I am developing cocos2d-x game which have online game mode.
Online game designed and implemented by Photon Cloud SDK(http://www.exitgames.com).
I implemented only ios version but it doesn't work.
The codes that I have implemented are blow.
void NetworkLogic::opJoinRandomRoom()
{
ExitGames::Common::JVector<ExitGames::LoadBalancing::Room> roomList;
roomList = mLoadBalancingClient.getRoomList();
int count = roomList.getSize();
CCLog("Room Count = %d", count);
if(count == 0)
{
this->opCreateRoom();
}else{
mLoadBalancingClient.opJoinRandomRoom();
}
}
void NetworkLogic::update(float dt)
{
this->run();
}
void NetworkLogic::run(void)
{
if(mLastInput == INPUT_EXIT && mStateAccessor.getState() != STATE_DISCONNECTING && mStateAccessor.getState() != STATE_DISCONNECTED)
{
disconnect();
mStateAccessor.setState(STATE_DISCONNECTING);
}
else
{
State state = mStateAccessor.getState();
switch(state)
{
case STATE_INITIALIZED:
connect();
mStateAccessor.setState(STATE_CONNECTING);
break;
case STATE_CONNECTING:
break; // wait for callback
case STATE_CONNECTED:
{
ExitGames::Common::JVector<ExitGames::LoadBalancing::Room> roomList;
roomList = mLoadBalancingClient.getRoomList();
int count = roomList.getSize();
ExitGames::Common::JString tmp;
tmp = count;
EGLOG(ExitGames::Common::DebugLevel::INFO, tmp);
CCLog("Room count in Room = %d", count);
switch(mLastInput)
{
case INPUT_CREATE_GAME: // create Game
opCreateRoom();
break;
case INPUT_JOIN_RANDOM_GAME: // join Game
opJoinRandomRoom();
mStateAccessor.setState(STATE_JOINING);
break;
default: // no or illegal input -> stay waiting for legal input
break;
}
break;
}
case STATE_JOINING:
break; // wait for callback
case STATE_JOINED:
switch(mLastInput)
{
case INPUT_LEAVE_GAME: // leave Game
mLoadBalancingClient.opLeaveRoom();
mStateAccessor.setState(STATE_LEAVING);
break;
default: // no or illegal input -> stay waiting for legal input
break;
}
break;
case STATE_LEAVING:
break; // wait for callback
case STATE_LEFT:
mStateAccessor.setState(STATE_CONNECTED);
break;
case STATE_DISCONNECTING:
break; // wait for callback
default:
break;
}
}
mLastInput = INPUT_NON;
mLoadBalancingClient.service();
}
First I run one app then getRoomList function returns 0 values.
Also after first room created and run second app but it also returns getRoomList function 0.
Please help me.
I have just taken the code that you have provided in your question and copied it into the according place inside the demo of an otherwise unchanged version 3.2.2.0 build of the Photon C++ Client SDK (and removed the two CCLog() lines to make it compile without cocos2d-x) and it worked just fine for me:
The demo prints 0 for the size of the room list until I let one client create a room. Afterwards the other client prints 1.

Resources