12. BEGIN
domainlength := LENGTH(domainin);
firstplace := INSTR(domainin, '|', 1, 1);
IF firstplace != 0 THEN
secondplace := INSTR (domainin, '|', 1, 2);
END IF;
IF secondplace != 0 THEN
thirdplace := INSTR (domainin, '|', 1, 3);
END IF;
IF thirdplace != 0 THEN
fourthplace := INSTR (domainin, '|', 1, 4);
END IF;
IF fourthplace != 0 THEN
fifthplace := INSTR (domainin, '|', 1, 5);
END IF;
IF fifthplace != 0 THEN
sixthplace := INSTR (domainin, '|', 1, 6);
END IF;
IF sixthplace != 0 THEN
seventhplace := INSTR (domainin, '|', 1, 7);
END IF;
IF firstplace != 0 AND firstplace != domainlength THEN
firststring := SUBSTR(domainin, 1, (firstplace-1));
ELSIF firstplace = domainlength THEN
firststring := SUBSTR (domainin, 1, (firstplace -1 ));
ELSIF firstplace = 0 AND domainlength !=0 THEN
firststring := domainin;
GOTO get_domain_id;
END IF;
IF secondplace != 0 AND secondplace != domainlength THEN
secondstring := SUBSTR(domainin, (firstplace+1), (secondplace - firstplace-1));
ELSIF secondplace = domainlength THEN
secondstring := SUBSTR (domainin, (firstplace+1), (secondplace-firstplace -1 ));
ELSIF secondplace = 0 AND firstplace != 0 THEN
secondstring := SUBSTR (domainin, (firstplace+1), (domainlength - firstplace));
GOTO get_domain_id;
END IF;
IF thirdplace != 0 AND thirdplace != domainlength THEN
thirdstring := SUBSTR(domainin, (secondplace+1), (thirdplace - secondplace -1));
ELSIF thirdplace = domainlength THEN
thirdstring := SUBSTR (domainin, (secondplace+1), (thirdplace-secondplace -1 ));
ELSIF thirdplace = 0 AND secondplace != 0 THEN
thirdstring := SUBSTR (domainin, (secondplace + 1), (domainlength - secondplace));
GOTO get_domain_id;
END IF;
13. private void SetAccount(RequisitionData.RequisitionItem requisitionItem,
AccountData.Account account, bool automation)
{
bool allowSetAccount = false;
if(account != null)
{
// if the account entry is being set by automation, ensure that
// the user hasn't already set a value
if (automation)
{
if (!requisitionItem.IsAccountCodeNull())
{
if (requisitionItem.AccountCode == string.Empty)
allowSetAccount = true;
else
allowSetAccount = true;
}
else
allowSetAccount = true;
}
else
allowSetAccount = true;
if (allowSetAccount)
{
requisitionItem.AccountID = account.ID;
requisitionItem.AccountCode = account.Code;
}
}
}
14. Public Function makeBoolean(ByVal b As Boolean)
Return b
End Function
Public Function makeByte(ByVal b As Byte)
Return b
End Function
Public Function makeChar(ByVal c As Char)
Return c
End Function
Public Function makeDate(ByVal d As Date)
Return d
End Function
Public Function makeDecimal(ByVal d As Decimal)
Return d
End Function
Public Function makeUShort(ByVal u As UShort)
Return u
End Function
15. "Any fool can write code that a
computer can understand. Good
programmers write code that humans
can understand."
Martin Fowler
18. class ContactController {
def create = {
def json = request.JSON
Contact contact = new Contact()
//map json to object
if (json.first_name) { contact.firstName = json.first_name }
if (json.last_name) { contact.lastName = json.last_name }
//checking attributes
HashSet set = new HashSet()
json.each { attribute ->
ContactAttributeType type = new ContactAttributeType()
type.value = attribute.key
if (attribute.key == 'email') {
attribute.value.each { val ->
ContactAttribute a = new ContactAttribute()
a.key = val.key
a.value = val.value
a.type = type
set.add(a)
}
}
if (attribute.key == 'address') {
attribute.value.each { val ->
ContactAttribute a = new ContactAttribute()
a.key = val.key
a.value = val.value
a.type = type
set.add(a)
}
}
}
contact.attributes = set
//save
if (!contact.save()) {
contact.errors.each {
println it
}
}
//convert to a map to output
Map map = new HashMap()
map.put("id", contact.id)
map.put("first_name", contact.firstName)
map.put("last_name", contact.lastName)
contact.attributes.each { att ->
Map m = map.get(att.type.value)
if (!m) {
m = new HashMap()
map.put(att.type.value, m)
}
m.put(att.key, att.value)
}
render map as JSON
}
}
19. class ContactController {
def create = {
def json = request.JSON
Contact contact = new Contact()
if (json.first_name) { contact.firstName = json.first_name }
if (json.last_name) { contact.lastName = json.last_name }
if (!contact.save()) {
contact.errors.each {
println it
}
}
Map map = new HashMap()
map.put("id", contact.id)
map.put("first_name", contact.firstName)
map.put("last_name", contact.lastName)
render map as JSON
}
}
20. class ContactController {
def create = {
def json = request.JSON
Contact contact = new Contact()
if (json.first_name) { contact.firstName = json.first_name }
if (json.last_name) { contact.lastName = json.last_name }
if (!contact.save()) {
contact.errors.each {
println it
}
}
Map map = new HashMap()
map.put("id", contact.id)
map.put("first_name", contact.firstName)
map.put("last_name", contact.lastName)
render map as JSON
}
}
21. class ContactController {
def create = {
def json = request.JSON
Contact contact = new Contact()
applyJson(contact, json)
if (!contact.save()) {
contact.errors.each {
println it
}
}
Map map = new HashMap()
map.put("id", contact.id)
map.put("first_name", contact.firstName)
map.put("last_name", contact.lastName)
render map as JSON
}
def applyJson = { contact, json ->
if (json.first_name) { contact.firstName = json.first_name }
if (json.last_name) { contact.lastName = json.last_name }
}
}
22. class ContactController {
def create = {
def json = request.JSON
Contact contact = new Contact()
applyJson(contact, json)
if (!contact.save()) {
contact.errors.each {
println it
}
}
Map map = new HashMap()
map.put("id", contact.id)
map.put("first_name", contact.firstName)
map.put("last_name", contact.lastName)
render map as JSON
}
def applyJson = { contact, json ->
if (json.first_name) { contact.firstName = json.first_name }
if (json.last_name) { contact.lastName = json.last_name }
}
}
23. class ContactController {
def create = {
def json = request.JSON
Contact contact = new Contact()
applyJson(contact, json)
if (!contact.save()) {
contact.errors.each {
println it
}
}
Map map = new HashMap()
map.put("id", contact.id)
map.put("first_name", contact.firstName)
map.put("last_name", contact.lastName)
render map as JSON
}
def applyJson = { contact, json ->
if (json.first_name) { contact.firstName = json.first_name }
if (json.last_name) { contact.lastName = json.last_name }
}
}
24. class ContactController {
def create = {
def json = request.JSON
Contact contact = new Contact()
applyJson(contact, json)
if (!contact.save()) {
contact.errors.each {
println it
}
}
render serialize(contact) as JSON
}
def applyJson = { contact, json ->
if (json.first_name) { contact.firstName = json.first_name }
if (json.last_name) { contact.lastName = json.last_name }
}
def serialize = { contact ->
Map map = new HashMap()
map.put("id", contact.id)
map.put("first_name", contact.firstName)
map.put("last_name", contact.lastName)
return map
}
}
25. class ContactController {
def create = {
def json = request.JSON
Contact contact = new Contact()
applyJson(contact, json)
if (!contact.save()) {
contact.errors.each {
println it
}
}
render serialize(contact) as JSON
}
def applyJson = { contact, json ->
if (json.first_name) { contact.firstName = json.first_name }
if (json.last_name) { contact.lastName = json.last_name }
}
def serialize = { contact ->
Map map = new HashMap()
map.put("id", contact.id)
map.put("first_name", contact.firstName)
map.put("last_name", contact.lastName)
return map
}
}
26. class ContactController {
def create = {
def json = request.JSON
Contact contact = new Contact()
applyJson(contact, json)
if (!contact.save()) {
contact.errors.each {
println it
}
}
render serialize(contact) as JSON
}
def applyJson = { contact, json ->
if (json.first_name) { contact.firstName = json.first_name }
if (json.last_name) { contact.lastName = json.last_name }
}
def serialize = { contact ->
Map map = new HashMap()
map.put("id", contact.id)
map.put("first_name", contact.firstName)
map.put("last_name", contact.lastName)
return map
}
}
44. "No matter who. No matter what. No
matter when. Short term. Long term.
Any term. Writing good code is
ALWAYS faster than writing bad code."
Robert Martin (AKA Uncle Bob)
45. “When you’re a carpenter making a
beautiful chest of drawers, you’re
not going to use a piece of plywood
on the back, even though it faces
the wall and nobody will ever see it.”
Steve Jobs