Abstract A matter. Then, map the matter and the related reality to a licence management system. Then a matter can implement a licence or an authorized supervisor. In the database, the top-level abstraction of all matters is maintained by one table, the code of licence and as is maintained by one table, and the relationship between AS and licence is maintained by one table.
Business Analyst also tells me that a licence can only have up to 2 as associated; then the same situation applies the other way around...
Then I encountered a problem: where should the preventive measures be put? Certainly, it cannot be in the presentation tier; where should I put the struts action?
In addition, there are four protection cases:
Get a current matter and determine whether it is as or licence. Then, get a list of the matter, which is associated matters.
In addition to this current matter, users also want to associate with the target matter. Similarly, the target matter also has its own list, which is the target matter Association (of matter ).
There are four types of judgments.
2. I wrote the code well and repeat it for redundancy. But in fact, in a real work environment, who would perform agile code one day like a 7-hour test, beautiful, no brain or time.
Reconstruction is certainly possible, but reality and ideal are often two things.
Code snippet as follows:
Airmatteractionform FRM = (airmatteractionform) form;
Mtrmatsupertypecustom matter = FRM. getmatter ();
List <mtrmatterxrefcustom> matters = matter. getmtrmatters ();
Actionmessages messages = new actionmessages ();
Connection conn = (transactionconnection) request. getattribute ("connection ");
// Check the related matter that the current matter is going to associate with first, there are together four conditions
If (! (FRM. getmtrmatterid2 () = NULL | frm. getmtrmatterid2 (). equals ("") | frm. getmtrxreftype () = NULL | frm. getmtrxreftype (). equals ("")))
{
Mtrmatsupertypecustom relatedmatter = new mtrmatsupertypecustom ();
Mtrmatsupertypequery. Query (long. parselong (FRM. getmtrmatterid2 (), relatedmatter, "View", Conn );
List <mtrmatterxrefcustom> relatedmatters = relatedmatter. getmtrmatters ();
// Find out if this matter is already related to two as application...
Int counter = 0;
If (relatedmatters. Size ()> 1)
{
// If the matter is a licence type
If (relatedmatter. getmtrmidcd () = "1" | "1". Equals (relatedmatter. getmtrmidcd ()))
{
Iterator iter = relatedmatters. iterator ();
While (ITER. hasnext ())
{
Mtrmatterxrefcustom matterx = (mtrmatterxrefcustom) ITER. Next ();
If (matterx. getmtrxreftype () = "as" | "as". Equals (matterx. getmtrxreftype ()))
{
Counter ++;
}
If (counter> = 2)
{
Messages. Add (actionmessages. global_message,
New actionmessage ("errors. detail", "WARNING-warning-the licence you are intend to associate with has already 2 authorised supervisors associated. The actioin is not permitted ."));
Savemessages (request, messages );
Return Mapping. findforward ("refmtr ");
}
}
} Else if (relatedmatter. getmtrmidcd () = "5" | "5". Equals (relatedmatter. getmtrmidcd ()))
{
// If the matter is an as type
Iterator iter = relatedmatters. iterator ();
While (ITER. hasnext ())
{
Mtrmatterxrefcustom matterx = (mtrmatterxrefcustom) ITER. Next ();
If (matterx. getmtrxreftype () = "LIC" | "LIC". Equals (matterx. getmtrxreftype ()))
{
Counter ++;
}
If (counter> = 2)
{
Messages. Add (actionmessages. global_message,
New actionmessage ("errors. detail", "WARNING-the authorised supervisor you are intend to associate with has already 2 licenses associated. The actioin is not permitted ."));
Savemessages (request, messages );
Return Mapping. findforward ("refmtr ");
}
}
}
}
// So need of this breaking line //////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// ///////
}
Else
{
// Then check the current matter.
// Find out if this matter is already related to two as application...
Int counter = 0;
If (matters. Size ()> 1)
{
// If the matter is a licence type
If (matter. getmtrmidcd () = "1" | "1". Equals (matter. getmtrmidcd ()))
{
Iterator iter = matters. iterator ();
While (ITER. hasnext ())
{
Mtrmatterxrefcustom matterx = (mtrmatterxrefcustom) ITER. Next ();
If (matterx. getmtrxreftype () = "as" | "as". Equals (matterx. getmtrxreftype ()))
{
Counter ++;
}
If (counter> = 2)
{
Messages. Add (actionmessages. global_message,
New actionmessage ("errors. detail", "WARNING-this license already has 2 authorised supervisor related to it. Another authorised supervisor is not permitted to be assigned ."));
Savemessages (request, messages );
Return Mapping. findforward ("refmtr ");
}
}
} Else if (matter. getmtrmidcd () = "5" | "5". Equals (matter. getmtrmidcd ()))
{
// If the matter is an as type
Iterator iter = matters. iterator ();
While (ITER. hasnext ())
{
Mtrmatterxrefcustom matterx = (mtrmatterxrefcustom) ITER. Next ();
If (matterx. getmtrxreftype () = "LIC" | "LIC". Equals (matterx. getmtrxreftype ()))
{
Counter ++;
}
If (counter> = 2)
{
Messages. Add (actionmessages. global_message,
New actionmessage ("errors. detail", "WARNING-This authorised supervisor already has 2 other associated licenses. Please make another selection ."));
Savemessages (request, messages );
Return Mapping. findforward ("refmtr ");
}
}
}
}
// End of the IF-Else
}
If (FRM. getmtrmatterid2 () = NULL | frm. getmtrmatterid2 (). equals ("") | frm. getmtrxreftype () = NULL | frm. getmtrxreftype (). equals (""))
Return Mapping. findforward ("refmtr ");
Mtrmatterxrefcustom ref = new mtrmatterxrefcustom ();
Ref. setmtrmatterid1 (matter. getmtrmatterid ());
Ref. setmtrmatterid2 (New Long (FRM. getmtrmatterid2 ()));
Ref. setmtrxreftype (FRM. getmtrxreftype ());
Try
{
Ref. setmtrnumberformatted (mtrmatterxrefquerycustom. querynumber (ref. getmtrmatterid2 (), Conn ));
Ref. setmtrcitedname (mtrmatterxrefquerycustom. querycitedname (ref. getmtrmatterid2 (), Conn ));
}
Catch (exception E)
{
Projectlogger. debug (this. getclass (). getname () + ". addref (): exception caught! "+ E );
}
Calendar nowcal = calendar. getinstance ();
Date nowdate = new date ();
Nowcal. settime (nowdate );
Ref. setmtrrefdate (New timestamp (nowdate. gettime ()));
If (! Ref. iscontain (matters, ref ))
{
Matters. Add (REF); // Add it to collection
Projectlogger. debug (this. getclass (). getname () + ". addref (): ref =" + ref );
}
Return Mapping. findforward ("refmtr ");
... End of this snippet
Although redundant, ugly, but can be used, really, there is not much energy in the work for logical abstraction and beautification. Will be tired. Architects can draw a picture and abstract it. The implementation is not implemented by CODER, which is hard and thankless. It is a bit unfair sometimes .....
So the only way to step out of the misery is... you are the same ect.
^