I have when statement that goes from an if statement to the else statement:
rule "rule"
ruleflow-group "ruleFlow"
when
$block : Block()
$inst : BlockInstitution(blockInstitutionCategory!=null) from $block.getInstitution()
$categorycode : InstitutionCategory(Constants.INSTITUTION_CATEGORY_CODE.equals(institutionCategoryCode)) from $inst.getInstitutionCategory()
$list : BlockInstitution(Constants.validNonList not contains dealCode) from $block.getInstitution()
then
Service $service = new Service();
try {
JsonObject enquiry =
$service.execute($block.getTransaction().getNumber()).get();
if (enquiry.isEmpty()) {
$block.getBusinessValidationResult().add(ValidationResult.NOT_FOUND);
$block.getMsg().setStatusText(Constants.NOT_FOUND);
}
else {
String numberFromService = statusEnquiry.getString(Constants.NUMBER);
String cardExpiryFromService =
enquiry.getString(Constants.EXPIRY_DATE);
String paymentRequestorIdentifier =
enquiry.getString(Constants.IDENTIFIER);
String paymentExpiryDate = enquiry.getString(Constants.EXPIRY_DATE);
String statusText = enquiry.getString(Constants.STATUS_TEXT);
String providerIdentifier =
enquiry.getString(Constants.PROVIDER_IDENTIFIER);
if (Objects.nonNull(paymentExpiryDate)) {
paymentExpiryDate =
EncryptionUtilFactory.getInstance().decryptData(paymentExpiryDate);
if (paymentExpiryDate.length() == 4) {
paymentExpiryDate =
paymentExpiryDate.substring(2, 4) + paymentExpiryDate.substring(0, 2);
}
paymentExpiryDate =
EncryptionUtilFactory.getInstance().encryptData(paymentExpiryDate);
}
if (Objects.nonNull(cardExpiryFromService)) {
cardExpiryFromService =
EncryptionUtilFactory.getInstance().decryptData(cardExpiryFromService);
if (cardExpiryFromService.length() == 4) {
cardExpiryFromService =
cardExpiryFromService.substring(2, 4) + cardExpiryFromService.substring(0, 2);
}
cardExpiryFromService =
EncryptionUtilFactory.getInstance().encryptData(cardExpiryFromService);
}
$block.getTransaction().setServiceNumber(numberFromService);
$block.getTransaction().setServiceAccountExpirationDate(cardExpiryFromService);
$block.getTransaction().setPaymentExpiryDate(paymentExpiryDate);
$block
.getTransaction()
.setFlag(Constants.ID_SET.contains(providerIdentifier));
$block.getTransaction().setProviderIdentifier(providerIdentifier);
String text = $block.getTransaction().getPrimaryAccountNumber();
$block.getTransaction().setText(text);
$block.getTransaction().setStatusText(statusText);
$block
.getTransaction()
.setPaymentRequestorIdentifier(paymentRequestorIdentifier);
if (!Constants.STATUS.equals(statusText)) {
switch (statusText) {
case Constants.INACTIVE_STATUS:
$block.getBusinessValidationResult().add(ValidationResult.INACTIVE);
break;
case Constants.CANCELLED_STATUS:
$block.getBusinessValidationResult().add(ValidationResult.CANCELLED);
break;
case Constants.SUSPENDED_STATUS:
$block.getBusinessValidationResult().add(ValidationResult.SUSPENDED);
break;
default:
break;
}
}
}
} catch (Exception ex) {
$block.getBusinessValidationResult().add(ValidationResult.CALL_FAILED);
$block.getTransaction().setStatusText(Constants.NOT_FOUND);
}
end
ERROR:
[Error: unterminated collection element]
[Near : {... _FOUND); } else { String numberFr ....}]
As the code goes from the if block to the else block it gives me an error: "Unterminated Collection Element".
Is there anything you see that indicates what's wrong. I can't find anything on the Internet that discusses this error. I've found "Unterminated String Element", but nothing on collection elements.
Related
I am parsing big xml input data using stax parser.
My input xml part will be like below
<User>
<LoginName>abcd</LoginName>
<FirstName>abcd</FirstName>
<LastName>kkk</LastName>
<CompanyName>infosys</CompanyName>
<EmailAddress>mmm#gmail.com</EmailAddress>
<CorporateEmailAddress></CorporateEmailAddress>
</User>
My stax code is as below
private static Message parseMessage(XMLStreamReader xr)
throws XMLStreamException {
String userName = null;
String content = null;
String email = null;
String comp = null;
while (xr.hasNext()) {
int event = xr.next();
switch (event) {
case XMLStreamConstants.START_ELEMENT: {
String elName = xr.getLocalName();
if (LOGIN_NAME.equals(elName)) {
userName = xr.getElementText();
} else if (CONTENT.equals(elName)) {
content = StringUtils.trimToEmpty(xr.getElementText());
content = content.replace("\n"," ");
} else if (CORP_EMAIL_ADDRESS.equals(elName)) {
email = xr.getElementText();
/*if(email.equals(""))
email ="unknown";*/
conv.emails.add(email);
}
else if (COMPANY_NAME.equals(elName)) {
comp = xr.getElementText();
conv.comps.add(comp);
//System.out.println(comp);
}
break;
}
case XMLStreamConstants.END_ELEMENT: {
String elName = xr.getLocalName();
if (MESSAGE.equals(elName)) {
return new Message(userName, content,email);
}
break;
}
case XMLStreamConstants.END_DOCUMENT:
throw new XMLStreamException("xml not well-formed: <"
+ MESSAGE + "> tag not closed");
}
}
here in code if xr.getElementText(email) is null as doesnot have any value. SO in this case I want to use tag value
So how to assign again xr.elementText to loginvalue? only when cor-email is null
Please help
So my code looks like this:
try {
t.delete("word");
result = t.getRootItem().getWord().equals("humpty");
} catch (Exception e) {
result = false;
}
The problem is my compiler keeps saying I have a catch without a previous try but I do have a previous try so what's wrong? Here's my entire main method (I can also post the entire class if you want:
public static void main(String args[]) {
BSTRefBased t;
AbstractBinaryTree tt;
int i;
boolean result;
String message;
message = "Test 1: inserting 'word0' -- ";
t = new BSTRefBased();
try {
t.insert("word0");
result = t.getRootItem().getWord().equals("word0");
} catch (Exception e) {
result = false;
}
System.out.println(message + (result ? "passed" : "FAILED"));
message = "Test 2: inserting 'word1', 'word2', 'word3' -- ";
t = new BSTRefBased();
try {
t.insert("word1");
t.insert("word2");
t.insert("word3");
result = t.getRootItem().getWord().equals("word1");
tt = t.detachLeftSubtree();
result &= tt.getRootItem().getWord().equals("word2");
tt = t.detachRightSubtree();
result &= tt.getRootItem().getWord().equals("word3");
} catch (Exception e) {
result = false;
}
System.out.println(message + (result ? "passed" : "FAILED"));
message = "Test 3: deleting 'word3'";
t = new BSTRefBased
try {
t.delete("word3");
result = t.getRootItem().getWord().equals("word3");
} catch (Exception e) {
result = false;
}
System.out.println(message + (result ? "passed" : "FAILED"));
}
This line appears to be incorrect:
t = new BSTRefBased
There is no () for a constructor call, and there is no semicolon. It's immediately before the try, and those errors must be messing up the parser, such that it no longer recognizes the try. Try
t = new BSTRefBased(); // or a similar constructor call
here is a piece of code:
class Main {
public static void main(String[] args) {
try {
CLI.parse (args, new String[0]);
InputStream inputStream = args.length == 0 ?
System.in : new java.io.FileInputStream(CLI.infile);
ANTLRInputStream antlrIOS = new ANTLRInputStream(inputStream);
if (CLI.target == CLI.SCAN || CLI.target == CLI.DEFAULT)
{
DecafScanner lexer = new DecafScanner(antlrIOS);
Token token;
boolean done = false;
while (!done)
{
try
{
for (token=lexer.nextToken();
token.getType()!=Token.EOF; token=lexer.nextToken())
{
String type = "";
String text = token.getText();
switch (token.getType())
{
case DecafScanner.ID:
type = " CHARLITERAL";
break;
}
System.out.println (token.getLine() + type + " " + text);
}
done = true;
} catch(Exception e) {
// print the error:
System.out.println(CLI.infile+" "+e);
}
}
}
else if (CLI.target == CLI.PARSE)
{
DecafScanner lexer = new DecafScanner(antlrIOS);
CommonTokenStream tokens = new CommonTokenStream(lexer);
DecafParser parser = new DecafParser (tokens);
parser.program();
}
} catch(Exception e) {
// print the error:
System.out.println(CLI.infile+" "+e);
}
}
}
It prints out as it is but somehow it does not print the type out only the default value of it which is an empty string. How can I make it to print out from the switch statement?
Thanks!
Try debugging.
Try printing the value from within the switch section, to see if you ever get into it.
Try replacing the switch with a simple "==" to see if you ever get "token.getType() == DecafScanner.ID"
General suggestion - move the definition of "type" and "next" outside the loop to avoid recreating them again and again.
I am currently working on an Android application that allows you to watch streaming video in a VideoView. I have a method for allowing you to select one of four streams via a switch statement. That is working correctly and the code for that is as follows:
public void playStream(int position) {
switch (position) {
case 0:
streamOn = true;
streamPos = 0;
logString = "M";
posSelected = "0";
break;
case 1:
streamOn = true;
streamPos = 1;
logString = "J";
posSelected = "1";
break;
case 2:
streamOn = true;
streamPos = 2;
logString = "B";
posSelected = "2";
break;
case 3:
streamOn = true;
streamPos = 3;
logString = "N";
posSelected = "3";
break;
default:
break;
}
checkStreamLink(position);
Log.wtf(logString, posSelected);
Log.wtf(logString, streamURL);
}
What is not working correctly is that in this method for selecting the stream, I have a call to another method ( checkStreamLink(); ) that runs a thread. Depending on which stream you have selected, the thread will call another method that opens up a webpage, reads a line of text, and then sets that text to a String streamURL. The code for those two methods is as follows:
public void checkStreamLink(final int position) {
Thread thread = new Thread(new Runnable() {
#Override
public void run() {
try {
switch (position) {
case 0:
streamURL = getStreamLink("LINK 0 GOES HERE");
break;
case 1:
streamURL = getStreamLink("LINK 1 GOES HERE");
break;
case 2:
streamURL = getStreamLink("LINK 2 GOES HERE");
break;
case 3:
streamURL = getStreamLink("LINK 3 GOES HERE");
break;
default:
break;
}
}
catch (Exception e) {
e.printStackTrace();
}
}
});
thread.start();
}
public String getStreamLink (String textSource) {
URL streamURL;
String errorParsingURL = "ERROR PARSING URL";
try {
streamURL = new URL(textSource);
BufferedReader bufferReader = new BufferedReader(new InputStreamReader(streamURL.openStream()));
String StringBuffer;
String stringText = "";
while ((StringBuffer = bufferReader.readLine()) != null) {
stringText += StringBuffer;
}
bufferReader.close();
return stringText;
}
catch (MalformedURLException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
return errorParsingURL;
}
The issue I'm having is that the String streamURL is returning null on its first use as evidenced by the Log statements I have included. Each time you select a stream after that, the String streamURL returns the text that you should have received the previous time you select a stream. I cannot seem to figure out why this is happening and I would appreciate any assistance.
You are getting a null because getStreamLink is returning its value after you have already printed the result. Print the result log messages at the end of the getStreamLink method to see the actual value which is being returned, and call any additional functionality at that point as well.
Could anyone please provide sample OSLC code with a where clause for the service class?
I have just started using OSLC recently.
Here is the code that I have tried (does't work):
#GET
#Produces({OslcMediaType.APPLICATION_RDF_XML, OslcMediaType.APPLICATION_XML, OslcMediaType.APPLICATION_JSON})
public Project[] getChangeRequests(#QueryParam("oslc.where") final String where,
#QueryParam("oslc.prefix") final String prefix)
{
final List< Project> results = new ArrayList<Project>();
Map<String, String> prefixMap;
try
{
QueryUtils.parseSearchTerms(where);
prefixMap = QueryUtils.parsePrefixes(prefix);
WhereClause whereClause = QueryUtils.parseWhere(where, prefixMap);
}
catch (ParseException e)
{
e.printStackTrace();
}
final Project[] changeRequests = Persistence.getChangeRequestsForProject();
for (final Project changeRequest : changeRequests)
{
changeRequest.setServiceProvider(ServiceProviderSingleton.getServiceProviderURI());
results.add(changeRequest);
}
return results.toArray(new Project[results.size()]);
}
I just thought I will post a working piece of code. Here it is:
prefixMap = QueryUtils.parsePrefixes(prefix);
WhereClause whereClause = QueryUtils.parseWhere(where, prefixMap);
PName property = null;
String value ="";
for (SimpleTerm term : whereClause.children())
{
ComparisonTerm comparison = (ComparisonTerm)term;
String operator;
switch (comparison.operator())
{
case EQUALS:
operator = "equals";
break;
case NOT_EQUALS:
operator = "notequals";
break;
case LESS_THAN:
operator = "lessthan";
break;
case LESS_EQUALS:
operator = "lessthaneq";
break;
case GREATER_THAN:
operator = "greaterthan";
break;
default:
case GREATER_EQUALS:
operator = "greaterhaneq";
break;
}
property = comparison.property();
Value operand = comparison.operand();
value = operand.toString();
switch (operand.type())
{
case STRING:
case URI_REF:
value = value.substring(1, value.length() - 1);
break;
case BOOLEAN:
case DECIMAL:
break;
default:
throw new WebApplicationException
(new UnsupportedOperationException("Unsupported oslc.where comparison operand: " + value),Status.BAD_REQUEST);
}
}
String compareString=property.toString().substring(property.toString().indexOf(":")+1);
String val="get" + compareString.substring(0,1).toUpperCase() +compareString.substring(1);
final Project[] changeRequests = Persistence.getChangeRequestsForProject();
for (final Project changeRequest : changeRequests)
{
changeRequest.setServiceProvider(ServiceProviderSingleton.getServiceProviderURI());
Method m=changeRequest.getClass().getMethod(val, null);
if((m.invoke(changeRequest).toString().equalsIgnoreCase(value)))
{
results.add(changeRequest);
}
}