Re: validation exceptions in ROP

2007-07-10 Thread Aristedes Maniatis

As I've mentioned offline, I think that if an exception message is
set by the user, it may be a bad idea to clobber it


Yep. Sorry for my brain lapse before - I know what you mean now. By  
"clobber" you mean that ideally we shouldn't be touching the message  
at all, even to append text to the end of it.



Ari



-->
Aristedes Maniatis
phone +61 2 9660 9700
PGP fingerprint 08 57 20 4B 80 69 59 E2  A9 BF 2D 48 C2 20 0C C8




PGP.sig
Description: This is a digitally signed message part


Re: validation exceptions in ROP

2007-07-09 Thread Andrus Adamchik

Hi Ari,

As I've mentioned offline, I think that if an exception message is  
set by the user, it may be a bad idea to clobber it  
(CayenneRuntimeException 'getMessage()' kind of does it too, doh!).  
The good news is that Cayenne internally uses a constructor without a  
message:  "ValidationException(ValidationResult)", so we can use the  
code below to build an informative message:


private static String createMessage(ValidationResult result) {
   // Ari's code goes here
}

public ValidationException(ValidationResult result) {
   this(createMessage(result), result);
}

Do you think this'll work?

Andrus



On Jul 9, 2007, at 1:05 PM, Aristedes Maniatis wrote:

Validation exception messages in three tier are pretty unhelpful by  
the time they get to the client. We've been extending them by  
adding this to ValidationException:



/**
 * Returns message that includes the details of the validation  
failures.

 */
public String getMessage() {
String message = super.getMessage();
if (result.hasFailures()) {
message = message + " validation failures: ";
for (int i = 0; i < result.getFailures().size(); i++) {
message = message + ((ValidationFailure)  
result.getFailures().get(i)).toString();

if (i < result.getFailures().size() - 1) {
message = message + ", ";
}
}
}
return message;
}


Any thoughts about side effects this might have for anyone?


As an aside, what would be even more helpful is if three tier  
returned not a CayenneRuntimeException, but a ValidationException  
to the client. I don't know if that is hard to change.



Ari





-->
ish
http://www.ish.com.au
Level 1, 30 Wilson Street Newtown 2042 Australia
phone +61 2 9550 5001   fax +61 2 9550 4001
GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A






validation exceptions in ROP

2007-07-09 Thread Aristedes Maniatis
Validation exception messages in three tier are pretty unhelpful by  
the time they get to the client. We've been extending them by adding  
this to ValidationException:



/**
 * Returns message that includes the details of the validation  
failures.

 */
public String getMessage() {
String message = super.getMessage();
if (result.hasFailures()) {
message = message + " validation failures: ";
for (int i = 0; i < result.getFailures().size(); i++) {
message = message + ((ValidationFailure)  
result.getFailures().get(i)).toString();

if (i < result.getFailures().size() - 1) {
message = message + ", ";
}
}
}
return message;
}


Any thoughts about side effects this might have for anyone?


As an aside, what would be even more helpful is if three tier  
returned not a CayenneRuntimeException, but a ValidationException to  
the client. I don't know if that is hard to change.



Ari





-->
ish
http://www.ish.com.au
Level 1, 30 Wilson Street Newtown 2042 Australia
phone +61 2 9550 5001   fax +61 2 9550 4001
GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A




PGP.sig
Description: This is a digitally signed message part