Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /* ************************************************************************
  #
  #  DivConq
  #
  #  http://divconq.com/
  #
  #  Copyright:
  #    Copyright 2014 eTimeline, LLC. All rights reserved.
  #
 #  License:
 #    See the license.txt file in the project's top-level directory for details.
 #
 #  Authors:
 #    * Andy White
 #
 ************************************************************************ */
 package divconq.lang;
 
 
 
 // can be used to build task context or user context
 public class OperationContextBuilder {
 	protected RecordStruct values = null;
 
 		this. = new RecordStruct();
 	}
 	
 		this. = ctx;
 	}
 	
 	// templates
 	
 		return this
 			.withOrigin("hub:")
 	}
 	
 		return this
 			.withElevated(true)
 			.withOrigin("hub:")
 	}
 
 		return this
 			.withDomainId("00000_000000000000001")		// guest is part of root domain
 			.withUserId("00000_000000000000002")
 			.withUserName("guest")
 			.withFullName("Guest User")
 			.withVerified(true)
 			.withAuthTags("Guest")
 			.withLocale(LocaleUtil.getDefaultLocale())
 			.withChronology("/" + DateTimeZone.getDefault().getID());		// ISOChronology w/ default zone
 	}
 
 		return this		
 			.withDomainId("00000_000000000000001")		// root is part of root domain
 			.withUserId("00000_000000000000001")
 			.withUserName("root")
 			.withFullName("Root User")
 			.withVerified(true)
 			.withAuthTags("User""PowerUser""Admin""SysAdmin")
 			.withLocale(LocaleUtil.getDefaultLocale())
 			.withChronology("/" + DateTimeZone.getDefault().getID());		// ISOChronology w/ default zone
 	}
 	
 		return this
 			.withElevated(true)
 			.withDomainId("00000_000000000000001")		// root is part of root domain
 			.withUserId("00000_000000000000001")
 			.withUserName("root")
 			.withFullName("Root User")
 			.withVerified(true)
 			.withAuthTags("User""PowerUser""Admin""SysAdmin");
 	}
 	
 	// for task
 		this..setField("OpId"v);
 		return this;
 	}
 
 		this..setField("OpId", OperationContext.allocateOpId());
 		return this;
 	}
 	
		this..setField("Origin"v);
		return this;
	}
		this..setField("SessionId"v);
		return this;
	}
		this..setField("DebugLevel"v.toString());
		return this;
	}
	public OperationContextBuilder withElevated(boolean v) {
		this..setField("Elevated"v);
		return this;
	}
		return OperationContext.allocate(this);
	}
		return OperationContext.allocate(utxthis);
	}
	// for user
		this..setField("UserId"v);
		return this;
	}
		this..setField("UserName"v);
		return this;
	}
		this..setField("FullName"v);
		return this;
	}
		this..setField("Email"v);
		return this;
	}
		this..setField("AuthToken"v);
		return this;
	}
		this..setField("Locale"v);
		return this;
	}
		this..setField("Chronology"v);
		return this;
	}
		this..setField("DomainId"v);
		return this;
	}
	public OperationContextBuilder withVerified(boolean v) {
		this..setField("Verified"v);
		return this;
	}
		this..setField("Credentials"v);
		// changing credentials clears any verification
		this.withVerified(false)
			.withAuthTags("Guest");
		return this;
	}
		this..setField("AuthTags"new ListStruct((Object[])v));
		return this;
	}
		this..setField("AuthTags"v.deepCopy());
		return this;
	}
		ListStruct tlist = this..getFieldAsList("AuthTags");
		if (tlist == null
			this..setField("AuthTags"new ListStruct((Object[])v));
		else
			tlist.addItem((Object[])v);
		return this;
	}
		return UserContext.allocate(this);
	}
	public String toString() {
		return this..toPrettyString();
	}
New to GrepCode? Check out our FAQ X