<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Asayal</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Asayal"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Asayal"/>
	<updated>2026-07-21T18:28:56Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=100082</id>
		<title>CSC/ECE 517 Fall 2015/M1506-Refactor-GLES2-Implementation</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=100082"/>
		<updated>2015-12-04T17:27:44Z</updated>

		<summary type="html">&lt;p&gt;Asayal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''' Refactor GLES2 Student Project with SERVO &amp;amp; RUST ''''&lt;br /&gt;
&lt;br /&gt;
Servo is a prototype web browser engine written in the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript RUST]&amp;lt;/span&amp;gt; language.Servo uses a variety of back-end implementations for drawing graphics depending on the operating system.One of such back-end is only compatible with Android right now, and we want to extend and refactor that back-end to enable on all Linux systems..&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
===Servo===&lt;br /&gt;
[https://en.wikipedia.org/wiki/Servo_(layout_engine) Servo]Servo is an open source prototype web browser layout engine being developed by Mozilla, and it is written in [https://www.rust-lang.org/ Rust] language. The main idea is to create a highly parallel environment, in which different components can be handled by fine grained, isolated tasks. The different components can be rendering, HTML parsing, etc.&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Servo_(layout_engine)&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://doc.rust-lang.org/book/README.html Rust] is an open source systems programming language developed by Mozilla. Servo is written in Rust. The main purpose behind it's design is to be thread safe and concurrent. The emphasis is also on speed, safety and control of memory layout.&amp;lt;ref&amp;gt;https://doc.rust-lang.org/stable/book/&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Rust_(programming_language)&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
===Setup of Development environment===&lt;br /&gt;
&lt;br /&gt;
* Servo can be built and compiled in the following steps:&lt;br /&gt;
Servo is built with [https://mail.mozilla.org/pipermail/rust-dev/2014-March/009090.html Cargo], the Rust package manager. Mozilla's Mach tools are used to orchestrate the build and other tasks.&lt;br /&gt;
&lt;br /&gt;
    git clone https://github.com/servo/servo&lt;br /&gt;
    cd servo&lt;br /&gt;
    ./mach build --dev&lt;br /&gt;
    ./mach run tests/html/about-mozilla.html&lt;br /&gt;
&lt;br /&gt;
* Next, we need a cargo override for servo to use our local copy of Rust-layers. For this, we created a &amp;lt;code&amp;gt;.cargo&amp;lt;/code&amp;gt; folder in our home directory(same place that servo and Rust-layers reside), and added a &amp;lt;code&amp;gt;config&amp;lt;/code&amp;gt; file to that folder. The content of that config file is a path to our local Rust-layers.&lt;br /&gt;
    paths = [path/to/rust_layers]&lt;br /&gt;
&lt;br /&gt;
===Overview===&lt;br /&gt;
* After building servo and rust-layers successfully, we added a new command line argument in Servo, which would allow user to select the graphics backend (GL or ES2).&lt;br /&gt;
&lt;br /&gt;
Example is as below&lt;br /&gt;
    ./mach run [url] -G GL or ./mach run [url] --graphics GL (for GL)&lt;br /&gt;
    ./mach run [url] -G ES2 or ./mach run [url] --graphics ES2 (for ES2)&lt;br /&gt;
&lt;br /&gt;
* This option selected is passed onto the rust-layers, which is modified to support ES2 for both linux and android versions. Hence, based on the option selected by the user, rust-layers renders the corresponding graphic backend on linux and android targets.To achieve this, the main changes are done in the platform to remove the EGL specific implementation from the Android platform to a more generic one, so that it can be used by both android and linux systems.&lt;br /&gt;
&lt;br /&gt;
=='''Requirement Analysis'''==&lt;br /&gt;
&lt;br /&gt;
Earlier, only [https://en.wikipedia.org/wiki/OpenGL OpenGL] implementation was supported for Android targets and we would be extending the [https://en.wikipedia.org/wiki/OpenGL_ES#2.0 ES2] implementation to support it for Linux targets. &lt;br /&gt;
&lt;br /&gt;
===Initial step===&lt;br /&gt;
&lt;br /&gt;
Our [https://github.com/servo/servo/wiki/Refactor-GLES2-student-project initial step], implemented for the OSS project involved:&lt;br /&gt;
* compile Servo and ensure that it runs on tests/html/about-mozilla.html&lt;br /&gt;
* adding a new command-line option to allow selecting the graphics backend (GL or ES2) in &amp;lt;code&amp;gt;components/utils/opts.rs&amp;lt;/code&amp;gt;&lt;br /&gt;
* clone rust-layers and build it independently of Servo&lt;br /&gt;
* adding a Cargo override for Servo to use the local copy of rust-layers&lt;br /&gt;
&lt;br /&gt;
===Final Requirements===&lt;br /&gt;
&lt;br /&gt;
* Enable selection of the render api working from the command line, so the user can pick whether to use GL or ES2&lt;br /&gt;
* Modify the necessary files so that the current display version of GL or ES2 are returned whenever either of them are selected&lt;br /&gt;
* Make the EGL libs available on Linux apart from android, for rust-layers to compile rust-egl on Linux build.&lt;br /&gt;
* Separate out the EGLImageNativeSurface implementation from Android and move it to EGL&lt;br /&gt;
* Enable use of EGL or GLX for Linux.&lt;br /&gt;
* In conclusion, implement a generic way of supporting EGL for both Linux and Android, such that ES2 is rendered as a display on linux targets as well.&lt;br /&gt;
&lt;br /&gt;
=='''Implementation'''==&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
&lt;br /&gt;
  Servo/components/utils/opts.rs&lt;br /&gt;
added the new command line option to enable user to select the option of GL or ES2 as the rendering backend. The options of GL or ES2 are stored as an enum called RenderApi , such that running the Servo with option --render-api=chosen_option sets the corresponding Api.&lt;br /&gt;
&lt;br /&gt;
  Servo/ports/glutin/window.rs&lt;br /&gt;
&amp;lt;code&amp;gt;gl_version()&amp;lt;/code&amp;gt; function is modified in a way that based on what is selected as the RenderApi option by the user, the corresponding version of the Api is set. To talk more in detail, if the render api is set to GL, it returns the current value (GL 2.1) &amp;amp; if set to ES2, it returns OpenGlEs 2.0.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;native_display()&amp;lt;/code&amp;gt; for linux target is also modified to call the specific NativeDisplay constructor based on the RenderApi option chosen by the user. Hence for the GL case, the existing NativeDisplay::new constructor is called, but if ES2 is selected, NativeDisplay::from_es2() is called, which has been introduced by us in an attempt to support ES2 for the linux platform as well.&lt;br /&gt;
&lt;br /&gt;
===Rust-Layers===&lt;br /&gt;
&lt;br /&gt;
  rust-layers/cargo.toml&lt;br /&gt;
In order to make the egl libraries available to the Linux too, the cargo.toml is edited which defines the different dependencies that various platforms has. Before, the dependency on rust-egl was added only for android targets but now these dependencies have been added for Linux targets as well.&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/platform/egl/surface.rs&lt;br /&gt;
In order to support EGL for both linux and android targets, we moved the implementation of &amp;lt;code&amp;gt;EGLImageNativeSurface&amp;lt;/code&amp;gt; from the android specific &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; and introduced a new folder &amp;lt;code&amp;gt;egl&amp;lt;/code&amp;gt; which contains its own &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; and implements a generic &amp;lt;code&amp;gt;EGLImageNativeSurface &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/lib.rs&lt;br /&gt;
Since egl needs to be supported for linux too now, the extern crate egl call needs to be linked on Linux as well now. Hence in the cfg flag, the target_os=&amp;quot;linux&amp;quot; is added in addition to android.&lt;br /&gt;
&lt;br /&gt;
In the pub mod platform { }, introduced a new pub mod egl {} section to pull in the new &amp;lt;code&amp;gt;egl/surface.rs&amp;lt;/code&amp;gt; implemented for both android and linux targets.&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/platform/linux/surface.rs&lt;br /&gt;
In order to ensure that ES2 is supported for linux targets too, we need to enable the use of EGL &amp;amp; GLX in the linux specific &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt;&lt;br /&gt;
A new enum is created for NativeDisplay which has two different values of &amp;lt;code&amp;gt;EGLDisplayInfo&amp;lt;/code&amp;gt; &amp;amp; &amp;lt;code&amp;gt;GlxDisplayInfo&amp;lt;/code&amp;gt; and respectively, two constructors are created . The existing NativeDisplay::new constructor is modified to return &amp;lt;code&amp;gt;NativeDisplay::Glx(info)&amp;lt;/code&amp;gt; for the GL version , and the NativeDisplay::from_es2() constructor introduced earlier can return &amp;lt;code&amp;gt;NativeDisplay::::Egl(egl_info)&amp;lt;/code&amp;gt; for the ES2 version.&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/platform/surface.rs&lt;br /&gt;
Earlier, the android target was using its own &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; and the linux target was using its own &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt;. But after the implementation of &amp;lt;code&amp;gt;egl/surface.rs&amp;lt;/code&amp;gt;, changes were made to platform &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; which uses the egl surface.rs for both android and linux now.&lt;br /&gt;
&lt;br /&gt;
=='''Design Principles'''==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to modify the egl implementation to support it for linux targets too, we are not modifying the existing functionality of the android platform, instead we have extended the egl implementation to provide support for linux as well.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code currently has specific platform implementations for android and linux, and egl implementation is provided in android. We have extended the egl implementation to a more generic platform surface and divided the functionality for the native display into two small methods such that these methods can be individually called for whichever graphic backend option is chosen. This avoids the need to call the bigger functionality.&lt;br /&gt;
&lt;br /&gt;
=='''Design Pattern'''==&lt;br /&gt;
The aim is to use ES2 implementation of rust layers for both android and Linux. So we need to use a design pattern that will allow us to extend the current implementation to support Linux targets too and give the user the flexibility to choose between the two implementations for rendering the backend.&lt;br /&gt;
&lt;br /&gt;
We propose to use [https://en.wikipedia.org/wiki/Decorator_pattern Decorator] pattern. The decorator pattern gives the user the ability to choose between the implementations that are desired, and attach the corresponding implementation to the target dynamically at runtime.&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:RefactorGLESMozilla1506OODD.png]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Class Diagram==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:Class_diagram_Mozilla_1506.png]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Proposed Test Cases ==&lt;br /&gt;
&lt;br /&gt;
Some of the test cases which will be used to validate our changes are as follows:&lt;br /&gt;
* Printing the command line option selected by the user in the &amp;lt;code&amp;gt;opts.rs&amp;lt;/code&amp;gt;.This ensures if the command line option selected is correctly passed onto the servo.&lt;br /&gt;
  println!(&amp;quot;selected {:?}&amp;quot;, opts.render_api);&lt;br /&gt;
* Printing the command line option selected by the user in the &amp;lt;code&amp;gt;window.rs&amp;lt;/code&amp;gt;.This ensures if the command line option selected is correctly propagated from the servo to the rust-layers.&lt;br /&gt;
* Test if the rust-egl compiles for the linux surface. A successful compilation ensures egl libraries are made available on Linux for rust-layers.&lt;br /&gt;
* Test if selecting an option ES2 though command line on a linux surface, renders a graphic display of ES2.&lt;br /&gt;
&lt;br /&gt;
== Video ==&lt;br /&gt;
A walkthrough of our entire project is available on this link: [https://drive.google.com/file/d/0B9TVPg3YRoHqT2llQ0FfMWNvUEE/view Walkthrough Video]&lt;br /&gt;
&lt;br /&gt;
=='''Useful libraries'''==&lt;br /&gt;
&lt;br /&gt;
waffle-gl/waffle: A C library for selecting an OpenGL API and window system at runtime.&lt;br /&gt;
&lt;br /&gt;
==Further Reading==&lt;br /&gt;
1.    [https://github.com/servo/servo Servo GitHub]&amp;lt;br&amp;gt;&lt;br /&gt;
2.    [https://github.com/servo/rust-layers Rust-layers GitHub]&amp;lt;br&amp;gt;&lt;br /&gt;
3.    [http://doc.crates.io/guide.html#overriding-dependencies Overriding Dependencies]&amp;lt;br&amp;gt;&lt;br /&gt;
4.    [http://rustbyexample.com/ Rust Language]&amp;lt;br&amp;gt;&lt;br /&gt;
5.    [http://javarevisited.blogspot.com/2014/11/strategy-design-pattern-in-java-using-Enum-Example.html Strategy Design Pattern]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=100081</id>
		<title>CSC/ECE 517 Fall 2015/M1506-Refactor-GLES2-Implementation</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=100081"/>
		<updated>2015-12-04T17:16:32Z</updated>

		<summary type="html">&lt;p&gt;Asayal: /* Servo */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''' Refactor GLES2 Student Project with SERVO &amp;amp; RUST ''''&lt;br /&gt;
&lt;br /&gt;
Servo is a prototype web browser engine written in the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript RUST]&amp;lt;/span&amp;gt; language.Servo uses a variety of back-end implementations for drawing graphics depending on the operating system.One of such back-end is only compatible with Android right now, and we want to extend and refactor that back-end to enable on all Linux systems..&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
===Servo===&lt;br /&gt;
[https://en.wikipedia.org/wiki/Servo_(layout_engine) Servo]Servo is an open source prototype web browser layout engine being developed by Mozilla, and it is written in [https://www.rust-lang.org/ Rust] language. The main idea is to create a highly parallel environment, in which different components can be handled by fine grained, isolated tasks. The different components can be rendering, HTML parsing, etc.&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Servo_(layout_engine)&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://doc.rust-lang.org/book/README.html Rust] is an open source systems programming language developed by Mozilla. Servo is written in Rust. The main purpose behind it's design is to be thread safe and concurrent. The emphasis is also on speed, safety and control of memory layout.&amp;lt;ref&amp;gt;https://doc.rust-lang.org/stable/book/&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Rust_(programming_language)&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
===Setup of Development environment===&lt;br /&gt;
&lt;br /&gt;
* Servo can be built and compiled in the following steps:&lt;br /&gt;
Servo is built with [https://mail.mozilla.org/pipermail/rust-dev/2014-March/009090.html Cargo], the Rust package manager. Mozilla's Mach tools are used to orchestrate the build and other tasks.&lt;br /&gt;
&lt;br /&gt;
    git clone https://github.com/servo/servo&lt;br /&gt;
    cd servo&lt;br /&gt;
    ./mach build --dev&lt;br /&gt;
    ./mach run tests/html/about-mozilla.html&lt;br /&gt;
&lt;br /&gt;
* Next, we need a cargo override for servo to use our local copy of Rust-layers. For this, we created a &amp;lt;code&amp;gt;.cargo&amp;lt;/code&amp;gt; folder in our home directory(same place that servo and Rust-layers reside), and added a &amp;lt;code&amp;gt;config&amp;lt;/code&amp;gt; file to that folder. The content of that config file is a path to our local Rust-layers.&lt;br /&gt;
    paths = [path/to/rust_layers]&lt;br /&gt;
&lt;br /&gt;
===Overview===&lt;br /&gt;
* After building servo and rust-layers successfully, we added a new command line argument in Servo, which would allow user to select the graphics backend (GL or ES2).&lt;br /&gt;
&lt;br /&gt;
Example is as below&lt;br /&gt;
    ./mach run [url] -G GL or ./mach run [url] --graphics GL (for GL)&lt;br /&gt;
    ./mach run [url] -G ES2 or ./mach run [url] --graphics ES2 (for ES2)&lt;br /&gt;
&lt;br /&gt;
* This option selected is passed onto the rust-layers, which is modified to support ES2 for both linux and android versions. Hence, based on the option selected by the user, rust-layers renders the corresponding graphic backend on linux and android targets.To achieve this, the main changes are done in the platform to remove the EGL specific implementation from the Android platform to a more generic one, so that it can be used by both android and linux systems.&lt;br /&gt;
&lt;br /&gt;
=='''Requirement Analysis'''==&lt;br /&gt;
&lt;br /&gt;
Earlier, only [https://en.wikipedia.org/wiki/OpenGL OpenGL] implementation was supported for Android targets and we would be extending the [https://en.wikipedia.org/wiki/OpenGL_ES#2.0 ES2] implementation to support it for Linux targets. &lt;br /&gt;
&lt;br /&gt;
===Initial step===&lt;br /&gt;
&lt;br /&gt;
Our [https://github.com/servo/servo/wiki/Refactor-GLES2-student-project initial step], implemented for the OSS project involved:&lt;br /&gt;
* compile Servo and ensure that it runs on tests/html/about-mozilla.html&lt;br /&gt;
* adding a new command-line option to allow selecting the graphics backend (GL or ES2) in &amp;lt;code&amp;gt;components/utils/opts.rs&amp;lt;/code&amp;gt;&lt;br /&gt;
* clone rust-layers and build it independently of Servo&lt;br /&gt;
* adding a Cargo override for Servo to use the local copy of rust-layers&lt;br /&gt;
&lt;br /&gt;
===Final Requirements===&lt;br /&gt;
&lt;br /&gt;
* Enable selection of the render api working from the command line, so the user can pick whether to use GL or ES2&lt;br /&gt;
* Modify the necessary files so that the current display version of GL or ES2 are returned whenever either of them are selected&lt;br /&gt;
* Make the EGL libs available on Linux apart from android, for rust-layers to compile rust-egl on Linux build.&lt;br /&gt;
* Separate out the EGLImageNativeSurface implementation from Android and move it to EGL&lt;br /&gt;
* Enable use of EGL or GLX for Linux.&lt;br /&gt;
* In conclusion, implement a generic way of supporting EGL for both Linux and Android, such that ES2 is rendered as a display on linux targets as well.&lt;br /&gt;
&lt;br /&gt;
=='''Implementation'''==&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
&lt;br /&gt;
  Servo/components/utils/opts.rs&lt;br /&gt;
added the new command line option to enable user to select the option of GL or ES2 as the rendering backend. The options of GL or ES2 are stored as an enum called RenderApi , such that running the Servo with option --render-api=chosen_option sets the corresponding Api.&lt;br /&gt;
&lt;br /&gt;
  Servo/ports/glutin/window.rs&lt;br /&gt;
&amp;lt;code&amp;gt;gl_version()&amp;lt;/code&amp;gt; function is modified in a way that based on what is selected as the RenderApi option by the user, the corresponding version of the Api is set. To talk more in detail, if the render api is set to GL, it returns the current value (GL 2.1) &amp;amp; if set to ES2, it returns OpenGlEs 2.0.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;native_display()&amp;lt;/code&amp;gt; for linux target is also modified to call the specific NativeDisplay constructor based on the RenderApi option chosen by the user. Hence for the GL case, the existing NativeDisplay::new constructor is called, but if ES2 is selected, NativeDisplay::from_es2() is called, which has been introduced by us in an attempt to support ES2 for the linux platform as well.&lt;br /&gt;
&lt;br /&gt;
===Rust-Layers===&lt;br /&gt;
&lt;br /&gt;
  rust-layers/cargo.toml&lt;br /&gt;
In order to make the egl libraries available to the Linux too, the cargo.toml is edited which defines the different dependencies that various platforms has. Before, the dependency on rust-egl was added only for android targets but now these dependencies have been added for Linux targets as well.&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/platform/egl/surface.rs&lt;br /&gt;
In order to support EGL for both linux and android targets, we moved the implementation of &amp;lt;code&amp;gt;EGLImageNativeSurface&amp;lt;/code&amp;gt; from the android specific &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; and introduced a new folder &amp;lt;code&amp;gt;egl&amp;lt;/code&amp;gt; which contains its own &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; and implements a generic &amp;lt;code&amp;gt;EGLImageNativeSurface &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/lib.rs&lt;br /&gt;
Since egl needs to be supported for linux too now, the extern crate egl call needs to be linked on Linux as well now. Hence in the cfg flag, the target_os=&amp;quot;linux&amp;quot; is added in addition to android.&lt;br /&gt;
&lt;br /&gt;
In the pub mod platform { }, introduced a new pub mod egl {} section to pull in the new &amp;lt;code&amp;gt;egl/surface.rs&amp;lt;/code&amp;gt; implemented for both android and linux targets.&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/platform/linux/surface.rs&lt;br /&gt;
In order to ensure that ES2 is supported for linux targets too, we need to enable the use of EGL &amp;amp; GLX in the linux specific &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt;&lt;br /&gt;
A new enum is created for NativeDisplay which has two different values of &amp;lt;code&amp;gt;EGLDisplayInfo&amp;lt;/code&amp;gt; &amp;amp; &amp;lt;code&amp;gt;GlxDisplayInfo&amp;lt;/code&amp;gt; and respectively, two constructors are created . The existing NativeDisplay::new constructor is modified to return &amp;lt;code&amp;gt;NativeDisplay::Glx(info)&amp;lt;/code&amp;gt; for the GL version , and the NativeDisplay::from_es2() constructor introduced earlier can return &amp;lt;code&amp;gt;NativeDisplay::::Egl(egl_info)&amp;lt;/code&amp;gt; for the ES2 version.&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/platform/surface.rs&lt;br /&gt;
Earlier, the android target was using its own &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; and the linux target was using its own &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt;. But after the implementation of &amp;lt;code&amp;gt;egl/surface.rs&amp;lt;/code&amp;gt;, changes were made to platform &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; which uses the egl surface.rs for both android and linux now.&lt;br /&gt;
&lt;br /&gt;
=='''Design Principles'''==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to modify the egl implementation to support it for linux targets too, we are not modifying the existing functionality of the android platform, instead we have extended the egl implementation to provide support for linux as well.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code currently has specific platform implementations for android and linux, and egl implementation is provided in android. We have extended the egl implementation to a more generic platform surface and divided the functionality for the native display into two small methods such that these methods can be individually called for whichever graphic backend option is chosen. This avoids the need to call the bigger functionality.&lt;br /&gt;
&lt;br /&gt;
=='''Design Pattern'''==&lt;br /&gt;
The aim is to use ES2 implementation of rust layers for both android and Linux. So we need to use a design pattern that will allow us to extend the current implementation to support Linux targets too and give the user the flexibility to choose between the two implementations for rendering the backend.&lt;br /&gt;
&lt;br /&gt;
We propose to use [https://en.wikipedia.org/wiki/Decorator_pattern Decorator] pattern. The decorator pattern gives the user the ability to choose between the implementations that are desired, and attach the corresponding implementation to the target dynamically at runtime.&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:RefactorGLESMozilla1506OODD.png]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Class Diagram==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:Class_diagram_Mozilla_1506.png]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Proposed Test Cases ==&lt;br /&gt;
&lt;br /&gt;
Some of the test cases which will be used to validate our changes are as follows:&lt;br /&gt;
* Printing the command line option selected by the user in the &amp;lt;code&amp;gt;opts.rs&amp;lt;/code&amp;gt;.This ensures if the command line option selected is correctly passed onto the servo.&lt;br /&gt;
  println!(&amp;quot;selected {:?}&amp;quot;, opts.render_api);&lt;br /&gt;
* Printing the command line option selected by the user in the &amp;lt;code&amp;gt;window.rs&amp;lt;/code&amp;gt;.This ensures if the command line option selected is correctly propagated from the servo to the rust-layers.&lt;br /&gt;
* Test if the rust-egl compiles for the linux surface. A successful compilation ensures egl libraries are made available on Linux for rust-layers.&lt;br /&gt;
* Test if selecting an option ES2 though command line on a linux surface, renders a graphic display of ES2.&lt;br /&gt;
&lt;br /&gt;
== Video ==&lt;br /&gt;
A walkthrough of our entire project is available on this link: [https://drive.google.com/file/d/0B9TVPg3YRoHqT2llQ0FfMWNvUEE/view Walkthrough Video]&lt;br /&gt;
&lt;br /&gt;
=='''Useful libraries'''==&lt;br /&gt;
&lt;br /&gt;
waffle-gl/waffle: A C library for selecting an OpenGL API and window system at runtime.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=100080</id>
		<title>CSC/ECE 517 Fall 2015/M1506-Refactor-GLES2-Implementation</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=100080"/>
		<updated>2015-12-04T17:14:29Z</updated>

		<summary type="html">&lt;p&gt;Asayal: /* Rust */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''' Refactor GLES2 Student Project with SERVO &amp;amp; RUST ''''&lt;br /&gt;
&lt;br /&gt;
Servo is a prototype web browser engine written in the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript RUST]&amp;lt;/span&amp;gt; language.Servo uses a variety of back-end implementations for drawing graphics depending on the operating system.One of such back-end is only compatible with Android right now, and we want to extend and refactor that back-end to enable on all Linux systems..&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
===Servo===&lt;br /&gt;
[https://en.wikipedia.org/wiki/Servo_(layout_engine) Servo]Servo is an open source prototype web browser layout engine being developed by Mozilla, and it is written in [https://www.rust-lang.org/ Rust] language. The main idea is to create a highly parallel environment, in which different components can be handled by fine grained, isolated tasks. The different components can be rendering, HTML parsing, etc. &lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://doc.rust-lang.org/book/README.html Rust] is an open source systems programming language developed by Mozilla. Servo is written in Rust. The main purpose behind it's design is to be thread safe and concurrent. The emphasis is also on speed, safety and control of memory layout.&amp;lt;ref&amp;gt;https://doc.rust-lang.org/stable/book/&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Rust_(programming_language)&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
===Setup of Development environment===&lt;br /&gt;
&lt;br /&gt;
* Servo can be built and compiled in the following steps:&lt;br /&gt;
Servo is built with [https://mail.mozilla.org/pipermail/rust-dev/2014-March/009090.html Cargo], the Rust package manager. Mozilla's Mach tools are used to orchestrate the build and other tasks.&lt;br /&gt;
&lt;br /&gt;
    git clone https://github.com/servo/servo&lt;br /&gt;
    cd servo&lt;br /&gt;
    ./mach build --dev&lt;br /&gt;
    ./mach run tests/html/about-mozilla.html&lt;br /&gt;
&lt;br /&gt;
* Next, we need a cargo override for servo to use our local copy of Rust-layers. For this, we created a &amp;lt;code&amp;gt;.cargo&amp;lt;/code&amp;gt; folder in our home directory(same place that servo and Rust-layers reside), and added a &amp;lt;code&amp;gt;config&amp;lt;/code&amp;gt; file to that folder. The content of that config file is a path to our local Rust-layers.&lt;br /&gt;
    paths = [path/to/rust_layers]&lt;br /&gt;
&lt;br /&gt;
===Overview===&lt;br /&gt;
* After building servo and rust-layers successfully, we added a new command line argument in Servo, which would allow user to select the graphics backend (GL or ES2).&lt;br /&gt;
&lt;br /&gt;
Example is as below&lt;br /&gt;
    ./mach run [url] -G GL or ./mach run [url] --graphics GL (for GL)&lt;br /&gt;
    ./mach run [url] -G ES2 or ./mach run [url] --graphics ES2 (for ES2)&lt;br /&gt;
&lt;br /&gt;
* This option selected is passed onto the rust-layers, which is modified to support ES2 for both linux and android versions. Hence, based on the option selected by the user, rust-layers renders the corresponding graphic backend on linux and android targets.To achieve this, the main changes are done in the platform to remove the EGL specific implementation from the Android platform to a more generic one, so that it can be used by both android and linux systems.&lt;br /&gt;
&lt;br /&gt;
=='''Requirement Analysis'''==&lt;br /&gt;
&lt;br /&gt;
Earlier, only [https://en.wikipedia.org/wiki/OpenGL OpenGL] implementation was supported for Android targets and we would be extending the [https://en.wikipedia.org/wiki/OpenGL_ES#2.0 ES2] implementation to support it for Linux targets. &lt;br /&gt;
&lt;br /&gt;
===Initial step===&lt;br /&gt;
&lt;br /&gt;
Our [https://github.com/servo/servo/wiki/Refactor-GLES2-student-project initial step], implemented for the OSS project involved:&lt;br /&gt;
* compile Servo and ensure that it runs on tests/html/about-mozilla.html&lt;br /&gt;
* adding a new command-line option to allow selecting the graphics backend (GL or ES2) in &amp;lt;code&amp;gt;components/utils/opts.rs&amp;lt;/code&amp;gt;&lt;br /&gt;
* clone rust-layers and build it independently of Servo&lt;br /&gt;
* adding a Cargo override for Servo to use the local copy of rust-layers&lt;br /&gt;
&lt;br /&gt;
===Final Requirements===&lt;br /&gt;
&lt;br /&gt;
* Enable selection of the render api working from the command line, so the user can pick whether to use GL or ES2&lt;br /&gt;
* Modify the necessary files so that the current display version of GL or ES2 are returned whenever either of them are selected&lt;br /&gt;
* Make the EGL libs available on Linux apart from android, for rust-layers to compile rust-egl on Linux build.&lt;br /&gt;
* Separate out the EGLImageNativeSurface implementation from Android and move it to EGL&lt;br /&gt;
* Enable use of EGL or GLX for Linux.&lt;br /&gt;
* In conclusion, implement a generic way of supporting EGL for both Linux and Android, such that ES2 is rendered as a display on linux targets as well.&lt;br /&gt;
&lt;br /&gt;
=='''Implementation'''==&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
&lt;br /&gt;
  Servo/components/utils/opts.rs&lt;br /&gt;
added the new command line option to enable user to select the option of GL or ES2 as the rendering backend. The options of GL or ES2 are stored as an enum called RenderApi , such that running the Servo with option --render-api=chosen_option sets the corresponding Api.&lt;br /&gt;
&lt;br /&gt;
  Servo/ports/glutin/window.rs&lt;br /&gt;
&amp;lt;code&amp;gt;gl_version()&amp;lt;/code&amp;gt; function is modified in a way that based on what is selected as the RenderApi option by the user, the corresponding version of the Api is set. To talk more in detail, if the render api is set to GL, it returns the current value (GL 2.1) &amp;amp; if set to ES2, it returns OpenGlEs 2.0.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;native_display()&amp;lt;/code&amp;gt; for linux target is also modified to call the specific NativeDisplay constructor based on the RenderApi option chosen by the user. Hence for the GL case, the existing NativeDisplay::new constructor is called, but if ES2 is selected, NativeDisplay::from_es2() is called, which has been introduced by us in an attempt to support ES2 for the linux platform as well.&lt;br /&gt;
&lt;br /&gt;
===Rust-Layers===&lt;br /&gt;
&lt;br /&gt;
  rust-layers/cargo.toml&lt;br /&gt;
In order to make the egl libraries available to the Linux too, the cargo.toml is edited which defines the different dependencies that various platforms has. Before, the dependency on rust-egl was added only for android targets but now these dependencies have been added for Linux targets as well.&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/platform/egl/surface.rs&lt;br /&gt;
In order to support EGL for both linux and android targets, we moved the implementation of &amp;lt;code&amp;gt;EGLImageNativeSurface&amp;lt;/code&amp;gt; from the android specific &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; and introduced a new folder &amp;lt;code&amp;gt;egl&amp;lt;/code&amp;gt; which contains its own &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; and implements a generic &amp;lt;code&amp;gt;EGLImageNativeSurface &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/lib.rs&lt;br /&gt;
Since egl needs to be supported for linux too now, the extern crate egl call needs to be linked on Linux as well now. Hence in the cfg flag, the target_os=&amp;quot;linux&amp;quot; is added in addition to android.&lt;br /&gt;
&lt;br /&gt;
In the pub mod platform { }, introduced a new pub mod egl {} section to pull in the new &amp;lt;code&amp;gt;egl/surface.rs&amp;lt;/code&amp;gt; implemented for both android and linux targets.&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/platform/linux/surface.rs&lt;br /&gt;
In order to ensure that ES2 is supported for linux targets too, we need to enable the use of EGL &amp;amp; GLX in the linux specific &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt;&lt;br /&gt;
A new enum is created for NativeDisplay which has two different values of &amp;lt;code&amp;gt;EGLDisplayInfo&amp;lt;/code&amp;gt; &amp;amp; &amp;lt;code&amp;gt;GlxDisplayInfo&amp;lt;/code&amp;gt; and respectively, two constructors are created . The existing NativeDisplay::new constructor is modified to return &amp;lt;code&amp;gt;NativeDisplay::Glx(info)&amp;lt;/code&amp;gt; for the GL version , and the NativeDisplay::from_es2() constructor introduced earlier can return &amp;lt;code&amp;gt;NativeDisplay::::Egl(egl_info)&amp;lt;/code&amp;gt; for the ES2 version.&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/platform/surface.rs&lt;br /&gt;
Earlier, the android target was using its own &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; and the linux target was using its own &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt;. But after the implementation of &amp;lt;code&amp;gt;egl/surface.rs&amp;lt;/code&amp;gt;, changes were made to platform &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; which uses the egl surface.rs for both android and linux now.&lt;br /&gt;
&lt;br /&gt;
=='''Design Principles'''==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to modify the egl implementation to support it for linux targets too, we are not modifying the existing functionality of the android platform, instead we have extended the egl implementation to provide support for linux as well.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code currently has specific platform implementations for android and linux, and egl implementation is provided in android. We have extended the egl implementation to a more generic platform surface and divided the functionality for the native display into two small methods such that these methods can be individually called for whichever graphic backend option is chosen. This avoids the need to call the bigger functionality.&lt;br /&gt;
&lt;br /&gt;
=='''Design Pattern'''==&lt;br /&gt;
The aim is to use ES2 implementation of rust layers for both android and Linux. So we need to use a design pattern that will allow us to extend the current implementation to support Linux targets too and give the user the flexibility to choose between the two implementations for rendering the backend.&lt;br /&gt;
&lt;br /&gt;
We propose to use [https://en.wikipedia.org/wiki/Decorator_pattern Decorator] pattern. The decorator pattern gives the user the ability to choose between the implementations that are desired, and attach the corresponding implementation to the target dynamically at runtime.&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:RefactorGLESMozilla1506OODD.png]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Class Diagram==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:Class_diagram_Mozilla_1506.png]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Proposed Test Cases ==&lt;br /&gt;
&lt;br /&gt;
Some of the test cases which will be used to validate our changes are as follows:&lt;br /&gt;
* Printing the command line option selected by the user in the &amp;lt;code&amp;gt;opts.rs&amp;lt;/code&amp;gt;.This ensures if the command line option selected is correctly passed onto the servo.&lt;br /&gt;
  println!(&amp;quot;selected {:?}&amp;quot;, opts.render_api);&lt;br /&gt;
* Printing the command line option selected by the user in the &amp;lt;code&amp;gt;window.rs&amp;lt;/code&amp;gt;.This ensures if the command line option selected is correctly propagated from the servo to the rust-layers.&lt;br /&gt;
* Test if the rust-egl compiles for the linux surface. A successful compilation ensures egl libraries are made available on Linux for rust-layers.&lt;br /&gt;
* Test if selecting an option ES2 though command line on a linux surface, renders a graphic display of ES2.&lt;br /&gt;
&lt;br /&gt;
== Video ==&lt;br /&gt;
A walkthrough of our entire project is available on this link: [https://drive.google.com/file/d/0B9TVPg3YRoHqT2llQ0FfMWNvUEE/view Walkthrough Video]&lt;br /&gt;
&lt;br /&gt;
=='''Useful libraries'''==&lt;br /&gt;
&lt;br /&gt;
waffle-gl/waffle: A C library for selecting an OpenGL API and window system at runtime.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=100079</id>
		<title>CSC/ECE 517 Fall 2015/M1506-Refactor-GLES2-Implementation</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=100079"/>
		<updated>2015-12-04T17:13:06Z</updated>

		<summary type="html">&lt;p&gt;Asayal: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''' Refactor GLES2 Student Project with SERVO &amp;amp; RUST ''''&lt;br /&gt;
&lt;br /&gt;
Servo is a prototype web browser engine written in the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript RUST]&amp;lt;/span&amp;gt; language.Servo uses a variety of back-end implementations for drawing graphics depending on the operating system.One of such back-end is only compatible with Android right now, and we want to extend and refactor that back-end to enable on all Linux systems..&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
===Servo===&lt;br /&gt;
[https://en.wikipedia.org/wiki/Servo_(layout_engine) Servo]Servo is an open source prototype web browser layout engine being developed by Mozilla, and it is written in [https://www.rust-lang.org/ Rust] language. The main idea is to create a highly parallel environment, in which different components can be handled by fine grained, isolated tasks. The different components can be rendering, HTML parsing, etc. &lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://doc.rust-lang.org/book/README.html Rust] is an open source systems programming language developed by Mozilla. Servo is written in Rust. The main purpose behind it's design is to be thread safe and concurrent. The emphasis is also on speed, safety and control of memory layout.&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
===Setup of Development environment===&lt;br /&gt;
&lt;br /&gt;
* Servo can be built and compiled in the following steps:&lt;br /&gt;
Servo is built with [https://mail.mozilla.org/pipermail/rust-dev/2014-March/009090.html Cargo], the Rust package manager. Mozilla's Mach tools are used to orchestrate the build and other tasks.&lt;br /&gt;
&lt;br /&gt;
    git clone https://github.com/servo/servo&lt;br /&gt;
    cd servo&lt;br /&gt;
    ./mach build --dev&lt;br /&gt;
    ./mach run tests/html/about-mozilla.html&lt;br /&gt;
&lt;br /&gt;
* Next, we need a cargo override for servo to use our local copy of Rust-layers. For this, we created a &amp;lt;code&amp;gt;.cargo&amp;lt;/code&amp;gt; folder in our home directory(same place that servo and Rust-layers reside), and added a &amp;lt;code&amp;gt;config&amp;lt;/code&amp;gt; file to that folder. The content of that config file is a path to our local Rust-layers.&lt;br /&gt;
    paths = [path/to/rust_layers]&lt;br /&gt;
&lt;br /&gt;
===Overview===&lt;br /&gt;
* After building servo and rust-layers successfully, we added a new command line argument in Servo, which would allow user to select the graphics backend (GL or ES2).&lt;br /&gt;
&lt;br /&gt;
Example is as below&lt;br /&gt;
    ./mach run [url] -G GL or ./mach run [url] --graphics GL (for GL)&lt;br /&gt;
    ./mach run [url] -G ES2 or ./mach run [url] --graphics ES2 (for ES2)&lt;br /&gt;
&lt;br /&gt;
* This option selected is passed onto the rust-layers, which is modified to support ES2 for both linux and android versions. Hence, based on the option selected by the user, rust-layers renders the corresponding graphic backend on linux and android targets.To achieve this, the main changes are done in the platform to remove the EGL specific implementation from the Android platform to a more generic one, so that it can be used by both android and linux systems.&lt;br /&gt;
&lt;br /&gt;
=='''Requirement Analysis'''==&lt;br /&gt;
&lt;br /&gt;
Earlier, only [https://en.wikipedia.org/wiki/OpenGL OpenGL] implementation was supported for Android targets and we would be extending the [https://en.wikipedia.org/wiki/OpenGL_ES#2.0 ES2] implementation to support it for Linux targets. &lt;br /&gt;
&lt;br /&gt;
===Initial step===&lt;br /&gt;
&lt;br /&gt;
Our [https://github.com/servo/servo/wiki/Refactor-GLES2-student-project initial step], implemented for the OSS project involved:&lt;br /&gt;
* compile Servo and ensure that it runs on tests/html/about-mozilla.html&lt;br /&gt;
* adding a new command-line option to allow selecting the graphics backend (GL or ES2) in &amp;lt;code&amp;gt;components/utils/opts.rs&amp;lt;/code&amp;gt;&lt;br /&gt;
* clone rust-layers and build it independently of Servo&lt;br /&gt;
* adding a Cargo override for Servo to use the local copy of rust-layers&lt;br /&gt;
&lt;br /&gt;
===Final Requirements===&lt;br /&gt;
&lt;br /&gt;
* Enable selection of the render api working from the command line, so the user can pick whether to use GL or ES2&lt;br /&gt;
* Modify the necessary files so that the current display version of GL or ES2 are returned whenever either of them are selected&lt;br /&gt;
* Make the EGL libs available on Linux apart from android, for rust-layers to compile rust-egl on Linux build.&lt;br /&gt;
* Separate out the EGLImageNativeSurface implementation from Android and move it to EGL&lt;br /&gt;
* Enable use of EGL or GLX for Linux.&lt;br /&gt;
* In conclusion, implement a generic way of supporting EGL for both Linux and Android, such that ES2 is rendered as a display on linux targets as well.&lt;br /&gt;
&lt;br /&gt;
=='''Implementation'''==&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
&lt;br /&gt;
  Servo/components/utils/opts.rs&lt;br /&gt;
added the new command line option to enable user to select the option of GL or ES2 as the rendering backend. The options of GL or ES2 are stored as an enum called RenderApi , such that running the Servo with option --render-api=chosen_option sets the corresponding Api.&lt;br /&gt;
&lt;br /&gt;
  Servo/ports/glutin/window.rs&lt;br /&gt;
&amp;lt;code&amp;gt;gl_version()&amp;lt;/code&amp;gt; function is modified in a way that based on what is selected as the RenderApi option by the user, the corresponding version of the Api is set. To talk more in detail, if the render api is set to GL, it returns the current value (GL 2.1) &amp;amp; if set to ES2, it returns OpenGlEs 2.0.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;native_display()&amp;lt;/code&amp;gt; for linux target is also modified to call the specific NativeDisplay constructor based on the RenderApi option chosen by the user. Hence for the GL case, the existing NativeDisplay::new constructor is called, but if ES2 is selected, NativeDisplay::from_es2() is called, which has been introduced by us in an attempt to support ES2 for the linux platform as well.&lt;br /&gt;
&lt;br /&gt;
===Rust-Layers===&lt;br /&gt;
&lt;br /&gt;
  rust-layers/cargo.toml&lt;br /&gt;
In order to make the egl libraries available to the Linux too, the cargo.toml is edited which defines the different dependencies that various platforms has. Before, the dependency on rust-egl was added only for android targets but now these dependencies have been added for Linux targets as well.&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/platform/egl/surface.rs&lt;br /&gt;
In order to support EGL for both linux and android targets, we moved the implementation of &amp;lt;code&amp;gt;EGLImageNativeSurface&amp;lt;/code&amp;gt; from the android specific &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; and introduced a new folder &amp;lt;code&amp;gt;egl&amp;lt;/code&amp;gt; which contains its own &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; and implements a generic &amp;lt;code&amp;gt;EGLImageNativeSurface &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/lib.rs&lt;br /&gt;
Since egl needs to be supported for linux too now, the extern crate egl call needs to be linked on Linux as well now. Hence in the cfg flag, the target_os=&amp;quot;linux&amp;quot; is added in addition to android.&lt;br /&gt;
&lt;br /&gt;
In the pub mod platform { }, introduced a new pub mod egl {} section to pull in the new &amp;lt;code&amp;gt;egl/surface.rs&amp;lt;/code&amp;gt; implemented for both android and linux targets.&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/platform/linux/surface.rs&lt;br /&gt;
In order to ensure that ES2 is supported for linux targets too, we need to enable the use of EGL &amp;amp; GLX in the linux specific &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt;&lt;br /&gt;
A new enum is created for NativeDisplay which has two different values of &amp;lt;code&amp;gt;EGLDisplayInfo&amp;lt;/code&amp;gt; &amp;amp; &amp;lt;code&amp;gt;GlxDisplayInfo&amp;lt;/code&amp;gt; and respectively, two constructors are created . The existing NativeDisplay::new constructor is modified to return &amp;lt;code&amp;gt;NativeDisplay::Glx(info)&amp;lt;/code&amp;gt; for the GL version , and the NativeDisplay::from_es2() constructor introduced earlier can return &amp;lt;code&amp;gt;NativeDisplay::::Egl(egl_info)&amp;lt;/code&amp;gt; for the ES2 version.&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/platform/surface.rs&lt;br /&gt;
Earlier, the android target was using its own &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; and the linux target was using its own &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt;. But after the implementation of &amp;lt;code&amp;gt;egl/surface.rs&amp;lt;/code&amp;gt;, changes were made to platform &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; which uses the egl surface.rs for both android and linux now.&lt;br /&gt;
&lt;br /&gt;
=='''Design Principles'''==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to modify the egl implementation to support it for linux targets too, we are not modifying the existing functionality of the android platform, instead we have extended the egl implementation to provide support for linux as well.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code currently has specific platform implementations for android and linux, and egl implementation is provided in android. We have extended the egl implementation to a more generic platform surface and divided the functionality for the native display into two small methods such that these methods can be individually called for whichever graphic backend option is chosen. This avoids the need to call the bigger functionality.&lt;br /&gt;
&lt;br /&gt;
=='''Design Pattern'''==&lt;br /&gt;
The aim is to use ES2 implementation of rust layers for both android and Linux. So we need to use a design pattern that will allow us to extend the current implementation to support Linux targets too and give the user the flexibility to choose between the two implementations for rendering the backend.&lt;br /&gt;
&lt;br /&gt;
We propose to use [https://en.wikipedia.org/wiki/Decorator_pattern Decorator] pattern. The decorator pattern gives the user the ability to choose between the implementations that are desired, and attach the corresponding implementation to the target dynamically at runtime.&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:RefactorGLESMozilla1506OODD.png]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Class Diagram==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:Class_diagram_Mozilla_1506.png]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Proposed Test Cases ==&lt;br /&gt;
&lt;br /&gt;
Some of the test cases which will be used to validate our changes are as follows:&lt;br /&gt;
* Printing the command line option selected by the user in the &amp;lt;code&amp;gt;opts.rs&amp;lt;/code&amp;gt;.This ensures if the command line option selected is correctly passed onto the servo.&lt;br /&gt;
  println!(&amp;quot;selected {:?}&amp;quot;, opts.render_api);&lt;br /&gt;
* Printing the command line option selected by the user in the &amp;lt;code&amp;gt;window.rs&amp;lt;/code&amp;gt;.This ensures if the command line option selected is correctly propagated from the servo to the rust-layers.&lt;br /&gt;
* Test if the rust-egl compiles for the linux surface. A successful compilation ensures egl libraries are made available on Linux for rust-layers.&lt;br /&gt;
* Test if selecting an option ES2 though command line on a linux surface, renders a graphic display of ES2.&lt;br /&gt;
&lt;br /&gt;
== Video ==&lt;br /&gt;
A walkthrough of our entire project is available on this link: [https://drive.google.com/file/d/0B9TVPg3YRoHqT2llQ0FfMWNvUEE/view Walkthrough Video]&lt;br /&gt;
&lt;br /&gt;
=='''Useful libraries'''==&lt;br /&gt;
&lt;br /&gt;
waffle-gl/waffle: A C library for selecting an OpenGL API and window system at runtime.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=100078</id>
		<title>CSC/ECE 517 Fall 2015/M1506-Refactor-GLES2-Implementation</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=100078"/>
		<updated>2015-12-04T17:12:44Z</updated>

		<summary type="html">&lt;p&gt;Asayal: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''' Refactor GLES2 Student Project with SERVO &amp;amp; RUST ''''&lt;br /&gt;
&lt;br /&gt;
Servo is a prototype web browser engine written in the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript RUST]&amp;lt;/span&amp;gt; language.Servo uses a variety of back-end implementations for drawing graphics depending on the operating system.One of such back-end is only compatible with Android right now, and we want to extend and refactor that back-end to enable on all Linux systems..&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
===Servo===&lt;br /&gt;
[https://en.wikipedia.org/wiki/Servo_(layout_engine) Servo]Servo is an open source prototype web browser layout engine being developed by Mozilla, and it is written in [https://www.rust-lang.org/ Rust] language. The main idea is to create a highly parallel environment, in which different components can be handled by fine grained, isolated tasks. The different components can be rendering, HTML parsing, etc. &lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://doc.rust-lang.org/book/README.html Rust] is an open source systems programming language developed by Mozilla. Servo is written in Rust. The main purpose behind it's design is to be thread safe and concurrent. The emphasis is also on speed, safety and control of memory layout.&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
===Setup of Development environment===&lt;br /&gt;
&lt;br /&gt;
* Servo can be built and compiled in the following steps:&lt;br /&gt;
Servo is built with [https://mail.mozilla.org/pipermail/rust-dev/2014-March/009090.html Cargo], the Rust package manager. Mozilla's Mach tools are used to orchestrate the build and other tasks.&lt;br /&gt;
&lt;br /&gt;
    git clone https://github.com/servo/servo&lt;br /&gt;
    cd servo&lt;br /&gt;
    ./mach build --dev&lt;br /&gt;
    ./mach run tests/html/about-mozilla.html&lt;br /&gt;
&lt;br /&gt;
* Next, we need a cargo override for servo to use our local copy of Rust-layers. For this, we created a &amp;lt;code&amp;gt;.cargo&amp;lt;/code&amp;gt; folder in our home directory(same place that servo and Rust-layers reside), and added a &amp;lt;code&amp;gt;config&amp;lt;/code&amp;gt; file to that folder. The content of that config file is a path to our local Rust-layers.&lt;br /&gt;
    paths = [path/to/rust_layers]&lt;br /&gt;
&lt;br /&gt;
===Overview===&lt;br /&gt;
* After building servo and rust-layers successfully, we added a new command line argument in Servo, which would allow user to select the graphics backend (GL or ES2).&lt;br /&gt;
&lt;br /&gt;
Example is as below&lt;br /&gt;
    ./mach run [url] -G GL or ./mach run [url] --graphics GL (for GL)&lt;br /&gt;
    ./mach run [url] -G ES2 or ./mach run [url] --graphics ES2 (for ES2)&lt;br /&gt;
&lt;br /&gt;
* This option selected is passed onto the rust-layers, which is modified to support ES2 for both linux and android versions. Hence, based on the option selected by the user, rust-layers renders the corresponding graphic backend on linux and android targets.To achieve this, the main changes are done in the platform to remove the EGL specific implementation from the Android platform to a more generic one, so that it can be used by both android and linux systems.&lt;br /&gt;
&lt;br /&gt;
=='''Requirement Analysis'''==&lt;br /&gt;
&lt;br /&gt;
Earlier, only [https://en.wikipedia.org/wiki/OpenGL OpenGL] implementation was supported for Android targets and we would be extending the [https://en.wikipedia.org/wiki/OpenGL_ES#2.0 ES2] implementation to support it for Linux targets. &lt;br /&gt;
&lt;br /&gt;
===Initial step===&lt;br /&gt;
&lt;br /&gt;
Our [https://github.com/servo/servo/wiki/Refactor-GLES2-student-project initial step], implemented for the OSS project involved:&lt;br /&gt;
* compile Servo and ensure that it runs on tests/html/about-mozilla.html&lt;br /&gt;
* adding a new command-line option to allow selecting the graphics backend (GL or ES2) in &amp;lt;code&amp;gt;components/utils/opts.rs&amp;lt;/code&amp;gt;&lt;br /&gt;
* clone rust-layers and build it independently of Servo&lt;br /&gt;
* adding a Cargo override for Servo to use the local copy of rust-layers&lt;br /&gt;
&lt;br /&gt;
===Final Requirements===&lt;br /&gt;
&lt;br /&gt;
* Enable selection of the render api working from the command line, so the user can pick whether to use GL or ES2&lt;br /&gt;
* Modify the necessary files so that the current display version of GL or ES2 are returned whenever either of them are selected&lt;br /&gt;
* Make the EGL libs available on Linux apart from android, for rust-layers to compile rust-egl on Linux build.&lt;br /&gt;
* Separate out the EGLImageNativeSurface implementation from Android and move it to EGL&lt;br /&gt;
* Enable use of EGL or GLX for Linux.&lt;br /&gt;
* In conclusion, implement a generic way of supporting EGL for both Linux and Android, such that ES2 is rendered as a display on linux targets as well.&lt;br /&gt;
&lt;br /&gt;
=='''Implementation'''==&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
&lt;br /&gt;
  Servo/components/utils/opts.rs&lt;br /&gt;
added the new command line option to enable user to select the option of GL or ES2 as the rendering backend. The options of GL or ES2 are stored as an enum called RenderApi , such that running the Servo with option --render-api=chosen_option sets the corresponding Api.&lt;br /&gt;
&lt;br /&gt;
  Servo/ports/glutin/window.rs&lt;br /&gt;
&amp;lt;code&amp;gt;gl_version()&amp;lt;/code&amp;gt; function is modified in a way that based on what is selected as the RenderApi option by the user, the corresponding version of the Api is set. To talk more in detail, if the render api is set to GL, it returns the current value (GL 2.1) &amp;amp; if set to ES2, it returns OpenGlEs 2.0.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;native_display()&amp;lt;/code&amp;gt; for linux target is also modified to call the specific NativeDisplay constructor based on the RenderApi option chosen by the user. Hence for the GL case, the existing NativeDisplay::new constructor is called, but if ES2 is selected, NativeDisplay::from_es2() is called, which has been introduced by us in an attempt to support ES2 for the linux platform as well.&lt;br /&gt;
&lt;br /&gt;
===Rust-Layers===&lt;br /&gt;
&lt;br /&gt;
  rust-layers/cargo.toml&lt;br /&gt;
In order to make the egl libraries available to the Linux too, the cargo.toml is edited which defines the different dependencies that various platforms has. Before, the dependency on rust-egl was added only for android targets but now these dependencies have been added for Linux targets as well.&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/platform/egl/surface.rs&lt;br /&gt;
In order to support EGL for both linux and android targets, we moved the implementation of &amp;lt;code&amp;gt;EGLImageNativeSurface&amp;lt;/code&amp;gt; from the android specific &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; and introduced a new folder &amp;lt;code&amp;gt;egl&amp;lt;/code&amp;gt; which contains its own &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; and implements a generic &amp;lt;code&amp;gt;EGLImageNativeSurface &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/lib.rs&lt;br /&gt;
Since egl needs to be supported for linux too now, the extern crate egl call needs to be linked on Linux as well now. Hence in the cfg flag, the target_os=&amp;quot;linux&amp;quot; is added in addition to android.&lt;br /&gt;
&lt;br /&gt;
In the pub mod platform { }, introduced a new pub mod egl {} section to pull in the new &amp;lt;code&amp;gt;egl/surface.rs&amp;lt;/code&amp;gt; implemented for both android and linux targets.&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/platform/linux/surface.rs&lt;br /&gt;
In order to ensure that ES2 is supported for linux targets too, we need to enable the use of EGL &amp;amp; GLX in the linux specific &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt;&lt;br /&gt;
A new enum is created for NativeDisplay which has two different values of &amp;lt;code&amp;gt;EGLDisplayInfo&amp;lt;/code&amp;gt; &amp;amp; &amp;lt;code&amp;gt;GlxDisplayInfo&amp;lt;/code&amp;gt; and respectively, two constructors are created . The existing NativeDisplay::new constructor is modified to return &amp;lt;code&amp;gt;NativeDisplay::Glx(info)&amp;lt;/code&amp;gt; for the GL version , and the NativeDisplay::from_es2() constructor introduced earlier can return &amp;lt;code&amp;gt;NativeDisplay::::Egl(egl_info)&amp;lt;/code&amp;gt; for the ES2 version.&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/platform/surface.rs&lt;br /&gt;
Earlier, the android target was using its own &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; and the linux target was using its own &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt;. But after the implementation of &amp;lt;code&amp;gt;egl/surface.rs&amp;lt;/code&amp;gt;, changes were made to platform &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; which uses the egl surface.rs for both android and linux now.&lt;br /&gt;
&lt;br /&gt;
=='''Design Principles'''==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to modify the egl implementation to support it for linux targets too, we are not modifying the existing functionality of the android platform, instead we have extended the egl implementation to provide support for linux as well.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code currently has specific platform implementations for android and linux, and egl implementation is provided in android. We have extended the egl implementation to a more generic platform surface and divided the functionality for the native display into two small methods such that these methods can be individually called for whichever graphic backend option is chosen. This avoids the need to call the bigger functionality.&lt;br /&gt;
&lt;br /&gt;
=='''Design Pattern'''==&lt;br /&gt;
The aim is to use ES2 implementation of rust layers for both android and Linux. So we need to use a design pattern that will allow us to extend the current implementation to support Linux targets too and give the user the flexibility to choose between the two implementations for rendering the backend.&lt;br /&gt;
&lt;br /&gt;
We propose to use [https://en.wikipedia.org/wiki/Decorator_pattern Decorator] pattern. The decorator pattern gives the user the ability to choose between the implementations that are desired, and attach the corresponding implementation to the target dynamically at runtime.&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:RefactorGLESMozilla1506OODD.png]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Class Diagram==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:Class_diagram_Mozilla_1506.png]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Proposed Test Cases ==&lt;br /&gt;
&lt;br /&gt;
Some of the test cases which will be used to validate our changes are as follows:&lt;br /&gt;
* Printing the command line option selected by the user in the &amp;lt;code&amp;gt;opts.rs&amp;lt;/code&amp;gt;.This ensures if the command line option selected is correctly passed onto the servo.&lt;br /&gt;
  println!(&amp;quot;selected {:?}&amp;quot;, opts.render_api);&lt;br /&gt;
* Printing the command line option selected by the user in the &amp;lt;code&amp;gt;window.rs&amp;lt;/code&amp;gt;.This ensures if the command line option selected is correctly propagated from the servo to the rust-layers.&lt;br /&gt;
* Test if the rust-egl compiles for the linux surface. A successful compilation ensures egl libraries are made available on Linux for rust-layers.&lt;br /&gt;
* Test if selecting an option ES2 though command line on a linux surface, renders a graphic display of ES2.&lt;br /&gt;
&lt;br /&gt;
== Video ==&lt;br /&gt;
A walkthrough of our entire project is available on this link: [https://drive.google.com/file/d/0B9TVPg3YRoHqT2llQ0FfMWNvUEE/view Walkthrough Video]&lt;br /&gt;
&lt;br /&gt;
=='''Useful libraries'''==&lt;br /&gt;
&lt;br /&gt;
waffle-gl/waffle: A C library for selecting an OpenGL API and window system at runtime.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=100077</id>
		<title>CSC/ECE 517 Fall 2015/M1506-Refactor-GLES2-Implementation</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=100077"/>
		<updated>2015-12-04T17:08:37Z</updated>

		<summary type="html">&lt;p&gt;Asayal: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''' Refactor GLES2 Student Project with SERVO &amp;amp; RUST ''''&lt;br /&gt;
&lt;br /&gt;
Servo is a prototype web browser engine written in the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript RUST]&amp;lt;/span&amp;gt; language.Servo uses a variety of back-end implementations for drawing graphics depending on the operating system.One of such back-end is only compatible with Android right now, and we want to extend and refactor that back-end to enable on all Linux systems..&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
===Servo===&lt;br /&gt;
[https://en.wikipedia.org/wiki/Servo_(layout_engine) Servo]Servo is an open source prototype web browser layout engine being developed by Mozilla, and it is written in [https://www.rust-lang.org/ Rust] language. The main idea is to create a highly parallel environment, in which different components can be handled by fine grained, isolated tasks. The different components can be rendering, HTML parsing, etc. &lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://doc.rust-lang.org/book/README.html Rust] is an open source systems programming language developed by Mozilla. Servo is written in Rust. The main purpose behind it's design is to be thread safe and concurrent. The emphasis is also on speed, safety and control of memory layout.&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
===Setup of Development environment===&lt;br /&gt;
&lt;br /&gt;
* Servo can be built and compiled in the following steps:&lt;br /&gt;
Servo is built with [https://mail.mozilla.org/pipermail/rust-dev/2014-March/009090.html Cargo], the Rust package manager. Mozilla's Mach tools are used to orchestrate the build and other tasks.&lt;br /&gt;
&lt;br /&gt;
    git clone https://github.com/servo/servo&lt;br /&gt;
    cd servo&lt;br /&gt;
    ./mach build --dev&lt;br /&gt;
    ./mach run tests/html/about-mozilla.html&lt;br /&gt;
&lt;br /&gt;
* Next, we need a cargo override for servo to use our local copy of Rust-layers. For this, we created a &amp;lt;code&amp;gt;.cargo&amp;lt;/code&amp;gt; folder in our home directory(same place that servo and Rust-layers reside), and added a &amp;lt;code&amp;gt;config&amp;lt;/code&amp;gt; file to that folder. The content of that config file is a path to our local Rust-layers.&lt;br /&gt;
    paths = [path/to/rust_layers]&lt;br /&gt;
&lt;br /&gt;
===Overview===&lt;br /&gt;
* After building servo and rust-layers successfully, we added a new command line argument in Servo, which would allow user to select the graphics backend (GL or ES2).&lt;br /&gt;
&lt;br /&gt;
Example is as below&lt;br /&gt;
    ./mach run [url] -G GL or ./mach run [url] --graphics GL (for GL)&lt;br /&gt;
    ./mach run [url] -G ES2 or ./mach run [url] --graphics ES2 (for ES2)&lt;br /&gt;
&lt;br /&gt;
* This option selected is passed onto the rust-layers, which is modified to support ES2 for both linux and android versions. Hence, based on the option selected by the user, rust-layers renders the corresponding graphic backend on linux and android targets.To achieve this, the main changes are done in the platform to remove the EGL specific implementation from the Android platform to a more generic one, so that it can be used by both android and linux systems.&lt;br /&gt;
&lt;br /&gt;
=='''Requirement Analysis'''==&lt;br /&gt;
&lt;br /&gt;
Earlier, only [https://en.wikipedia.org/wiki/OpenGL OpenGL] implementation was supported for Android targets and we would be extending the [https://en.wikipedia.org/wiki/OpenGL_ES#2.0 ES2] implementation to support it for Linux targets. &lt;br /&gt;
&lt;br /&gt;
===Initial step===&lt;br /&gt;
&lt;br /&gt;
Our [https://github.com/servo/servo/wiki/Refactor-GLES2-student-project initial step], implemented for the OSS project involved:&lt;br /&gt;
* compile Servo and ensure that it runs on tests/html/about-mozilla.html&lt;br /&gt;
* adding a new command-line option to allow selecting the graphics backend (GL or ES2) in &amp;lt;code&amp;gt;components/utils/opts.rs&amp;lt;/code&amp;gt;&lt;br /&gt;
* clone rust-layers and build it independently of Servo&lt;br /&gt;
* adding a Cargo override for Servo to use the local copy of rust-layers&lt;br /&gt;
&lt;br /&gt;
===Final Requirements===&lt;br /&gt;
&lt;br /&gt;
* Enable selection of the render api working from the command line, so the user can pick whether to use GL or ES2&lt;br /&gt;
* Modify the necessary files so that the current display version of GL or ES2 are returned whenever either of them are selected&lt;br /&gt;
* Make the EGL libs available on Linux apart from android, for rust-layers to compile rust-egl on Linux build.&lt;br /&gt;
* Separate out the EGLImageNativeSurface implementation from Android and move it to EGL&lt;br /&gt;
* Enable use of EGL or GLX for Linux.&lt;br /&gt;
* In conclusion, implement a generic way of supporting EGL for both Linux and Android, such that ES2 is rendered as a display on linux targets as well.&lt;br /&gt;
&lt;br /&gt;
=='''Implementation'''==&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
&lt;br /&gt;
  Servo/components/utils/opts.rs&lt;br /&gt;
added the new command line option to enable user to select the option of GL or ES2 as the rendering backend. The options of GL or ES2 are stored as an enum called RenderApi , such that running the Servo with option --render-api=chosen_option sets the corresponding Api.&lt;br /&gt;
&lt;br /&gt;
  Servo/ports/glutin/window.rs&lt;br /&gt;
&amp;lt;code&amp;gt;gl_version()&amp;lt;/code&amp;gt; function is modified in a way that based on what is selected as the RenderApi option by the user, the corresponding version of the Api is set. To talk more in detail, if the render api is set to GL, it returns the current value (GL 2.1) &amp;amp; if set to ES2, it returns OpenGlEs 2.0.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;native_display()&amp;lt;/code&amp;gt; for linux target is also modified to call the specific NativeDisplay constructor based on the RenderApi option chosen by the user. Hence for the GL case, the existing NativeDisplay::new constructor is called, but if ES2 is selected, NativeDisplay::from_es2() is called, which has been introduced by us in an attempt to support ES2 for the linux platform as well.&lt;br /&gt;
&lt;br /&gt;
===Rust-Layers===&lt;br /&gt;
&lt;br /&gt;
  rust-layers/cargo.toml&lt;br /&gt;
In order to make the egl libraries available to the Linux too, the cargo.toml is edited which defines the different dependencies that various platforms has. Before, the dependency on rust-egl was added only for android targets but now these dependencies have been added for Linux targets as well.&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/platform/egl/surface.rs&lt;br /&gt;
In order to support EGL for both linux and android targets, we moved the implementation of &amp;lt;code&amp;gt;EGLImageNativeSurface&amp;lt;/code&amp;gt; from the android specific &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; and introduced a new folder &amp;lt;code&amp;gt;egl&amp;lt;/code&amp;gt; which contains its own &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; and implements a generic &amp;lt;code&amp;gt;EGLImageNativeSurface &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/lib.rs&lt;br /&gt;
Since egl needs to be supported for linux too now, the extern crate egl call needs to be linked on Linux as well now. Hence in the cfg flag, the target_os=&amp;quot;linux&amp;quot; is added in addition to android.&lt;br /&gt;
&lt;br /&gt;
In the pub mod platform { }, introduced a new pub mod egl {} section to pull in the new &amp;lt;code&amp;gt;egl/surface.rs&amp;lt;/code&amp;gt; implemented for both android and linux targets.&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/platform/linux/surface.rs&lt;br /&gt;
In order to ensure that ES2 is supported for linux targets too, we need to enable the use of EGL &amp;amp; GLX in the linux specific &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt;&lt;br /&gt;
A new enum is created for NativeDisplay which has two different values of &amp;lt;code&amp;gt;EGLDisplayInfo&amp;lt;/code&amp;gt; &amp;amp; &amp;lt;code&amp;gt;GlxDisplayInfo&amp;lt;/code&amp;gt; and respectively, two constructors are created . The existing NativeDisplay::new constructor is modified to return &amp;lt;code&amp;gt;NativeDisplay::Glx(info)&amp;lt;/code&amp;gt; for the GL version , and the NativeDisplay::from_es2() constructor introduced earlier can return &amp;lt;code&amp;gt;NativeDisplay::::Egl(egl_info)&amp;lt;/code&amp;gt; for the ES2 version.&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/platform/surface.rs&lt;br /&gt;
Earlier, the android target was using its own &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; and the linux target was using its own &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt;. But after the implementation of &amp;lt;code&amp;gt;egl/surface.rs&amp;lt;/code&amp;gt;, changes were made to platform &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; which uses the egl surface.rs for both android and linux now.&lt;br /&gt;
&lt;br /&gt;
=='''Design Principles'''==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to modify the egl implementation to support it for linux targets too, we are not modifying the existing functionality of the android platform, instead we have extended the egl implementation to provide support for linux as well.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code currently has specific platform implementations for android and linux, and egl implementation is provided in android. We have extended the egl implementation to a more generic platform surface and divided the functionality for the native display into two small methods such that these methods can be individually called for whichever graphic backend option is chosen. This avoids the need to call the bigger functionality.&lt;br /&gt;
&lt;br /&gt;
=='''Design Pattern'''==&lt;br /&gt;
The aim is to use ES2 implementation of rust layers for both android and Linux. So we need to use a design pattern that will allow us to extend the current implementation to support Linux targets too and give the user the flexibility to choose between the two implementations for rendering the backend.&lt;br /&gt;
&lt;br /&gt;
We propose to use [https://en.wikipedia.org/wiki/Decorator_pattern Decorator] pattern. The decorator pattern gives the user the ability to choose between the implementations that are desired, and attach the corresponding implementation to the target dynamically at runtime.&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:RefactorGLESMozilla1506OODD.png]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Class Diagram==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:Class_diagram_Mozilla_1506.png]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Proposed Test Cases ==&lt;br /&gt;
&lt;br /&gt;
Some of the test cases which will be used to validate our changes are as follows:&lt;br /&gt;
* Printing the command line option selected by the user in the &amp;lt;code&amp;gt;opts.rs&amp;lt;/code&amp;gt;.This ensures if the command line option selected is correctly passed onto the servo.&lt;br /&gt;
  println!(&amp;quot;selected {:?}&amp;quot;, opts.render_api);&lt;br /&gt;
* Printing the command line option selected by the user in the &amp;lt;code&amp;gt;window.rs&amp;lt;/code&amp;gt;.This ensures if the command line option selected is correctly propagated from the servo to the rust-layers.&lt;br /&gt;
* Test if the rust-egl compiles for the linux surface. A successful compilation ensures egl libraries are made available on Linux for rust-layers.&lt;br /&gt;
* Test if selecting an option ES2 though command line on a linux surface, renders a graphic display of ES2.&lt;br /&gt;
&lt;br /&gt;
== Video ==&lt;br /&gt;
A walkthrough of our entire project is available on this link: [https://drive.google.com/file/d/0B9TVPg3YRoHqT2llQ0FfMWNvUEE/view Walkthrough Video]&lt;br /&gt;
&lt;br /&gt;
=='''Useful libraries'''==&lt;br /&gt;
&lt;br /&gt;
waffle-gl/waffle: A C library for selecting an OpenGL API and window system at runtime.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
1.    &amp;lt;ref&amp;gt;https://doc.rust-lang.org/stable/book/&amp;lt;/ref&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
2.    https://en.wikipedia.org/wiki/Rust_(programming_language)&amp;lt;br&amp;gt;&lt;br /&gt;
3.    https://en.wikipedia.org/wiki/Servo_(layout_engine)&amp;lt;br&amp;gt;&lt;br /&gt;
4.    https://github.com/servo/servo/wiki/Refactor-GLES2-student-project&amp;lt;br&amp;gt;&lt;br /&gt;
5.    http://doc.crates.io/guide.html#overriding-dependencies&amp;lt;br&amp;gt;&lt;br /&gt;
6.    http://rustbyexample.com/&amp;lt;br&amp;gt;&lt;br /&gt;
7.    http://javarevisited.blogspot.com/2014/11/strategy-design-pattern-in-java-using-Enum-Example.html&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=100076</id>
		<title>CSC/ECE 517 Fall 2015/M1506-Refactor-GLES2-Implementation</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=100076"/>
		<updated>2015-12-04T17:07:26Z</updated>

		<summary type="html">&lt;p&gt;Asayal: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''' Refactor GLES2 Student Project with SERVO &amp;amp; RUST ''''&lt;br /&gt;
&lt;br /&gt;
Servo is a prototype web browser engine written in the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript RUST]&amp;lt;/span&amp;gt; language.Servo uses a variety of back-end implementations for drawing graphics depending on the operating system.One of such back-end is only compatible with Android right now, and we want to extend and refactor that back-end to enable on all Linux systems..&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
===Servo===&lt;br /&gt;
[https://en.wikipedia.org/wiki/Servo_(layout_engine) Servo]Servo is an open source prototype web browser layout engine being developed by Mozilla, and it is written in [https://www.rust-lang.org/ Rust] language. The main idea is to create a highly parallel environment, in which different components can be handled by fine grained, isolated tasks. The different components can be rendering, HTML parsing, etc. &lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://doc.rust-lang.org/book/README.html Rust] is an open source systems programming language developed by Mozilla. Servo is written in Rust. The main purpose behind it's design is to be thread safe and concurrent. The emphasis is also on speed, safety and control of memory layout.&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
===Setup of Development environment===&lt;br /&gt;
&lt;br /&gt;
* Servo can be built and compiled in the following steps:&lt;br /&gt;
Servo is built with [https://mail.mozilla.org/pipermail/rust-dev/2014-March/009090.html Cargo], the Rust package manager. Mozilla's Mach tools are used to orchestrate the build and other tasks.&lt;br /&gt;
&lt;br /&gt;
    git clone https://github.com/servo/servo&lt;br /&gt;
    cd servo&lt;br /&gt;
    ./mach build --dev&lt;br /&gt;
    ./mach run tests/html/about-mozilla.html&lt;br /&gt;
&lt;br /&gt;
* Next, we need a cargo override for servo to use our local copy of Rust-layers. For this, we created a &amp;lt;code&amp;gt;.cargo&amp;lt;/code&amp;gt; folder in our home directory(same place that servo and Rust-layers reside), and added a &amp;lt;code&amp;gt;config&amp;lt;/code&amp;gt; file to that folder. The content of that config file is a path to our local Rust-layers.&lt;br /&gt;
    paths = [path/to/rust_layers]&lt;br /&gt;
&lt;br /&gt;
===Overview===&lt;br /&gt;
* After building servo and rust-layers successfully, we added a new command line argument in Servo, which would allow user to select the graphics backend (GL or ES2).&lt;br /&gt;
&lt;br /&gt;
Example is as below&lt;br /&gt;
    ./mach run [url] -G GL or ./mach run [url] --graphics GL (for GL)&lt;br /&gt;
    ./mach run [url] -G ES2 or ./mach run [url] --graphics ES2 (for ES2)&lt;br /&gt;
&lt;br /&gt;
* This option selected is passed onto the rust-layers, which is modified to support ES2 for both linux and android versions. Hence, based on the option selected by the user, rust-layers renders the corresponding graphic backend on linux and android targets.To achieve this, the main changes are done in the platform to remove the EGL specific implementation from the Android platform to a more generic one, so that it can be used by both android and linux systems.&lt;br /&gt;
&lt;br /&gt;
=='''Requirement Analysis'''==&lt;br /&gt;
&lt;br /&gt;
Earlier, only [https://en.wikipedia.org/wiki/OpenGL OpenGL] implementation was supported for Android targets and we would be extending the [https://en.wikipedia.org/wiki/OpenGL_ES#2.0 ES2] implementation to support it for Linux targets. &lt;br /&gt;
&lt;br /&gt;
===Initial step===&lt;br /&gt;
&lt;br /&gt;
Our [https://github.com/servo/servo/wiki/Refactor-GLES2-student-project initial step], implemented for the OSS project involved:&lt;br /&gt;
* compile Servo and ensure that it runs on tests/html/about-mozilla.html&lt;br /&gt;
* adding a new command-line option to allow selecting the graphics backend (GL or ES2) in &amp;lt;code&amp;gt;components/utils/opts.rs&amp;lt;/code&amp;gt;&lt;br /&gt;
* clone rust-layers and build it independently of Servo&lt;br /&gt;
* adding a Cargo override for Servo to use the local copy of rust-layers&lt;br /&gt;
&lt;br /&gt;
===Final Requirements===&lt;br /&gt;
&lt;br /&gt;
* Enable selection of the render api working from the command line, so the user can pick whether to use GL or ES2&lt;br /&gt;
* Modify the necessary files so that the current display version of GL or ES2 are returned whenever either of them are selected&lt;br /&gt;
* Make the EGL libs available on Linux apart from android, for rust-layers to compile rust-egl on Linux build.&lt;br /&gt;
* Separate out the EGLImageNativeSurface implementation from Android and move it to EGL&lt;br /&gt;
* Enable use of EGL or GLX for Linux.&lt;br /&gt;
* In conclusion, implement a generic way of supporting EGL for both Linux and Android, such that ES2 is rendered as a display on linux targets as well.&lt;br /&gt;
&lt;br /&gt;
=='''Implementation'''==&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
&lt;br /&gt;
  Servo/components/utils/opts.rs&lt;br /&gt;
added the new command line option to enable user to select the option of GL or ES2 as the rendering backend. The options of GL or ES2 are stored as an enum called RenderApi , such that running the Servo with option --render-api=chosen_option sets the corresponding Api.&lt;br /&gt;
&lt;br /&gt;
  Servo/ports/glutin/window.rs&lt;br /&gt;
&amp;lt;code&amp;gt;gl_version()&amp;lt;/code&amp;gt; function is modified in a way that based on what is selected as the RenderApi option by the user, the corresponding version of the Api is set. To talk more in detail, if the render api is set to GL, it returns the current value (GL 2.1) &amp;amp; if set to ES2, it returns OpenGlEs 2.0.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;native_display()&amp;lt;/code&amp;gt; for linux target is also modified to call the specific NativeDisplay constructor based on the RenderApi option chosen by the user. Hence for the GL case, the existing NativeDisplay::new constructor is called, but if ES2 is selected, NativeDisplay::from_es2() is called, which has been introduced by us in an attempt to support ES2 for the linux platform as well.&lt;br /&gt;
&lt;br /&gt;
===Rust-Layers===&lt;br /&gt;
&lt;br /&gt;
  rust-layers/cargo.toml&lt;br /&gt;
In order to make the egl libraries available to the Linux too, the cargo.toml is edited which defines the different dependencies that various platforms has. Before, the dependency on rust-egl was added only for android targets but now these dependencies have been added for Linux targets as well.&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/platform/egl/surface.rs&lt;br /&gt;
In order to support EGL for both linux and android targets, we moved the implementation of &amp;lt;code&amp;gt;EGLImageNativeSurface&amp;lt;/code&amp;gt; from the android specific &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; and introduced a new folder &amp;lt;code&amp;gt;egl&amp;lt;/code&amp;gt; which contains its own &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; and implements a generic &amp;lt;code&amp;gt;EGLImageNativeSurface &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/lib.rs&lt;br /&gt;
Since egl needs to be supported for linux too now, the extern crate egl call needs to be linked on Linux as well now. Hence in the cfg flag, the target_os=&amp;quot;linux&amp;quot; is added in addition to android.&lt;br /&gt;
&lt;br /&gt;
In the pub mod platform { }, introduced a new pub mod egl {} section to pull in the new &amp;lt;code&amp;gt;egl/surface.rs&amp;lt;/code&amp;gt; implemented for both android and linux targets.&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/platform/linux/surface.rs&lt;br /&gt;
In order to ensure that ES2 is supported for linux targets too, we need to enable the use of EGL &amp;amp; GLX in the linux specific &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt;&lt;br /&gt;
A new enum is created for NativeDisplay which has two different values of &amp;lt;code&amp;gt;EGLDisplayInfo&amp;lt;/code&amp;gt; &amp;amp; &amp;lt;code&amp;gt;GlxDisplayInfo&amp;lt;/code&amp;gt; and respectively, two constructors are created . The existing NativeDisplay::new constructor is modified to return &amp;lt;code&amp;gt;NativeDisplay::Glx(info)&amp;lt;/code&amp;gt; for the GL version , and the NativeDisplay::from_es2() constructor introduced earlier can return &amp;lt;code&amp;gt;NativeDisplay::::Egl(egl_info)&amp;lt;/code&amp;gt; for the ES2 version.&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/platform/surface.rs&lt;br /&gt;
Earlier, the android target was using its own &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; and the linux target was using its own &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt;. But after the implementation of &amp;lt;code&amp;gt;egl/surface.rs&amp;lt;/code&amp;gt;, changes were made to platform &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; which uses the egl surface.rs for both android and linux now.&lt;br /&gt;
&lt;br /&gt;
=='''Design Principles'''==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to modify the egl implementation to support it for linux targets too, we are not modifying the existing functionality of the android platform, instead we have extended the egl implementation to provide support for linux as well.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code currently has specific platform implementations for android and linux, and egl implementation is provided in android. We have extended the egl implementation to a more generic platform surface and divided the functionality for the native display into two small methods such that these methods can be individually called for whichever graphic backend option is chosen. This avoids the need to call the bigger functionality.&lt;br /&gt;
&lt;br /&gt;
=='''Design Pattern'''==&lt;br /&gt;
The aim is to use ES2 implementation of rust layers for both android and Linux. So we need to use a design pattern that will allow us to extend the current implementation to support Linux targets too and give the user the flexibility to choose between the two implementations for rendering the backend.&lt;br /&gt;
&lt;br /&gt;
We propose to use [https://en.wikipedia.org/wiki/Decorator_pattern Decorator] pattern. The decorator pattern gives the user the ability to choose between the implementations that are desired, and attach the corresponding implementation to the target dynamically at runtime.&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:RefactorGLESMozilla1506OODD.png]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Class Diagram==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:Class_diagram_Mozilla_1506.png]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Proposed Test Cases ==&lt;br /&gt;
&lt;br /&gt;
Some of the test cases which will be used to validate our changes are as follows:&lt;br /&gt;
* Printing the command line option selected by the user in the &amp;lt;code&amp;gt;opts.rs&amp;lt;/code&amp;gt;.This ensures if the command line option selected is correctly passed onto the servo.&lt;br /&gt;
  println!(&amp;quot;selected {:?}&amp;quot;, opts.render_api);&lt;br /&gt;
* Printing the command line option selected by the user in the &amp;lt;code&amp;gt;window.rs&amp;lt;/code&amp;gt;.This ensures if the command line option selected is correctly propagated from the servo to the rust-layers.&lt;br /&gt;
* Test if the rust-egl compiles for the linux surface. A successful compilation ensures egl libraries are made available on Linux for rust-layers.&lt;br /&gt;
* Test if selecting an option ES2 though command line on a linux surface, renders a graphic display of ES2.&lt;br /&gt;
&lt;br /&gt;
== Video ==&lt;br /&gt;
A walkthrough of our entire project is available on this link: [https://drive.google.com/file/d/0B9TVPg3YRoHqT2llQ0FfMWNvUEE/view Walkthrough Video]&lt;br /&gt;
&lt;br /&gt;
=='''Useful libraries'''==&lt;br /&gt;
&lt;br /&gt;
waffle-gl/waffle: A C library for selecting an OpenGL API and window system at runtime.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=100074</id>
		<title>CSC/ECE 517 Fall 2015/M1506-Refactor-GLES2-Implementation</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=100074"/>
		<updated>2015-12-04T16:49:01Z</updated>

		<summary type="html">&lt;p&gt;Asayal: /* Video */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''' Refactor GLES2 Student Project with SERVO &amp;amp; RUST ''''&lt;br /&gt;
&lt;br /&gt;
Servo is a prototype web browser engine written in the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript RUST]&amp;lt;/span&amp;gt; language.Servo uses a variety of back-end implementations for drawing graphics depending on the operating system.One of such back-end is only compatible with Android right now, and we want to extend and refactor that back-end to enable on all Linux systems..&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
===Servo===&lt;br /&gt;
[https://en.wikipedia.org/wiki/Servo_(layout_engine) Servo]Servo is an open source prototype web browser layout engine being developed by Mozilla, and it is written in [https://www.rust-lang.org/ Rust] language. The main idea is to create a highly parallel environment, in which different components can be handled by fine grained, isolated tasks. The different components can be rendering, HTML parsing, etc. &lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://doc.rust-lang.org/book/README.html Rust] is an open source systems programming language developed by Mozilla. Servo is written in Rust. The main purpose behind it's design is to be thread safe and concurrent. The emphasis is also on speed, safety and control of memory layout.&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
===Setup of Development environment===&lt;br /&gt;
&lt;br /&gt;
* Servo can be built and compiled in the following steps:&lt;br /&gt;
Servo is built with [https://mail.mozilla.org/pipermail/rust-dev/2014-March/009090.html Cargo], the Rust package manager. Mozilla's Mach tools are used to orchestrate the build and other tasks.&lt;br /&gt;
&lt;br /&gt;
    git clone https://github.com/servo/servo&lt;br /&gt;
    cd servo&lt;br /&gt;
    ./mach build --dev&lt;br /&gt;
    ./mach run tests/html/about-mozilla.html&lt;br /&gt;
&lt;br /&gt;
* Next, we need a cargo override for servo to use our local copy of Rust-layers. For this, we created a &amp;lt;code&amp;gt;.cargo&amp;lt;/code&amp;gt; folder in our home directory(same place that servo and Rust-layers reside), and added a &amp;lt;code&amp;gt;config&amp;lt;/code&amp;gt; file to that folder. The content of that config file is a path to our local Rust-layers.&lt;br /&gt;
    paths = [path/to/rust_layers]&lt;br /&gt;
&lt;br /&gt;
===Overview===&lt;br /&gt;
* After building servo and rust-layers successfully, we added a new command line argument in Servo, which would allow user to select the graphics backend (GL or ES2).&lt;br /&gt;
&lt;br /&gt;
Example is as below&lt;br /&gt;
    ./mach run [url] -G GL or ./mach run [url] --graphics GL (for GL)&lt;br /&gt;
    ./mach run [url] -G ES2 or ./mach run [url] --graphics ES2 (for ES2)&lt;br /&gt;
&lt;br /&gt;
* This option selected is passed onto the rust-layers, which is modified to support ES2 for both linux and android versions. Hence, based on the option selected by the user, rust-layers renders the corresponding graphic backend on linux and android targets.To achieve this, the main changes are done in the platform to remove the EGL specific implementation from the Android platform to a more generic one, so that it can be used by both android and linux systems.&lt;br /&gt;
&lt;br /&gt;
=='''Requirement Analysis'''==&lt;br /&gt;
&lt;br /&gt;
Earlier, only [https://en.wikipedia.org/wiki/OpenGL OpenGL] implementation was supported for Android targets and we would be extending the [https://en.wikipedia.org/wiki/OpenGL_ES#2.0 ES2] implementation to support it for Linux targets. &lt;br /&gt;
&lt;br /&gt;
===Initial step===&lt;br /&gt;
&lt;br /&gt;
Our [https://github.com/servo/servo/wiki/Refactor-GLES2-student-project initial step], implemented for the OSS project involved:&lt;br /&gt;
* compile Servo and ensure that it runs on tests/html/about-mozilla.html&lt;br /&gt;
* adding a new command-line option to allow selecting the graphics backend (GL or ES2) in &amp;lt;code&amp;gt;components/utils/opts.rs&amp;lt;/code&amp;gt;&lt;br /&gt;
* clone rust-layers and build it independently of Servo&lt;br /&gt;
* adding a Cargo override for Servo to use the local copy of rust-layers&lt;br /&gt;
&lt;br /&gt;
===Final Requirements===&lt;br /&gt;
&lt;br /&gt;
* Enable selection of the render api working from the command line, so the user can pick whether to use GL or ES2&lt;br /&gt;
* Modify the necessary files so that the current display version of GL or ES2 are returned whenever either of them are selected&lt;br /&gt;
* Make the EGL libs available on Linux apart from android, for rust-layers to compile rust-egl on Linux build.&lt;br /&gt;
* Separate out the EGLImageNativeSurface implementation from Android and move it to EGL&lt;br /&gt;
* Enable use of EGL or GLX for Linux.&lt;br /&gt;
* In conclusion, implement a generic way of supporting EGL for both Linux and Android, such that ES2 is rendered as a display on linux targets as well.&lt;br /&gt;
&lt;br /&gt;
=='''Implementation'''==&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
&lt;br /&gt;
  Servo/components/utils/opts.rs&lt;br /&gt;
added the new command line option to enable user to select the option of GL or ES2 as the rendering backend. The options of GL or ES2 are stored as an enum called RenderApi , such that running the Servo with option --render-api=chosen_option sets the corresponding Api.&lt;br /&gt;
&lt;br /&gt;
  Servo/ports/glutin/window.rs&lt;br /&gt;
&amp;lt;code&amp;gt;gl_version()&amp;lt;/code&amp;gt; function is modified in a way that based on what is selected as the RenderApi option by the user, the corresponding version of the Api is set. To talk more in detail, if the render api is set to GL, it returns the current value (GL 2.1) &amp;amp; if set to ES2, it returns OpenGlEs 2.0.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;native_display()&amp;lt;/code&amp;gt; for linux target is also modified to call the specific NativeDisplay constructor based on the RenderApi option chosen by the user. Hence for the GL case, the existing NativeDisplay::new constructor is called, but if ES2 is selected, NativeDisplay::from_es2() is called, which has been introduced by us in an attempt to support ES2 for the linux platform as well.&lt;br /&gt;
&lt;br /&gt;
===Rust-Layers===&lt;br /&gt;
&lt;br /&gt;
  rust-layers/cargo.toml&lt;br /&gt;
In order to make the egl libraries available to the Linux too, the cargo.toml is edited which defines the different dependencies that various platforms has. Before, the dependency on rust-egl was added only for android targets but now these dependencies have been added for Linux targets as well.&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/platform/egl/surface.rs&lt;br /&gt;
In order to support EGL for both linux and android targets, we moved the implementation of &amp;lt;code&amp;gt;EGLImageNativeSurface&amp;lt;/code&amp;gt; from the android specific &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; and introduced a new folder &amp;lt;code&amp;gt;egl&amp;lt;/code&amp;gt; which contains its own &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; and implements a generic &amp;lt;code&amp;gt;EGLImageNativeSurface &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/lib.rs&lt;br /&gt;
Since egl needs to be supported for linux too now, the extern crate egl call needs to be linked on Linux as well now. Hence in the cfg flag, the target_os=&amp;quot;linux&amp;quot; is added in addition to android.&lt;br /&gt;
&lt;br /&gt;
In the pub mod platform { }, introduced a new pub mod egl {} section to pull in the new &amp;lt;code&amp;gt;egl/surface.rs&amp;lt;/code&amp;gt; implemented for both android and linux targets.&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/platform/linux/surface.rs&lt;br /&gt;
In order to ensure that ES2 is supported for linux targets too, we need to enable the use of EGL &amp;amp; GLX in the linux specific &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt;&lt;br /&gt;
A new enum is created for NativeDisplay which has two different values of &amp;lt;code&amp;gt;EGLDisplayInfo&amp;lt;/code&amp;gt; &amp;amp; &amp;lt;code&amp;gt;GlxDisplayInfo&amp;lt;/code&amp;gt; and respectively, two constructors are created . The existing NativeDisplay::new constructor is modified to return &amp;lt;code&amp;gt;NativeDisplay::Glx(info)&amp;lt;/code&amp;gt; for the GL version , and the NativeDisplay::from_es2() constructor introduced earlier can return &amp;lt;code&amp;gt;NativeDisplay::::Egl(egl_info)&amp;lt;/code&amp;gt; for the ES2 version.&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/platform/surface.rs&lt;br /&gt;
Earlier, the android target was using its own &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; and the linux target was using its own &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt;. But after the implementation of &amp;lt;code&amp;gt;egl/surface.rs&amp;lt;/code&amp;gt;, changes were made to platform &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; which uses the egl surface.rs for both android and linux now.&lt;br /&gt;
&lt;br /&gt;
=='''Design Principles'''==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to modify the egl implementation to support it for linux targets too, we are not modifying the existing functionality of the android platform, instead we have extended the egl implementation to provide support for linux as well.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code currently has specific platform implementations for android and linux, and egl implementation is provided in android. We have extended the egl implementation to a more generic platform surface and divided the functionality for the native display into two small methods such that these methods can be individually called for whichever graphic backend option is chosen. This avoids the need to call the bigger functionality.&lt;br /&gt;
&lt;br /&gt;
=='''Design Pattern'''==&lt;br /&gt;
The aim is to use ES2 implementation of rust layers for both android and Linux. So we need to use a design pattern that will allow us to extend the current implementation to support Linux targets too and give the user the flexibility to choose between the two implementations for rendering the backend.&lt;br /&gt;
&lt;br /&gt;
We propose to use [https://en.wikipedia.org/wiki/Decorator_pattern Decorator] pattern. The decorator pattern gives the user the ability to choose between the implementations that are desired, and attach the corresponding implementation to the target dynamically at runtime.&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:RefactorGLESMozilla1506OODD.png]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Class Diagram==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:Class_diagram_Mozilla_1506.png]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Proposed Test Cases ==&lt;br /&gt;
&lt;br /&gt;
Some of the test cases which will be used to validate our changes are as follows:&lt;br /&gt;
* Printing the command line option selected by the user in the &amp;lt;code&amp;gt;opts.rs&amp;lt;/code&amp;gt;.This ensures if the command line option selected is correctly passed onto the servo.&lt;br /&gt;
  println!(&amp;quot;selected {:?}&amp;quot;, opts.render_api);&lt;br /&gt;
* Printing the command line option selected by the user in the &amp;lt;code&amp;gt;window.rs&amp;lt;/code&amp;gt;.This ensures if the command line option selected is correctly propagated from the servo to the rust-layers.&lt;br /&gt;
* Test if the rust-egl compiles for the linux surface. A successful compilation ensures egl libraries are made available on Linux for rust-layers.&lt;br /&gt;
* Test if selecting an option ES2 though command line on a linux surface, renders a graphic display of ES2.&lt;br /&gt;
&lt;br /&gt;
== Video ==&lt;br /&gt;
A walkthrough of our entire project is available on this link: [https://drive.google.com/file/d/0B9TVPg3YRoHqT2llQ0FfMWNvUEE/view Walkthrough Video]&lt;br /&gt;
&lt;br /&gt;
=='''Useful libraries'''==&lt;br /&gt;
&lt;br /&gt;
waffle-gl/waffle: A C library for selecting an OpenGL API and window system at runtime.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
1.    https://doc.rust-lang.org/stable/book/&amp;lt;br&amp;gt;&lt;br /&gt;
2.    https://en.wikipedia.org/wiki/Rust_(programming_language)&amp;lt;br&amp;gt;&lt;br /&gt;
3.    https://en.wikipedia.org/wiki/Servo_(layout_engine)&amp;lt;br&amp;gt;&lt;br /&gt;
4.    https://github.com/servo/servo/wiki/Refactor-GLES2-student-project&amp;lt;br&amp;gt;&lt;br /&gt;
5.    http://doc.crates.io/guide.html#overriding-dependencies&amp;lt;br&amp;gt;&lt;br /&gt;
6.    http://rustbyexample.com/&amp;lt;br&amp;gt;&lt;br /&gt;
7.    http://javarevisited.blogspot.com/2014/11/strategy-design-pattern-in-java-using-Enum-Example.html&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=100073</id>
		<title>CSC/ECE 517 Fall 2015/M1506-Refactor-GLES2-Implementation</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=100073"/>
		<updated>2015-12-04T16:47:00Z</updated>

		<summary type="html">&lt;p&gt;Asayal: /* Video */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''' Refactor GLES2 Student Project with SERVO &amp;amp; RUST ''''&lt;br /&gt;
&lt;br /&gt;
Servo is a prototype web browser engine written in the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript RUST]&amp;lt;/span&amp;gt; language.Servo uses a variety of back-end implementations for drawing graphics depending on the operating system.One of such back-end is only compatible with Android right now, and we want to extend and refactor that back-end to enable on all Linux systems..&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
===Servo===&lt;br /&gt;
[https://en.wikipedia.org/wiki/Servo_(layout_engine) Servo]Servo is an open source prototype web browser layout engine being developed by Mozilla, and it is written in [https://www.rust-lang.org/ Rust] language. The main idea is to create a highly parallel environment, in which different components can be handled by fine grained, isolated tasks. The different components can be rendering, HTML parsing, etc. &lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://doc.rust-lang.org/book/README.html Rust] is an open source systems programming language developed by Mozilla. Servo is written in Rust. The main purpose behind it's design is to be thread safe and concurrent. The emphasis is also on speed, safety and control of memory layout.&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
===Setup of Development environment===&lt;br /&gt;
&lt;br /&gt;
* Servo can be built and compiled in the following steps:&lt;br /&gt;
Servo is built with [https://mail.mozilla.org/pipermail/rust-dev/2014-March/009090.html Cargo], the Rust package manager. Mozilla's Mach tools are used to orchestrate the build and other tasks.&lt;br /&gt;
&lt;br /&gt;
    git clone https://github.com/servo/servo&lt;br /&gt;
    cd servo&lt;br /&gt;
    ./mach build --dev&lt;br /&gt;
    ./mach run tests/html/about-mozilla.html&lt;br /&gt;
&lt;br /&gt;
* Next, we need a cargo override for servo to use our local copy of Rust-layers. For this, we created a &amp;lt;code&amp;gt;.cargo&amp;lt;/code&amp;gt; folder in our home directory(same place that servo and Rust-layers reside), and added a &amp;lt;code&amp;gt;config&amp;lt;/code&amp;gt; file to that folder. The content of that config file is a path to our local Rust-layers.&lt;br /&gt;
    paths = [path/to/rust_layers]&lt;br /&gt;
&lt;br /&gt;
===Overview===&lt;br /&gt;
* After building servo and rust-layers successfully, we added a new command line argument in Servo, which would allow user to select the graphics backend (GL or ES2).&lt;br /&gt;
&lt;br /&gt;
Example is as below&lt;br /&gt;
    ./mach run [url] -G GL or ./mach run [url] --graphics GL (for GL)&lt;br /&gt;
    ./mach run [url] -G ES2 or ./mach run [url] --graphics ES2 (for ES2)&lt;br /&gt;
&lt;br /&gt;
* This option selected is passed onto the rust-layers, which is modified to support ES2 for both linux and android versions. Hence, based on the option selected by the user, rust-layers renders the corresponding graphic backend on linux and android targets.To achieve this, the main changes are done in the platform to remove the EGL specific implementation from the Android platform to a more generic one, so that it can be used by both android and linux systems.&lt;br /&gt;
&lt;br /&gt;
=='''Requirement Analysis'''==&lt;br /&gt;
&lt;br /&gt;
Earlier, only [https://en.wikipedia.org/wiki/OpenGL OpenGL] implementation was supported for Android targets and we would be extending the [https://en.wikipedia.org/wiki/OpenGL_ES#2.0 ES2] implementation to support it for Linux targets. &lt;br /&gt;
&lt;br /&gt;
===Initial step===&lt;br /&gt;
&lt;br /&gt;
Our [https://github.com/servo/servo/wiki/Refactor-GLES2-student-project initial step], implemented for the OSS project involved:&lt;br /&gt;
* compile Servo and ensure that it runs on tests/html/about-mozilla.html&lt;br /&gt;
* adding a new command-line option to allow selecting the graphics backend (GL or ES2) in &amp;lt;code&amp;gt;components/utils/opts.rs&amp;lt;/code&amp;gt;&lt;br /&gt;
* clone rust-layers and build it independently of Servo&lt;br /&gt;
* adding a Cargo override for Servo to use the local copy of rust-layers&lt;br /&gt;
&lt;br /&gt;
===Final Requirements===&lt;br /&gt;
&lt;br /&gt;
* Enable selection of the render api working from the command line, so the user can pick whether to use GL or ES2&lt;br /&gt;
* Modify the necessary files so that the current display version of GL or ES2 are returned whenever either of them are selected&lt;br /&gt;
* Make the EGL libs available on Linux apart from android, for rust-layers to compile rust-egl on Linux build.&lt;br /&gt;
* Separate out the EGLImageNativeSurface implementation from Android and move it to EGL&lt;br /&gt;
* Enable use of EGL or GLX for Linux.&lt;br /&gt;
* In conclusion, implement a generic way of supporting EGL for both Linux and Android, such that ES2 is rendered as a display on linux targets as well.&lt;br /&gt;
&lt;br /&gt;
=='''Implementation'''==&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
&lt;br /&gt;
  Servo/components/utils/opts.rs&lt;br /&gt;
added the new command line option to enable user to select the option of GL or ES2 as the rendering backend. The options of GL or ES2 are stored as an enum called RenderApi , such that running the Servo with option --render-api=chosen_option sets the corresponding Api.&lt;br /&gt;
&lt;br /&gt;
  Servo/ports/glutin/window.rs&lt;br /&gt;
&amp;lt;code&amp;gt;gl_version()&amp;lt;/code&amp;gt; function is modified in a way that based on what is selected as the RenderApi option by the user, the corresponding version of the Api is set. To talk more in detail, if the render api is set to GL, it returns the current value (GL 2.1) &amp;amp; if set to ES2, it returns OpenGlEs 2.0.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;native_display()&amp;lt;/code&amp;gt; for linux target is also modified to call the specific NativeDisplay constructor based on the RenderApi option chosen by the user. Hence for the GL case, the existing NativeDisplay::new constructor is called, but if ES2 is selected, NativeDisplay::from_es2() is called, which has been introduced by us in an attempt to support ES2 for the linux platform as well.&lt;br /&gt;
&lt;br /&gt;
===Rust-Layers===&lt;br /&gt;
&lt;br /&gt;
  rust-layers/cargo.toml&lt;br /&gt;
In order to make the egl libraries available to the Linux too, the cargo.toml is edited which defines the different dependencies that various platforms has. Before, the dependency on rust-egl was added only for android targets but now these dependencies have been added for Linux targets as well.&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/platform/egl/surface.rs&lt;br /&gt;
In order to support EGL for both linux and android targets, we moved the implementation of &amp;lt;code&amp;gt;EGLImageNativeSurface&amp;lt;/code&amp;gt; from the android specific &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; and introduced a new folder &amp;lt;code&amp;gt;egl&amp;lt;/code&amp;gt; which contains its own &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; and implements a generic &amp;lt;code&amp;gt;EGLImageNativeSurface &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/lib.rs&lt;br /&gt;
Since egl needs to be supported for linux too now, the extern crate egl call needs to be linked on Linux as well now. Hence in the cfg flag, the target_os=&amp;quot;linux&amp;quot; is added in addition to android.&lt;br /&gt;
&lt;br /&gt;
In the pub mod platform { }, introduced a new pub mod egl {} section to pull in the new &amp;lt;code&amp;gt;egl/surface.rs&amp;lt;/code&amp;gt; implemented for both android and linux targets.&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/platform/linux/surface.rs&lt;br /&gt;
In order to ensure that ES2 is supported for linux targets too, we need to enable the use of EGL &amp;amp; GLX in the linux specific &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt;&lt;br /&gt;
A new enum is created for NativeDisplay which has two different values of &amp;lt;code&amp;gt;EGLDisplayInfo&amp;lt;/code&amp;gt; &amp;amp; &amp;lt;code&amp;gt;GlxDisplayInfo&amp;lt;/code&amp;gt; and respectively, two constructors are created . The existing NativeDisplay::new constructor is modified to return &amp;lt;code&amp;gt;NativeDisplay::Glx(info)&amp;lt;/code&amp;gt; for the GL version , and the NativeDisplay::from_es2() constructor introduced earlier can return &amp;lt;code&amp;gt;NativeDisplay::::Egl(egl_info)&amp;lt;/code&amp;gt; for the ES2 version.&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/platform/surface.rs&lt;br /&gt;
Earlier, the android target was using its own &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; and the linux target was using its own &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt;. But after the implementation of &amp;lt;code&amp;gt;egl/surface.rs&amp;lt;/code&amp;gt;, changes were made to platform &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; which uses the egl surface.rs for both android and linux now.&lt;br /&gt;
&lt;br /&gt;
=='''Design Principles'''==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to modify the egl implementation to support it for linux targets too, we are not modifying the existing functionality of the android platform, instead we have extended the egl implementation to provide support for linux as well.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code currently has specific platform implementations for android and linux, and egl implementation is provided in android. We have extended the egl implementation to a more generic platform surface and divided the functionality for the native display into two small methods such that these methods can be individually called for whichever graphic backend option is chosen. This avoids the need to call the bigger functionality.&lt;br /&gt;
&lt;br /&gt;
=='''Design Pattern'''==&lt;br /&gt;
The aim is to use ES2 implementation of rust layers for both android and Linux. So we need to use a design pattern that will allow us to extend the current implementation to support Linux targets too and give the user the flexibility to choose between the two implementations for rendering the backend.&lt;br /&gt;
&lt;br /&gt;
We propose to use [https://en.wikipedia.org/wiki/Decorator_pattern Decorator] pattern. The decorator pattern gives the user the ability to choose between the implementations that are desired, and attach the corresponding implementation to the target dynamically at runtime.&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:RefactorGLESMozilla1506OODD.png]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Class Diagram==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:Class_diagram_Mozilla_1506.png]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Proposed Test Cases ==&lt;br /&gt;
&lt;br /&gt;
Some of the test cases which will be used to validate our changes are as follows:&lt;br /&gt;
* Printing the command line option selected by the user in the &amp;lt;code&amp;gt;opts.rs&amp;lt;/code&amp;gt;.This ensures if the command line option selected is correctly passed onto the servo.&lt;br /&gt;
  println!(&amp;quot;selected {:?}&amp;quot;, opts.render_api);&lt;br /&gt;
* Printing the command line option selected by the user in the &amp;lt;code&amp;gt;window.rs&amp;lt;/code&amp;gt;.This ensures if the command line option selected is correctly propagated from the servo to the rust-layers.&lt;br /&gt;
* Test if the rust-egl compiles for the linux surface. A successful compilation ensures egl libraries are made available on Linux for rust-layers.&lt;br /&gt;
* Test if selecting an option ES2 though command line on a linux surface, renders a graphic display of ES2.&lt;br /&gt;
&lt;br /&gt;
== Video ==&lt;br /&gt;
A walkthrough of our entire project is available on this link: [Walkthrough Video](https://drive.google.com/file/d/0B9TVPg3YRoHqT2llQ0FfMWNvUEE/view)&lt;br /&gt;
&lt;br /&gt;
=='''Useful libraries'''==&lt;br /&gt;
&lt;br /&gt;
waffle-gl/waffle: A C library for selecting an OpenGL API and window system at runtime.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
1.    https://doc.rust-lang.org/stable/book/&amp;lt;br&amp;gt;&lt;br /&gt;
2.    https://en.wikipedia.org/wiki/Rust_(programming_language)&amp;lt;br&amp;gt;&lt;br /&gt;
3.    https://en.wikipedia.org/wiki/Servo_(layout_engine)&amp;lt;br&amp;gt;&lt;br /&gt;
4.    https://github.com/servo/servo/wiki/Refactor-GLES2-student-project&amp;lt;br&amp;gt;&lt;br /&gt;
5.    http://doc.crates.io/guide.html#overriding-dependencies&amp;lt;br&amp;gt;&lt;br /&gt;
6.    http://rustbyexample.com/&amp;lt;br&amp;gt;&lt;br /&gt;
7.    http://javarevisited.blogspot.com/2014/11/strategy-design-pattern-in-java-using-Enum-Example.html&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=100072</id>
		<title>CSC/ECE 517 Fall 2015/M1506-Refactor-GLES2-Implementation</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=100072"/>
		<updated>2015-12-04T16:46:29Z</updated>

		<summary type="html">&lt;p&gt;Asayal: /* Video */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''' Refactor GLES2 Student Project with SERVO &amp;amp; RUST ''''&lt;br /&gt;
&lt;br /&gt;
Servo is a prototype web browser engine written in the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript RUST]&amp;lt;/span&amp;gt; language.Servo uses a variety of back-end implementations for drawing graphics depending on the operating system.One of such back-end is only compatible with Android right now, and we want to extend and refactor that back-end to enable on all Linux systems..&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
===Servo===&lt;br /&gt;
[https://en.wikipedia.org/wiki/Servo_(layout_engine) Servo]Servo is an open source prototype web browser layout engine being developed by Mozilla, and it is written in [https://www.rust-lang.org/ Rust] language. The main idea is to create a highly parallel environment, in which different components can be handled by fine grained, isolated tasks. The different components can be rendering, HTML parsing, etc. &lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://doc.rust-lang.org/book/README.html Rust] is an open source systems programming language developed by Mozilla. Servo is written in Rust. The main purpose behind it's design is to be thread safe and concurrent. The emphasis is also on speed, safety and control of memory layout.&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
===Setup of Development environment===&lt;br /&gt;
&lt;br /&gt;
* Servo can be built and compiled in the following steps:&lt;br /&gt;
Servo is built with [https://mail.mozilla.org/pipermail/rust-dev/2014-March/009090.html Cargo], the Rust package manager. Mozilla's Mach tools are used to orchestrate the build and other tasks.&lt;br /&gt;
&lt;br /&gt;
    git clone https://github.com/servo/servo&lt;br /&gt;
    cd servo&lt;br /&gt;
    ./mach build --dev&lt;br /&gt;
    ./mach run tests/html/about-mozilla.html&lt;br /&gt;
&lt;br /&gt;
* Next, we need a cargo override for servo to use our local copy of Rust-layers. For this, we created a &amp;lt;code&amp;gt;.cargo&amp;lt;/code&amp;gt; folder in our home directory(same place that servo and Rust-layers reside), and added a &amp;lt;code&amp;gt;config&amp;lt;/code&amp;gt; file to that folder. The content of that config file is a path to our local Rust-layers.&lt;br /&gt;
    paths = [path/to/rust_layers]&lt;br /&gt;
&lt;br /&gt;
===Overview===&lt;br /&gt;
* After building servo and rust-layers successfully, we added a new command line argument in Servo, which would allow user to select the graphics backend (GL or ES2).&lt;br /&gt;
&lt;br /&gt;
Example is as below&lt;br /&gt;
    ./mach run [url] -G GL or ./mach run [url] --graphics GL (for GL)&lt;br /&gt;
    ./mach run [url] -G ES2 or ./mach run [url] --graphics ES2 (for ES2)&lt;br /&gt;
&lt;br /&gt;
* This option selected is passed onto the rust-layers, which is modified to support ES2 for both linux and android versions. Hence, based on the option selected by the user, rust-layers renders the corresponding graphic backend on linux and android targets.To achieve this, the main changes are done in the platform to remove the EGL specific implementation from the Android platform to a more generic one, so that it can be used by both android and linux systems.&lt;br /&gt;
&lt;br /&gt;
=='''Requirement Analysis'''==&lt;br /&gt;
&lt;br /&gt;
Earlier, only [https://en.wikipedia.org/wiki/OpenGL OpenGL] implementation was supported for Android targets and we would be extending the [https://en.wikipedia.org/wiki/OpenGL_ES#2.0 ES2] implementation to support it for Linux targets. &lt;br /&gt;
&lt;br /&gt;
===Initial step===&lt;br /&gt;
&lt;br /&gt;
Our [https://github.com/servo/servo/wiki/Refactor-GLES2-student-project initial step], implemented for the OSS project involved:&lt;br /&gt;
* compile Servo and ensure that it runs on tests/html/about-mozilla.html&lt;br /&gt;
* adding a new command-line option to allow selecting the graphics backend (GL or ES2) in &amp;lt;code&amp;gt;components/utils/opts.rs&amp;lt;/code&amp;gt;&lt;br /&gt;
* clone rust-layers and build it independently of Servo&lt;br /&gt;
* adding a Cargo override for Servo to use the local copy of rust-layers&lt;br /&gt;
&lt;br /&gt;
===Final Requirements===&lt;br /&gt;
&lt;br /&gt;
* Enable selection of the render api working from the command line, so the user can pick whether to use GL or ES2&lt;br /&gt;
* Modify the necessary files so that the current display version of GL or ES2 are returned whenever either of them are selected&lt;br /&gt;
* Make the EGL libs available on Linux apart from android, for rust-layers to compile rust-egl on Linux build.&lt;br /&gt;
* Separate out the EGLImageNativeSurface implementation from Android and move it to EGL&lt;br /&gt;
* Enable use of EGL or GLX for Linux.&lt;br /&gt;
* In conclusion, implement a generic way of supporting EGL for both Linux and Android, such that ES2 is rendered as a display on linux targets as well.&lt;br /&gt;
&lt;br /&gt;
=='''Implementation'''==&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
&lt;br /&gt;
  Servo/components/utils/opts.rs&lt;br /&gt;
added the new command line option to enable user to select the option of GL or ES2 as the rendering backend. The options of GL or ES2 are stored as an enum called RenderApi , such that running the Servo with option --render-api=chosen_option sets the corresponding Api.&lt;br /&gt;
&lt;br /&gt;
  Servo/ports/glutin/window.rs&lt;br /&gt;
&amp;lt;code&amp;gt;gl_version()&amp;lt;/code&amp;gt; function is modified in a way that based on what is selected as the RenderApi option by the user, the corresponding version of the Api is set. To talk more in detail, if the render api is set to GL, it returns the current value (GL 2.1) &amp;amp; if set to ES2, it returns OpenGlEs 2.0.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;native_display()&amp;lt;/code&amp;gt; for linux target is also modified to call the specific NativeDisplay constructor based on the RenderApi option chosen by the user. Hence for the GL case, the existing NativeDisplay::new constructor is called, but if ES2 is selected, NativeDisplay::from_es2() is called, which has been introduced by us in an attempt to support ES2 for the linux platform as well.&lt;br /&gt;
&lt;br /&gt;
===Rust-Layers===&lt;br /&gt;
&lt;br /&gt;
  rust-layers/cargo.toml&lt;br /&gt;
In order to make the egl libraries available to the Linux too, the cargo.toml is edited which defines the different dependencies that various platforms has. Before, the dependency on rust-egl was added only for android targets but now these dependencies have been added for Linux targets as well.&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/platform/egl/surface.rs&lt;br /&gt;
In order to support EGL for both linux and android targets, we moved the implementation of &amp;lt;code&amp;gt;EGLImageNativeSurface&amp;lt;/code&amp;gt; from the android specific &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; and introduced a new folder &amp;lt;code&amp;gt;egl&amp;lt;/code&amp;gt; which contains its own &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; and implements a generic &amp;lt;code&amp;gt;EGLImageNativeSurface &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/lib.rs&lt;br /&gt;
Since egl needs to be supported for linux too now, the extern crate egl call needs to be linked on Linux as well now. Hence in the cfg flag, the target_os=&amp;quot;linux&amp;quot; is added in addition to android.&lt;br /&gt;
&lt;br /&gt;
In the pub mod platform { }, introduced a new pub mod egl {} section to pull in the new &amp;lt;code&amp;gt;egl/surface.rs&amp;lt;/code&amp;gt; implemented for both android and linux targets.&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/platform/linux/surface.rs&lt;br /&gt;
In order to ensure that ES2 is supported for linux targets too, we need to enable the use of EGL &amp;amp; GLX in the linux specific &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt;&lt;br /&gt;
A new enum is created for NativeDisplay which has two different values of &amp;lt;code&amp;gt;EGLDisplayInfo&amp;lt;/code&amp;gt; &amp;amp; &amp;lt;code&amp;gt;GlxDisplayInfo&amp;lt;/code&amp;gt; and respectively, two constructors are created . The existing NativeDisplay::new constructor is modified to return &amp;lt;code&amp;gt;NativeDisplay::Glx(info)&amp;lt;/code&amp;gt; for the GL version , and the NativeDisplay::from_es2() constructor introduced earlier can return &amp;lt;code&amp;gt;NativeDisplay::::Egl(egl_info)&amp;lt;/code&amp;gt; for the ES2 version.&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/platform/surface.rs&lt;br /&gt;
Earlier, the android target was using its own &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; and the linux target was using its own &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt;. But after the implementation of &amp;lt;code&amp;gt;egl/surface.rs&amp;lt;/code&amp;gt;, changes were made to platform &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; which uses the egl surface.rs for both android and linux now.&lt;br /&gt;
&lt;br /&gt;
=='''Design Principles'''==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to modify the egl implementation to support it for linux targets too, we are not modifying the existing functionality of the android platform, instead we have extended the egl implementation to provide support for linux as well.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code currently has specific platform implementations for android and linux, and egl implementation is provided in android. We have extended the egl implementation to a more generic platform surface and divided the functionality for the native display into two small methods such that these methods can be individually called for whichever graphic backend option is chosen. This avoids the need to call the bigger functionality.&lt;br /&gt;
&lt;br /&gt;
=='''Design Pattern'''==&lt;br /&gt;
The aim is to use ES2 implementation of rust layers for both android and Linux. So we need to use a design pattern that will allow us to extend the current implementation to support Linux targets too and give the user the flexibility to choose between the two implementations for rendering the backend.&lt;br /&gt;
&lt;br /&gt;
We propose to use [https://en.wikipedia.org/wiki/Decorator_pattern Decorator] pattern. The decorator pattern gives the user the ability to choose between the implementations that are desired, and attach the corresponding implementation to the target dynamically at runtime.&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:RefactorGLESMozilla1506OODD.png]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Class Diagram==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:Class_diagram_Mozilla_1506.png]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Proposed Test Cases ==&lt;br /&gt;
&lt;br /&gt;
Some of the test cases which will be used to validate our changes are as follows:&lt;br /&gt;
* Printing the command line option selected by the user in the &amp;lt;code&amp;gt;opts.rs&amp;lt;/code&amp;gt;.This ensures if the command line option selected is correctly passed onto the servo.&lt;br /&gt;
  println!(&amp;quot;selected {:?}&amp;quot;, opts.render_api);&lt;br /&gt;
* Printing the command line option selected by the user in the &amp;lt;code&amp;gt;window.rs&amp;lt;/code&amp;gt;.This ensures if the command line option selected is correctly propagated from the servo to the rust-layers.&lt;br /&gt;
* Test if the rust-egl compiles for the linux surface. A successful compilation ensures egl libraries are made available on Linux for rust-layers.&lt;br /&gt;
* Test if selecting an option ES2 though command line on a linux surface, renders a graphic display of ES2.&lt;br /&gt;
&lt;br /&gt;
== Video ==&lt;br /&gt;
A walkthrough of our entire project is available on this link: Walkthrough Video[https://drive.google.com/file/d/0B9TVPg3YRoHqT2llQ0FfMWNvUEE/view]&lt;br /&gt;
&lt;br /&gt;
=='''Useful libraries'''==&lt;br /&gt;
&lt;br /&gt;
waffle-gl/waffle: A C library for selecting an OpenGL API and window system at runtime.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
1.    https://doc.rust-lang.org/stable/book/&amp;lt;br&amp;gt;&lt;br /&gt;
2.    https://en.wikipedia.org/wiki/Rust_(programming_language)&amp;lt;br&amp;gt;&lt;br /&gt;
3.    https://en.wikipedia.org/wiki/Servo_(layout_engine)&amp;lt;br&amp;gt;&lt;br /&gt;
4.    https://github.com/servo/servo/wiki/Refactor-GLES2-student-project&amp;lt;br&amp;gt;&lt;br /&gt;
5.    http://doc.crates.io/guide.html#overriding-dependencies&amp;lt;br&amp;gt;&lt;br /&gt;
6.    http://rustbyexample.com/&amp;lt;br&amp;gt;&lt;br /&gt;
7.    http://javarevisited.blogspot.com/2014/11/strategy-design-pattern-in-java-using-Enum-Example.html&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=100071</id>
		<title>CSC/ECE 517 Fall 2015/M1506-Refactor-GLES2-Implementation</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=100071"/>
		<updated>2015-12-04T16:46:02Z</updated>

		<summary type="html">&lt;p&gt;Asayal: /* Video */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''' Refactor GLES2 Student Project with SERVO &amp;amp; RUST ''''&lt;br /&gt;
&lt;br /&gt;
Servo is a prototype web browser engine written in the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript RUST]&amp;lt;/span&amp;gt; language.Servo uses a variety of back-end implementations for drawing graphics depending on the operating system.One of such back-end is only compatible with Android right now, and we want to extend and refactor that back-end to enable on all Linux systems..&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
===Servo===&lt;br /&gt;
[https://en.wikipedia.org/wiki/Servo_(layout_engine) Servo]Servo is an open source prototype web browser layout engine being developed by Mozilla, and it is written in [https://www.rust-lang.org/ Rust] language. The main idea is to create a highly parallel environment, in which different components can be handled by fine grained, isolated tasks. The different components can be rendering, HTML parsing, etc. &lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://doc.rust-lang.org/book/README.html Rust] is an open source systems programming language developed by Mozilla. Servo is written in Rust. The main purpose behind it's design is to be thread safe and concurrent. The emphasis is also on speed, safety and control of memory layout.&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
===Setup of Development environment===&lt;br /&gt;
&lt;br /&gt;
* Servo can be built and compiled in the following steps:&lt;br /&gt;
Servo is built with [https://mail.mozilla.org/pipermail/rust-dev/2014-March/009090.html Cargo], the Rust package manager. Mozilla's Mach tools are used to orchestrate the build and other tasks.&lt;br /&gt;
&lt;br /&gt;
    git clone https://github.com/servo/servo&lt;br /&gt;
    cd servo&lt;br /&gt;
    ./mach build --dev&lt;br /&gt;
    ./mach run tests/html/about-mozilla.html&lt;br /&gt;
&lt;br /&gt;
* Next, we need a cargo override for servo to use our local copy of Rust-layers. For this, we created a &amp;lt;code&amp;gt;.cargo&amp;lt;/code&amp;gt; folder in our home directory(same place that servo and Rust-layers reside), and added a &amp;lt;code&amp;gt;config&amp;lt;/code&amp;gt; file to that folder. The content of that config file is a path to our local Rust-layers.&lt;br /&gt;
    paths = [path/to/rust_layers]&lt;br /&gt;
&lt;br /&gt;
===Overview===&lt;br /&gt;
* After building servo and rust-layers successfully, we added a new command line argument in Servo, which would allow user to select the graphics backend (GL or ES2).&lt;br /&gt;
&lt;br /&gt;
Example is as below&lt;br /&gt;
    ./mach run [url] -G GL or ./mach run [url] --graphics GL (for GL)&lt;br /&gt;
    ./mach run [url] -G ES2 or ./mach run [url] --graphics ES2 (for ES2)&lt;br /&gt;
&lt;br /&gt;
* This option selected is passed onto the rust-layers, which is modified to support ES2 for both linux and android versions. Hence, based on the option selected by the user, rust-layers renders the corresponding graphic backend on linux and android targets.To achieve this, the main changes are done in the platform to remove the EGL specific implementation from the Android platform to a more generic one, so that it can be used by both android and linux systems.&lt;br /&gt;
&lt;br /&gt;
=='''Requirement Analysis'''==&lt;br /&gt;
&lt;br /&gt;
Earlier, only [https://en.wikipedia.org/wiki/OpenGL OpenGL] implementation was supported for Android targets and we would be extending the [https://en.wikipedia.org/wiki/OpenGL_ES#2.0 ES2] implementation to support it for Linux targets. &lt;br /&gt;
&lt;br /&gt;
===Initial step===&lt;br /&gt;
&lt;br /&gt;
Our [https://github.com/servo/servo/wiki/Refactor-GLES2-student-project initial step], implemented for the OSS project involved:&lt;br /&gt;
* compile Servo and ensure that it runs on tests/html/about-mozilla.html&lt;br /&gt;
* adding a new command-line option to allow selecting the graphics backend (GL or ES2) in &amp;lt;code&amp;gt;components/utils/opts.rs&amp;lt;/code&amp;gt;&lt;br /&gt;
* clone rust-layers and build it independently of Servo&lt;br /&gt;
* adding a Cargo override for Servo to use the local copy of rust-layers&lt;br /&gt;
&lt;br /&gt;
===Final Requirements===&lt;br /&gt;
&lt;br /&gt;
* Enable selection of the render api working from the command line, so the user can pick whether to use GL or ES2&lt;br /&gt;
* Modify the necessary files so that the current display version of GL or ES2 are returned whenever either of them are selected&lt;br /&gt;
* Make the EGL libs available on Linux apart from android, for rust-layers to compile rust-egl on Linux build.&lt;br /&gt;
* Separate out the EGLImageNativeSurface implementation from Android and move it to EGL&lt;br /&gt;
* Enable use of EGL or GLX for Linux.&lt;br /&gt;
* In conclusion, implement a generic way of supporting EGL for both Linux and Android, such that ES2 is rendered as a display on linux targets as well.&lt;br /&gt;
&lt;br /&gt;
=='''Implementation'''==&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
&lt;br /&gt;
  Servo/components/utils/opts.rs&lt;br /&gt;
added the new command line option to enable user to select the option of GL or ES2 as the rendering backend. The options of GL or ES2 are stored as an enum called RenderApi , such that running the Servo with option --render-api=chosen_option sets the corresponding Api.&lt;br /&gt;
&lt;br /&gt;
  Servo/ports/glutin/window.rs&lt;br /&gt;
&amp;lt;code&amp;gt;gl_version()&amp;lt;/code&amp;gt; function is modified in a way that based on what is selected as the RenderApi option by the user, the corresponding version of the Api is set. To talk more in detail, if the render api is set to GL, it returns the current value (GL 2.1) &amp;amp; if set to ES2, it returns OpenGlEs 2.0.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;native_display()&amp;lt;/code&amp;gt; for linux target is also modified to call the specific NativeDisplay constructor based on the RenderApi option chosen by the user. Hence for the GL case, the existing NativeDisplay::new constructor is called, but if ES2 is selected, NativeDisplay::from_es2() is called, which has been introduced by us in an attempt to support ES2 for the linux platform as well.&lt;br /&gt;
&lt;br /&gt;
===Rust-Layers===&lt;br /&gt;
&lt;br /&gt;
  rust-layers/cargo.toml&lt;br /&gt;
In order to make the egl libraries available to the Linux too, the cargo.toml is edited which defines the different dependencies that various platforms has. Before, the dependency on rust-egl was added only for android targets but now these dependencies have been added for Linux targets as well.&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/platform/egl/surface.rs&lt;br /&gt;
In order to support EGL for both linux and android targets, we moved the implementation of &amp;lt;code&amp;gt;EGLImageNativeSurface&amp;lt;/code&amp;gt; from the android specific &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; and introduced a new folder &amp;lt;code&amp;gt;egl&amp;lt;/code&amp;gt; which contains its own &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; and implements a generic &amp;lt;code&amp;gt;EGLImageNativeSurface &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/lib.rs&lt;br /&gt;
Since egl needs to be supported for linux too now, the extern crate egl call needs to be linked on Linux as well now. Hence in the cfg flag, the target_os=&amp;quot;linux&amp;quot; is added in addition to android.&lt;br /&gt;
&lt;br /&gt;
In the pub mod platform { }, introduced a new pub mod egl {} section to pull in the new &amp;lt;code&amp;gt;egl/surface.rs&amp;lt;/code&amp;gt; implemented for both android and linux targets.&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/platform/linux/surface.rs&lt;br /&gt;
In order to ensure that ES2 is supported for linux targets too, we need to enable the use of EGL &amp;amp; GLX in the linux specific &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt;&lt;br /&gt;
A new enum is created for NativeDisplay which has two different values of &amp;lt;code&amp;gt;EGLDisplayInfo&amp;lt;/code&amp;gt; &amp;amp; &amp;lt;code&amp;gt;GlxDisplayInfo&amp;lt;/code&amp;gt; and respectively, two constructors are created . The existing NativeDisplay::new constructor is modified to return &amp;lt;code&amp;gt;NativeDisplay::Glx(info)&amp;lt;/code&amp;gt; for the GL version , and the NativeDisplay::from_es2() constructor introduced earlier can return &amp;lt;code&amp;gt;NativeDisplay::::Egl(egl_info)&amp;lt;/code&amp;gt; for the ES2 version.&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/platform/surface.rs&lt;br /&gt;
Earlier, the android target was using its own &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; and the linux target was using its own &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt;. But after the implementation of &amp;lt;code&amp;gt;egl/surface.rs&amp;lt;/code&amp;gt;, changes were made to platform &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; which uses the egl surface.rs for both android and linux now.&lt;br /&gt;
&lt;br /&gt;
=='''Design Principles'''==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to modify the egl implementation to support it for linux targets too, we are not modifying the existing functionality of the android platform, instead we have extended the egl implementation to provide support for linux as well.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code currently has specific platform implementations for android and linux, and egl implementation is provided in android. We have extended the egl implementation to a more generic platform surface and divided the functionality for the native display into two small methods such that these methods can be individually called for whichever graphic backend option is chosen. This avoids the need to call the bigger functionality.&lt;br /&gt;
&lt;br /&gt;
=='''Design Pattern'''==&lt;br /&gt;
The aim is to use ES2 implementation of rust layers for both android and Linux. So we need to use a design pattern that will allow us to extend the current implementation to support Linux targets too and give the user the flexibility to choose between the two implementations for rendering the backend.&lt;br /&gt;
&lt;br /&gt;
We propose to use [https://en.wikipedia.org/wiki/Decorator_pattern Decorator] pattern. The decorator pattern gives the user the ability to choose between the implementations that are desired, and attach the corresponding implementation to the target dynamically at runtime.&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:RefactorGLESMozilla1506OODD.png]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Class Diagram==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:Class_diagram_Mozilla_1506.png]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Proposed Test Cases ==&lt;br /&gt;
&lt;br /&gt;
Some of the test cases which will be used to validate our changes are as follows:&lt;br /&gt;
* Printing the command line option selected by the user in the &amp;lt;code&amp;gt;opts.rs&amp;lt;/code&amp;gt;.This ensures if the command line option selected is correctly passed onto the servo.&lt;br /&gt;
  println!(&amp;quot;selected {:?}&amp;quot;, opts.render_api);&lt;br /&gt;
* Printing the command line option selected by the user in the &amp;lt;code&amp;gt;window.rs&amp;lt;/code&amp;gt;.This ensures if the command line option selected is correctly propagated from the servo to the rust-layers.&lt;br /&gt;
* Test if the rust-egl compiles for the linux surface. A successful compilation ensures egl libraries are made available on Linux for rust-layers.&lt;br /&gt;
* Test if selecting an option ES2 though command line on a linux surface, renders a graphic display of ES2.&lt;br /&gt;
&lt;br /&gt;
== Video ==&lt;br /&gt;
A walkthrough of our entire project is available on this link: [https://drive.google.com/file/d/0B9TVPg3YRoHqT2llQ0FfMWNvUEE/view]&lt;br /&gt;
&lt;br /&gt;
=='''Useful libraries'''==&lt;br /&gt;
&lt;br /&gt;
waffle-gl/waffle: A C library for selecting an OpenGL API and window system at runtime.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
1.    https://doc.rust-lang.org/stable/book/&amp;lt;br&amp;gt;&lt;br /&gt;
2.    https://en.wikipedia.org/wiki/Rust_(programming_language)&amp;lt;br&amp;gt;&lt;br /&gt;
3.    https://en.wikipedia.org/wiki/Servo_(layout_engine)&amp;lt;br&amp;gt;&lt;br /&gt;
4.    https://github.com/servo/servo/wiki/Refactor-GLES2-student-project&amp;lt;br&amp;gt;&lt;br /&gt;
5.    http://doc.crates.io/guide.html#overriding-dependencies&amp;lt;br&amp;gt;&lt;br /&gt;
6.    http://rustbyexample.com/&amp;lt;br&amp;gt;&lt;br /&gt;
7.    http://javarevisited.blogspot.com/2014/11/strategy-design-pattern-in-java-using-Enum-Example.html&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=100070</id>
		<title>CSC/ECE 517 Fall 2015/M1506-Refactor-GLES2-Implementation</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=100070"/>
		<updated>2015-12-04T16:44:48Z</updated>

		<summary type="html">&lt;p&gt;Asayal: /* Flowchart describing Project Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''' Refactor GLES2 Student Project with SERVO &amp;amp; RUST ''''&lt;br /&gt;
&lt;br /&gt;
Servo is a prototype web browser engine written in the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript RUST]&amp;lt;/span&amp;gt; language.Servo uses a variety of back-end implementations for drawing graphics depending on the operating system.One of such back-end is only compatible with Android right now, and we want to extend and refactor that back-end to enable on all Linux systems..&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
===Servo===&lt;br /&gt;
[https://en.wikipedia.org/wiki/Servo_(layout_engine) Servo]Servo is an open source prototype web browser layout engine being developed by Mozilla, and it is written in [https://www.rust-lang.org/ Rust] language. The main idea is to create a highly parallel environment, in which different components can be handled by fine grained, isolated tasks. The different components can be rendering, HTML parsing, etc. &lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://doc.rust-lang.org/book/README.html Rust] is an open source systems programming language developed by Mozilla. Servo is written in Rust. The main purpose behind it's design is to be thread safe and concurrent. The emphasis is also on speed, safety and control of memory layout.&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
===Setup of Development environment===&lt;br /&gt;
&lt;br /&gt;
* Servo can be built and compiled in the following steps:&lt;br /&gt;
Servo is built with [https://mail.mozilla.org/pipermail/rust-dev/2014-March/009090.html Cargo], the Rust package manager. Mozilla's Mach tools are used to orchestrate the build and other tasks.&lt;br /&gt;
&lt;br /&gt;
    git clone https://github.com/servo/servo&lt;br /&gt;
    cd servo&lt;br /&gt;
    ./mach build --dev&lt;br /&gt;
    ./mach run tests/html/about-mozilla.html&lt;br /&gt;
&lt;br /&gt;
* Next, we need a cargo override for servo to use our local copy of Rust-layers. For this, we created a &amp;lt;code&amp;gt;.cargo&amp;lt;/code&amp;gt; folder in our home directory(same place that servo and Rust-layers reside), and added a &amp;lt;code&amp;gt;config&amp;lt;/code&amp;gt; file to that folder. The content of that config file is a path to our local Rust-layers.&lt;br /&gt;
    paths = [path/to/rust_layers]&lt;br /&gt;
&lt;br /&gt;
===Overview===&lt;br /&gt;
* After building servo and rust-layers successfully, we added a new command line argument in Servo, which would allow user to select the graphics backend (GL or ES2).&lt;br /&gt;
&lt;br /&gt;
Example is as below&lt;br /&gt;
    ./mach run [url] -G GL or ./mach run [url] --graphics GL (for GL)&lt;br /&gt;
    ./mach run [url] -G ES2 or ./mach run [url] --graphics ES2 (for ES2)&lt;br /&gt;
&lt;br /&gt;
* This option selected is passed onto the rust-layers, which is modified to support ES2 for both linux and android versions. Hence, based on the option selected by the user, rust-layers renders the corresponding graphic backend on linux and android targets.To achieve this, the main changes are done in the platform to remove the EGL specific implementation from the Android platform to a more generic one, so that it can be used by both android and linux systems.&lt;br /&gt;
&lt;br /&gt;
=='''Requirement Analysis'''==&lt;br /&gt;
&lt;br /&gt;
Earlier, only [https://en.wikipedia.org/wiki/OpenGL OpenGL] implementation was supported for Android targets and we would be extending the [https://en.wikipedia.org/wiki/OpenGL_ES#2.0 ES2] implementation to support it for Linux targets. &lt;br /&gt;
&lt;br /&gt;
===Initial step===&lt;br /&gt;
&lt;br /&gt;
Our [https://github.com/servo/servo/wiki/Refactor-GLES2-student-project initial step], implemented for the OSS project involved:&lt;br /&gt;
* compile Servo and ensure that it runs on tests/html/about-mozilla.html&lt;br /&gt;
* adding a new command-line option to allow selecting the graphics backend (GL or ES2) in &amp;lt;code&amp;gt;components/utils/opts.rs&amp;lt;/code&amp;gt;&lt;br /&gt;
* clone rust-layers and build it independently of Servo&lt;br /&gt;
* adding a Cargo override for Servo to use the local copy of rust-layers&lt;br /&gt;
&lt;br /&gt;
===Final Requirements===&lt;br /&gt;
&lt;br /&gt;
* Enable selection of the render api working from the command line, so the user can pick whether to use GL or ES2&lt;br /&gt;
* Modify the necessary files so that the current display version of GL or ES2 are returned whenever either of them are selected&lt;br /&gt;
* Make the EGL libs available on Linux apart from android, for rust-layers to compile rust-egl on Linux build.&lt;br /&gt;
* Separate out the EGLImageNativeSurface implementation from Android and move it to EGL&lt;br /&gt;
* Enable use of EGL or GLX for Linux.&lt;br /&gt;
* In conclusion, implement a generic way of supporting EGL for both Linux and Android, such that ES2 is rendered as a display on linux targets as well.&lt;br /&gt;
&lt;br /&gt;
=='''Implementation'''==&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
&lt;br /&gt;
  Servo/components/utils/opts.rs&lt;br /&gt;
added the new command line option to enable user to select the option of GL or ES2 as the rendering backend. The options of GL or ES2 are stored as an enum called RenderApi , such that running the Servo with option --render-api=chosen_option sets the corresponding Api.&lt;br /&gt;
&lt;br /&gt;
  Servo/ports/glutin/window.rs&lt;br /&gt;
&amp;lt;code&amp;gt;gl_version()&amp;lt;/code&amp;gt; function is modified in a way that based on what is selected as the RenderApi option by the user, the corresponding version of the Api is set. To talk more in detail, if the render api is set to GL, it returns the current value (GL 2.1) &amp;amp; if set to ES2, it returns OpenGlEs 2.0.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;native_display()&amp;lt;/code&amp;gt; for linux target is also modified to call the specific NativeDisplay constructor based on the RenderApi option chosen by the user. Hence for the GL case, the existing NativeDisplay::new constructor is called, but if ES2 is selected, NativeDisplay::from_es2() is called, which has been introduced by us in an attempt to support ES2 for the linux platform as well.&lt;br /&gt;
&lt;br /&gt;
===Rust-Layers===&lt;br /&gt;
&lt;br /&gt;
  rust-layers/cargo.toml&lt;br /&gt;
In order to make the egl libraries available to the Linux too, the cargo.toml is edited which defines the different dependencies that various platforms has. Before, the dependency on rust-egl was added only for android targets but now these dependencies have been added for Linux targets as well.&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/platform/egl/surface.rs&lt;br /&gt;
In order to support EGL for both linux and android targets, we moved the implementation of &amp;lt;code&amp;gt;EGLImageNativeSurface&amp;lt;/code&amp;gt; from the android specific &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; and introduced a new folder &amp;lt;code&amp;gt;egl&amp;lt;/code&amp;gt; which contains its own &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; and implements a generic &amp;lt;code&amp;gt;EGLImageNativeSurface &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/lib.rs&lt;br /&gt;
Since egl needs to be supported for linux too now, the extern crate egl call needs to be linked on Linux as well now. Hence in the cfg flag, the target_os=&amp;quot;linux&amp;quot; is added in addition to android.&lt;br /&gt;
&lt;br /&gt;
In the pub mod platform { }, introduced a new pub mod egl {} section to pull in the new &amp;lt;code&amp;gt;egl/surface.rs&amp;lt;/code&amp;gt; implemented for both android and linux targets.&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/platform/linux/surface.rs&lt;br /&gt;
In order to ensure that ES2 is supported for linux targets too, we need to enable the use of EGL &amp;amp; GLX in the linux specific &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt;&lt;br /&gt;
A new enum is created for NativeDisplay which has two different values of &amp;lt;code&amp;gt;EGLDisplayInfo&amp;lt;/code&amp;gt; &amp;amp; &amp;lt;code&amp;gt;GlxDisplayInfo&amp;lt;/code&amp;gt; and respectively, two constructors are created . The existing NativeDisplay::new constructor is modified to return &amp;lt;code&amp;gt;NativeDisplay::Glx(info)&amp;lt;/code&amp;gt; for the GL version , and the NativeDisplay::from_es2() constructor introduced earlier can return &amp;lt;code&amp;gt;NativeDisplay::::Egl(egl_info)&amp;lt;/code&amp;gt; for the ES2 version.&lt;br /&gt;
&lt;br /&gt;
  rust-layers/src/platform/surface.rs&lt;br /&gt;
Earlier, the android target was using its own &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; and the linux target was using its own &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt;. But after the implementation of &amp;lt;code&amp;gt;egl/surface.rs&amp;lt;/code&amp;gt;, changes were made to platform &amp;lt;code&amp;gt;surface.rs&amp;lt;/code&amp;gt; which uses the egl surface.rs for both android and linux now.&lt;br /&gt;
&lt;br /&gt;
=='''Design Principles'''==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to modify the egl implementation to support it for linux targets too, we are not modifying the existing functionality of the android platform, instead we have extended the egl implementation to provide support for linux as well.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code currently has specific platform implementations for android and linux, and egl implementation is provided in android. We have extended the egl implementation to a more generic platform surface and divided the functionality for the native display into two small methods such that these methods can be individually called for whichever graphic backend option is chosen. This avoids the need to call the bigger functionality.&lt;br /&gt;
&lt;br /&gt;
=='''Design Pattern'''==&lt;br /&gt;
The aim is to use ES2 implementation of rust layers for both android and Linux. So we need to use a design pattern that will allow us to extend the current implementation to support Linux targets too and give the user the flexibility to choose between the two implementations for rendering the backend.&lt;br /&gt;
&lt;br /&gt;
We propose to use [https://en.wikipedia.org/wiki/Decorator_pattern Decorator] pattern. The decorator pattern gives the user the ability to choose between the implementations that are desired, and attach the corresponding implementation to the target dynamically at runtime.&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:RefactorGLESMozilla1506OODD.png]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Class Diagram==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:Class_diagram_Mozilla_1506.png]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Proposed Test Cases ==&lt;br /&gt;
&lt;br /&gt;
Some of the test cases which will be used to validate our changes are as follows:&lt;br /&gt;
* Printing the command line option selected by the user in the &amp;lt;code&amp;gt;opts.rs&amp;lt;/code&amp;gt;.This ensures if the command line option selected is correctly passed onto the servo.&lt;br /&gt;
  println!(&amp;quot;selected {:?}&amp;quot;, opts.render_api);&lt;br /&gt;
* Printing the command line option selected by the user in the &amp;lt;code&amp;gt;window.rs&amp;lt;/code&amp;gt;.This ensures if the command line option selected is correctly propagated from the servo to the rust-layers.&lt;br /&gt;
* Test if the rust-egl compiles for the linux surface. A successful compilation ensures egl libraries are made available on Linux for rust-layers.&lt;br /&gt;
* Test if selecting an option ES2 though command line on a linux surface, renders a graphic display of ES2.&lt;br /&gt;
&lt;br /&gt;
== Video ==&lt;br /&gt;
A walkthrough of our entire project is available on this link: [https://www.youtube.com/watch?v=rq8MvpR1JyI Final Project Walkthrough]&lt;br /&gt;
&lt;br /&gt;
=='''Useful libraries'''==&lt;br /&gt;
&lt;br /&gt;
waffle-gl/waffle: A C library for selecting an OpenGL API and window system at runtime.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
1.    https://doc.rust-lang.org/stable/book/&amp;lt;br&amp;gt;&lt;br /&gt;
2.    https://en.wikipedia.org/wiki/Rust_(programming_language)&amp;lt;br&amp;gt;&lt;br /&gt;
3.    https://en.wikipedia.org/wiki/Servo_(layout_engine)&amp;lt;br&amp;gt;&lt;br /&gt;
4.    https://github.com/servo/servo/wiki/Refactor-GLES2-student-project&amp;lt;br&amp;gt;&lt;br /&gt;
5.    http://doc.crates.io/guide.html#overriding-dependencies&amp;lt;br&amp;gt;&lt;br /&gt;
6.    http://rustbyexample.com/&amp;lt;br&amp;gt;&lt;br /&gt;
7.    http://javarevisited.blogspot.com/2014/11/strategy-design-pattern-in-java-using-Enum-Example.html&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:RefactorGLESMozilla1506OODD.png&amp;diff=100069</id>
		<title>File:RefactorGLESMozilla1506OODD.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:RefactorGLESMozilla1506OODD.png&amp;diff=100069"/>
		<updated>2015-12-04T16:44:17Z</updated>

		<summary type="html">&lt;p&gt;Asayal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=100024</id>
		<title>CSC/ECE 517 Fall 2015/M1506-Refactor-GLES2-Implementation</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=100024"/>
		<updated>2015-12-03T21:49:26Z</updated>

		<summary type="html">&lt;p&gt;Asayal: /* Files modified */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''' Refactor GLES2 Student Project with SERVO &amp;amp; RUST ''''&lt;br /&gt;
&lt;br /&gt;
Servo is a prototype web browser engine written in the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript RUST]&amp;lt;/span&amp;gt; language.Servo uses a variety of back-end implementations for drawing graphics depending on the operating system.One of such back-end is only compatible with Android right now, and we want to extend and refactor that back-end to enable on all Linux systems..&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
===Servo===&lt;br /&gt;
[https://en.wikipedia.org/wiki/Servo_(layout_engine) Servo]Servo is an open source prototype web browser layout engine being developed by Mozilla, and it is written in [https://www.rust-lang.org/ Rust] language. The main idea is to create a highly parallel environment, in which different components can be handled by fine grained, isolated tasks. The different components can be rendering, HTML parsing, etc. &lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://doc.rust-lang.org/book/README.html Rust] is an open source systems programming language developed by Mozilla. Servo is written in Rust. The main purpose behind it's design is to be thread safe and concurrent. The emphasis is also on speed, safety and control of memory layout.&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
* The project requirement initially stated that we build and Compile servo. Following are the steps for this:&lt;br /&gt;
Servo is built with [https://mail.mozilla.org/pipermail/rust-dev/2014-March/009090.html Cargo], the Rust package manager. Mozilla's Mach tools are used to orchestrate the build and other tasks.&lt;br /&gt;
&lt;br /&gt;
    git clone https://github.com/servo/servo&lt;br /&gt;
    cd servo&lt;br /&gt;
    ./mach build --dev&lt;br /&gt;
    ./mach run tests/html/about-mozilla.html&lt;br /&gt;
&lt;br /&gt;
* The next requirement was to build the Rust-layers independently of Servo. For this, we &lt;br /&gt;
* Next, we had to over-ride cargo to use our local copy of Rust-layers, so we had to add a cargo override to it. For this, we created a &amp;lt;code&amp;gt;.cargo&amp;lt;/code&amp;gt; folder in our home directory(same place that servo and Rust-layers reside), and added a &amp;lt;code&amp;gt;config&amp;lt;/code&amp;gt; file to that folder. The content of that config file is a path to our local Rust-layers.&lt;br /&gt;
    paths = [path/to/rust_layers]&lt;br /&gt;
* Next, we had to add a new command line argument in Servo, which would allow selecting the graphics background (GL or ES2). For this, we made the following changes:&lt;br /&gt;
- We added a command line option which lets the user enter the option &amp;lt;code&amp;gt;-E&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;--es2&amp;lt;/code&amp;gt; if the user wants to set ES2 as the graphic back end option. GL is set by default, hence if the user doesn't give any argument, Gl is selected as the graphic back end option. Example is as below&lt;br /&gt;
    ./mach run [url] -E&lt;br /&gt;
* Next, we had to add a flag in Rust-layers. This change was made in the file [https://github.com/prashantgupta24/rust-layers/blob/master/src/rendergl.rs Rust/src/rendergl.rs] in the &amp;lt;code&amp;gt;RenderContext::new&amp;lt;/code&amp;gt; function. For this, we did the following change:&lt;br /&gt;
- We defined an enum &amp;lt;code&amp;gt;GraphicOption&amp;lt;/code&amp;gt; which defined two options &amp;lt;code&amp;gt;GL&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ES2&amp;lt;/code&amp;gt; and then based on the boolean value from the servo &amp;lt;code&amp;gt;opts.rs&amp;lt;/code&amp;gt;, we set a variable with the respective enum value &amp;lt;code&amp;gt;GL&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;ES2&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Then, we had to use the new command line option to pass the selected graphics back-end option to the Rust-layers context which we created in the previous step. For this we made changes to the [https://github.com/prashantgupta24/servo/blob/master/components/compositing/compositor.rs compositor.rs] in Compositing folder which is how Servo interacts with the Rust layers. The command line option is passed through the &amp;lt;code&amp;gt;initialize_compositing&amp;lt;/code&amp;gt; function.&lt;br /&gt;
* Now we need to change the platform implementation in [https://github.com/servo/rust-layers/blob/master/src/platform/surface.rs surface.rs] and provide a generic implementation to dynamically select between GL &amp;amp; ES2.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:RefactorGLESMozilla.png]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Requirement Analysis'''==&lt;br /&gt;
&lt;br /&gt;
Earlier, only [https://en.wikipedia.org/wiki/OpenGL OpenGL] implementation was supported for Android targets and we would be extending the [https://en.wikipedia.org/wiki/OpenGL_ES#2.0 ES2] implementation to support it for Linux targets. As a part of the final project, we accomplished the following steps:&lt;br /&gt;
&lt;br /&gt;
* Enable selection of the render api working from the command line, so the user can pick whether to use GL or ES2&lt;br /&gt;
* Modify the necessary files so that the current version of GL or ES2 are returned whenever either of them are selected&lt;br /&gt;
* Make the EGL libs available on Linux for rust-layers to compile rust-egl on Linux build.&lt;br /&gt;
* Separate out the EGLImageNativeSurface implementation from Android and move it to EGL&lt;br /&gt;
* Enable use of EGL or GLX for Linux&lt;br /&gt;
&lt;br /&gt;
=='''Implementation'''==&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
&lt;br /&gt;
  Servo/components/utils/opts.rs&lt;br /&gt;
added the new command line option to enable user to select the option of GL or ES2 as the rendering backend. The options of GL or ES2 are stored as an enum called RenderApi , such that running the Servo with option --render-api=chosen_option sets the corresponding Api.&lt;br /&gt;
&lt;br /&gt;
  Servo/ports/glutin/window.rs&lt;br /&gt;
&amp;lt;code&amp;gt;gl_version()&amp;lt;/code&amp;gt; function is modified in a way that based on what is selected as the RenderApi option by the user, the corresponding version of the Api is set. To talk more in detail, if the render api is set to GL, it returns the current value (GL 2.1) &amp;amp; if set to ES2, it returns OpenGlEs 2.0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
rust-layers/src/platform/surface.rs: providing generic GL implementation that can dynamically select between the 2 interfaces.&lt;br /&gt;
&lt;br /&gt;
=='''Useful libraries'''==&lt;br /&gt;
&lt;br /&gt;
waffle-gl/waffle: A C library for selecting an OpenGL API and window system at runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Design Pattern'''==&lt;br /&gt;
The aim is to use ES2 implementation of rust layers for both android and Linux. So we need to use a design pattern that will allow us to extend the current implementation to support Linux targets too and give the user the flexibility to choose between the two implementations for rendering the backend.&lt;br /&gt;
&lt;br /&gt;
We propose to use [https://en.wikipedia.org/wiki/Decorator_pattern Decorator] pattern. The decorator pattern gives the user the ability to choose between the implementations that are desired, and attach the corresponding implementation to the target dynamically at runtime.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
1.    https://doc.rust-lang.org/stable/book/&amp;lt;br&amp;gt;&lt;br /&gt;
2.    https://en.wikipedia.org/wiki/Rust_(programming_language)&amp;lt;br&amp;gt;&lt;br /&gt;
3.    https://en.wikipedia.org/wiki/Servo_(layout_engine)&amp;lt;br&amp;gt;&lt;br /&gt;
4.    https://github.com/servo/servo/wiki/Refactor-GLES2-student-project&amp;lt;br&amp;gt;&lt;br /&gt;
5.    http://doc.crates.io/guide.html#overriding-dependencies&amp;lt;br&amp;gt;&lt;br /&gt;
6.    http://rustbyexample.com/&amp;lt;br&amp;gt;&lt;br /&gt;
7.    http://javarevisited.blogspot.com/2014/11/strategy-design-pattern-in-java-using-Enum-Example.html&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=100022</id>
		<title>CSC/ECE 517 Fall 2015/M1506-Refactor-GLES2-Implementation</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=100022"/>
		<updated>2015-12-03T21:38:20Z</updated>

		<summary type="html">&lt;p&gt;Asayal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''' Refactor GLES2 Student Project with SERVO &amp;amp; RUST ''''&lt;br /&gt;
&lt;br /&gt;
Servo is a prototype web browser engine written in the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript RUST]&amp;lt;/span&amp;gt; language.Servo uses a variety of back-end implementations for drawing graphics depending on the operating system.One of such back-end is only compatible with Android right now, and we want to extend and refactor that back-end to enable on all Linux systems..&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
===Servo===&lt;br /&gt;
[https://en.wikipedia.org/wiki/Servo_(layout_engine) Servo]Servo is an open source prototype web browser layout engine being developed by Mozilla, and it is written in [https://www.rust-lang.org/ Rust] language. The main idea is to create a highly parallel environment, in which different components can be handled by fine grained, isolated tasks. The different components can be rendering, HTML parsing, etc. &lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://doc.rust-lang.org/book/README.html Rust] is an open source systems programming language developed by Mozilla. Servo is written in Rust. The main purpose behind it's design is to be thread safe and concurrent. The emphasis is also on speed, safety and control of memory layout.&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
* The project requirement initially stated that we build and Compile servo. Following are the steps for this:&lt;br /&gt;
Servo is built with [https://mail.mozilla.org/pipermail/rust-dev/2014-March/009090.html Cargo], the Rust package manager. Mozilla's Mach tools are used to orchestrate the build and other tasks.&lt;br /&gt;
&lt;br /&gt;
    git clone https://github.com/servo/servo&lt;br /&gt;
    cd servo&lt;br /&gt;
    ./mach build --dev&lt;br /&gt;
    ./mach run tests/html/about-mozilla.html&lt;br /&gt;
&lt;br /&gt;
* The next requirement was to build the Rust-layers independently of Servo. For this, we &lt;br /&gt;
* Next, we had to over-ride cargo to use our local copy of Rust-layers, so we had to add a cargo override to it. For this, we created a &amp;lt;code&amp;gt;.cargo&amp;lt;/code&amp;gt; folder in our home directory(same place that servo and Rust-layers reside), and added a &amp;lt;code&amp;gt;config&amp;lt;/code&amp;gt; file to that folder. The content of that config file is a path to our local Rust-layers.&lt;br /&gt;
    paths = [path/to/rust_layers]&lt;br /&gt;
* Next, we had to add a new command line argument in Servo, which would allow selecting the graphics background (GL or ES2). For this, we made the following changes:&lt;br /&gt;
- We added a command line option which lets the user enter the option &amp;lt;code&amp;gt;-E&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;--es2&amp;lt;/code&amp;gt; if the user wants to set ES2 as the graphic back end option. GL is set by default, hence if the user doesn't give any argument, Gl is selected as the graphic back end option. Example is as below&lt;br /&gt;
    ./mach run [url] -E&lt;br /&gt;
* Next, we had to add a flag in Rust-layers. This change was made in the file [https://github.com/prashantgupta24/rust-layers/blob/master/src/rendergl.rs Rust/src/rendergl.rs] in the &amp;lt;code&amp;gt;RenderContext::new&amp;lt;/code&amp;gt; function. For this, we did the following change:&lt;br /&gt;
- We defined an enum &amp;lt;code&amp;gt;GraphicOption&amp;lt;/code&amp;gt; which defined two options &amp;lt;code&amp;gt;GL&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ES2&amp;lt;/code&amp;gt; and then based on the boolean value from the servo &amp;lt;code&amp;gt;opts.rs&amp;lt;/code&amp;gt;, we set a variable with the respective enum value &amp;lt;code&amp;gt;GL&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;ES2&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Then, we had to use the new command line option to pass the selected graphics back-end option to the Rust-layers context which we created in the previous step. For this we made changes to the [https://github.com/prashantgupta24/servo/blob/master/components/compositing/compositor.rs compositor.rs] in Compositing folder which is how Servo interacts with the Rust layers. The command line option is passed through the &amp;lt;code&amp;gt;initialize_compositing&amp;lt;/code&amp;gt; function.&lt;br /&gt;
* Now we need to change the platform implementation in [https://github.com/servo/rust-layers/blob/master/src/platform/surface.rs surface.rs] and provide a generic implementation to dynamically select between GL &amp;amp; ES2.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:RefactorGLESMozilla.png]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Requirement Analysis'''==&lt;br /&gt;
&lt;br /&gt;
Earlier, only [https://en.wikipedia.org/wiki/OpenGL OpenGL] implementation was supported for Android targets and we would be extending the [https://en.wikipedia.org/wiki/OpenGL_ES#2.0 ES2] implementation to support it for Linux targets. As a part of the final project, we accomplished the following steps:&lt;br /&gt;
&lt;br /&gt;
* Enable selection of the render api working from the command line, so the user can pick whether to use GL or ES2&lt;br /&gt;
* Modify the necessary files so that the current version of GL or ES2 are returned whenever either of them are selected&lt;br /&gt;
* Make the EGL libs available on Linux for rust-layers to compile rust-egl on Linux build.&lt;br /&gt;
* Separate out the EGLImageNativeSurface implementation from Android and move it to EGL&lt;br /&gt;
* Enable use of EGL or GLX for Linux&lt;br /&gt;
&lt;br /&gt;
=='''Files modified'''==&lt;br /&gt;
&lt;br /&gt;
  Servo/components/utils/opts.rs&lt;br /&gt;
added the new command line option to enable user to select the option of GL or ES2 as the rendering backend. The options of GL or ES2 are stored as an enum called RenderApi , such that running the Servo with option --render-api=chosen_option sets the corresponding Api.&lt;br /&gt;
&lt;br /&gt;
  Servo/ports/glutin/window.rs&lt;br /&gt;
&amp;lt;code&amp;gt;gl_version()&amp;lt;/code&amp;gt; function is modified in a way that based on what is selected as the RenderApi option by the user, the corresponding version of the Api is set. To talk more in detail,&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
rust-layers/src/platform/surface.rs: providing generic GL implementation that can dynamically select between the 2 interfaces.&lt;br /&gt;
&lt;br /&gt;
=='''Useful libraries'''==&lt;br /&gt;
&lt;br /&gt;
waffle-gl/waffle: A C library for selecting an OpenGL API and window system at runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Design Pattern'''==&lt;br /&gt;
The aim is to use ES2 implementation of rust layers for both android and Linux. So we need to use a design pattern that will allow us to extend the current implementation to support Linux targets too and give the user the flexibility to choose between the two implementations for rendering the backend.&lt;br /&gt;
&lt;br /&gt;
We propose to use [https://en.wikipedia.org/wiki/Decorator_pattern Decorator] pattern. The decorator pattern gives the user the ability to choose between the implementations that are desired, and attach the corresponding implementation to the target dynamically at runtime.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
1.    https://doc.rust-lang.org/stable/book/&amp;lt;br&amp;gt;&lt;br /&gt;
2.    https://en.wikipedia.org/wiki/Rust_(programming_language)&amp;lt;br&amp;gt;&lt;br /&gt;
3.    https://en.wikipedia.org/wiki/Servo_(layout_engine)&amp;lt;br&amp;gt;&lt;br /&gt;
4.    https://github.com/servo/servo/wiki/Refactor-GLES2-student-project&amp;lt;br&amp;gt;&lt;br /&gt;
5.    http://doc.crates.io/guide.html#overriding-dependencies&amp;lt;br&amp;gt;&lt;br /&gt;
6.    http://rustbyexample.com/&amp;lt;br&amp;gt;&lt;br /&gt;
7.    http://javarevisited.blogspot.com/2014/11/strategy-design-pattern-in-java-using-Enum-Example.html&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=100021</id>
		<title>CSC/ECE 517 Fall 2015/M1506-Refactor-GLES2-Implementation</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=100021"/>
		<updated>2015-12-03T21:37:59Z</updated>

		<summary type="html">&lt;p&gt;Asayal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''' Refactor GLES2 Student Project with SERVO &amp;amp; RUST ''''&lt;br /&gt;
&lt;br /&gt;
Servo is a prototype web browser engine written in the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript RUST]&amp;lt;/span&amp;gt; language.Servo uses a variety of back-end implementations for drawing graphics depending on the operating system.One of such back-end is only compatible with Android right now, and we want to extend and refactor that back-end to enable on all Linux systems..&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
===Servo===&lt;br /&gt;
[https://en.wikipedia.org/wiki/Servo_(layout_engine) Servo]Servo is an open source prototype web browser layout engine being developed by Mozilla, and it is written in [https://www.rust-lang.org/ Rust] language. The main idea is to create a highly parallel environment, in which different components can be handled by fine grained, isolated tasks. The different components can be rendering, HTML parsing, etc. &lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://doc.rust-lang.org/book/README.html Rust] is an open source systems programming language developed by Mozilla. Servo is written in Rust. The main purpose behind it's design is to be thread safe and concurrent. The emphasis is also on speed, safety and control of memory layout.&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
* The project requirement initially stated that we build and Compile servo. Following are the steps for this:&lt;br /&gt;
Servo is built with [https://mail.mozilla.org/pipermail/rust-dev/2014-March/009090.html Cargo], the Rust package manager. Mozilla's Mach tools are used to orchestrate the build and other tasks.&lt;br /&gt;
&lt;br /&gt;
    git clone https://github.com/servo/servo&lt;br /&gt;
    cd servo&lt;br /&gt;
    ./mach build --dev&lt;br /&gt;
    ./mach run tests/html/about-mozilla.html&lt;br /&gt;
&lt;br /&gt;
* The next requirement was to build the Rust-layers independently of Servo. For this, we &lt;br /&gt;
* Next, we had to over-ride cargo to use our local copy of Rust-layers, so we had to add a cargo override to it. For this, we created a &amp;lt;code&amp;gt;.cargo&amp;lt;/code&amp;gt; folder in our home directory(same place that servo and Rust-layers reside), and added a &amp;lt;code&amp;gt;config&amp;lt;/code&amp;gt; file to that folder. The content of that config file is a path to our local Rust-layers.&lt;br /&gt;
    paths = [path/to/rust_layers]&lt;br /&gt;
* Next, we had to add a new command line argument in Servo, which would allow selecting the graphics background (GL or ES2). For this, we made the following changes:&lt;br /&gt;
- We added a command line option which lets the user enter the option &amp;lt;code&amp;gt;-E&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;--es2&amp;lt;/code&amp;gt; if the user wants to set ES2 as the graphic back end option. GL is set by default, hence if the user doesn't give any argument, Gl is selected as the graphic back end option. Example is as below&lt;br /&gt;
    ./mach run [url] -E&lt;br /&gt;
* Next, we had to add a flag in Rust-layers. This change was made in the file [https://github.com/prashantgupta24/rust-layers/blob/master/src/rendergl.rs Rust/src/rendergl.rs] in the &amp;lt;code&amp;gt;RenderContext::new&amp;lt;/code&amp;gt; function. For this, we did the following change:&lt;br /&gt;
- We defined an enum &amp;lt;code&amp;gt;GraphicOption&amp;lt;/code&amp;gt; which defined two options &amp;lt;code&amp;gt;GL&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ES2&amp;lt;/code&amp;gt; and then based on the boolean value from the servo &amp;lt;code&amp;gt;opts.rs&amp;lt;/code&amp;gt;, we set a variable with the respective enum value &amp;lt;code&amp;gt;GL&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;ES2&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Then, we had to use the new command line option to pass the selected graphics back-end option to the Rust-layers context which we created in the previous step. For this we made changes to the [https://github.com/prashantgupta24/servo/blob/master/components/compositing/compositor.rs compositor.rs] in Compositing folder which is how Servo interacts with the Rust layers. The command line option is passed through the &amp;lt;code&amp;gt;initialize_compositing&amp;lt;/code&amp;gt; function.&lt;br /&gt;
* Now we need to change the platform implementation in [https://github.com/servo/rust-layers/blob/master/src/platform/surface.rs surface.rs] and provide a generic implementation to dynamically select between GL &amp;amp; ES2.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:RefactorGLESMozilla.png]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Requirement Analysis'''==&lt;br /&gt;
&lt;br /&gt;
Earlier, only [https://en.wikipedia.org/wiki/OpenGL OpenGL] implementation was supported for Android targets and we would be extending the [https://en.wikipedia.org/wiki/OpenGL_ES#2.0 ES2] implementation to support it for Linux targets. As a part of the final project, we accomplished the following steps:&lt;br /&gt;
&lt;br /&gt;
* Enable selection of the render api working from the command line, so the user can pick whether to use GL or ES2&lt;br /&gt;
* Modify the necessary files so that the current version of GL or ES2 are returned whenever either of them are selected&lt;br /&gt;
* Make the EGL libs available on Linux for rust-layers to compile rust-egl on Linux build.&lt;br /&gt;
* Separate out the EGLImageNativeSurface implementation from Android and move it to EGL&lt;br /&gt;
* Enable use of EGL or GLX for Linux&lt;br /&gt;
&lt;br /&gt;
=='''Files modified'''==&lt;br /&gt;
&lt;br /&gt;
  Servo/components/utils/opts.rs&lt;br /&gt;
added the new command line option to enable user to select the option of GL or ES2 as the rendering backend. The options of GL or ES2 are stored as an enum called RenderApi , such that running the Servo with option --render-api=chosen_option sets the corresponding Api.&lt;br /&gt;
&lt;br /&gt;
  Servo/ports/glutin/window.rs&lt;br /&gt;
&amp;lt;code&amp;gt;gl_version()&amp;lt;/code&amp;gt; function is modified in a way that based on what is selected as the RenderApi option by the user, the corresponding version of the Api is set. To talk more in detail,&lt;br /&gt;
&lt;br /&gt;
=='''Files modified'''==&lt;br /&gt;
&lt;br /&gt;
rust-layers/src/platform/surface.rs: providing generic GL implementation that can dynamically select between the 2 interfaces.&lt;br /&gt;
&lt;br /&gt;
=='''Useful libraries'''==&lt;br /&gt;
&lt;br /&gt;
waffle-gl/waffle: A C library for selecting an OpenGL API and window system at runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Design Pattern'''==&lt;br /&gt;
The aim is to use ES2 implementation of rust layers for both android and Linux. So we need to use a design pattern that will allow us to extend the current implementation to support Linux targets too and give the user the flexibility to choose between the two implementations for rendering the backend.&lt;br /&gt;
&lt;br /&gt;
We propose to use [https://en.wikipedia.org/wiki/Decorator_pattern Decorator] pattern. The decorator pattern gives the user the ability to choose between the implementations that are desired, and attach the corresponding implementation to the target dynamically at runtime.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
1.    https://doc.rust-lang.org/stable/book/&amp;lt;br&amp;gt;&lt;br /&gt;
2.    https://en.wikipedia.org/wiki/Rust_(programming_language)&amp;lt;br&amp;gt;&lt;br /&gt;
3.    https://en.wikipedia.org/wiki/Servo_(layout_engine)&amp;lt;br&amp;gt;&lt;br /&gt;
4.    https://github.com/servo/servo/wiki/Refactor-GLES2-student-project&amp;lt;br&amp;gt;&lt;br /&gt;
5.    http://doc.crates.io/guide.html#overriding-dependencies&amp;lt;br&amp;gt;&lt;br /&gt;
6.    http://rustbyexample.com/&amp;lt;br&amp;gt;&lt;br /&gt;
7.    http://javarevisited.blogspot.com/2014/11/strategy-design-pattern-in-java-using-Enum-Example.html&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=100019</id>
		<title>CSC/ECE 517 Fall 2015/M1506-Refactor-GLES2-Implementation</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=100019"/>
		<updated>2015-12-03T21:18:45Z</updated>

		<summary type="html">&lt;p&gt;Asayal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''' Refactor GLES2 Student Project with SERVO &amp;amp; RUST ''''&lt;br /&gt;
&lt;br /&gt;
Servo is a prototype web browser engine written in the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript RUST]&amp;lt;/span&amp;gt; language.Servo uses a variety of back-end implementations for drawing graphics depending on the operating system.One of such back-end is only compatible with Android right now, and we want to extend and refactor that back-end to enable on all Linux systems..&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
===Servo===&lt;br /&gt;
[https://en.wikipedia.org/wiki/Servo_(layout_engine) Servo]Servo is an open source prototype web browser layout engine being developed by Mozilla, and it is written in [https://www.rust-lang.org/ Rust] language. The main idea is to create a highly parallel environment, in which different components can be handled by fine grained, isolated tasks. The different components can be rendering, HTML parsing, etc. &lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://doc.rust-lang.org/book/README.html Rust] is an open source systems programming language developed by Mozilla. Servo is written in Rust. The main purpose behind it's design is to be thread safe and concurrent. The emphasis is also on speed, safety and control of memory layout.&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
* The project requirement initially stated that we build and Compile servo. Following are the steps for this:&lt;br /&gt;
Servo is built with [https://mail.mozilla.org/pipermail/rust-dev/2014-March/009090.html Cargo], the Rust package manager. Mozilla's Mach tools are used to orchestrate the build and other tasks.&lt;br /&gt;
&lt;br /&gt;
    git clone https://github.com/servo/servo&lt;br /&gt;
    cd servo&lt;br /&gt;
    ./mach build --dev&lt;br /&gt;
    ./mach run tests/html/about-mozilla.html&lt;br /&gt;
&lt;br /&gt;
* The next requirement was to build the Rust-layers independently of Servo. For this, we &lt;br /&gt;
* Next, we had to over-ride cargo to use our local copy of Rust-layers, so we had to add a cargo override to it. For this, we created a &amp;lt;code&amp;gt;.cargo&amp;lt;/code&amp;gt; folder in our home directory(same place that servo and Rust-layers reside), and added a &amp;lt;code&amp;gt;config&amp;lt;/code&amp;gt; file to that folder. The content of that config file is a path to our local Rust-layers.&lt;br /&gt;
    paths = [path/to/rust_layers]&lt;br /&gt;
* Next, we had to add a new command line argument in Servo, which would allow selecting the graphics background (GL or ES2). For this, we made the following changes:&lt;br /&gt;
- We added a command line option which lets the user enter the option &amp;lt;code&amp;gt;-E&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;--es2&amp;lt;/code&amp;gt; if the user wants to set ES2 as the graphic back end option. GL is set by default, hence if the user doesn't give any argument, Gl is selected as the graphic back end option. Example is as below&lt;br /&gt;
    ./mach run [url] -E&lt;br /&gt;
* Next, we had to add a flag in Rust-layers. This change was made in the file [https://github.com/prashantgupta24/rust-layers/blob/master/src/rendergl.rs Rust/src/rendergl.rs] in the &amp;lt;code&amp;gt;RenderContext::new&amp;lt;/code&amp;gt; function. For this, we did the following change:&lt;br /&gt;
- We defined an enum &amp;lt;code&amp;gt;GraphicOption&amp;lt;/code&amp;gt; which defined two options &amp;lt;code&amp;gt;GL&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ES2&amp;lt;/code&amp;gt; and then based on the boolean value from the servo &amp;lt;code&amp;gt;opts.rs&amp;lt;/code&amp;gt;, we set a variable with the respective enum value &amp;lt;code&amp;gt;GL&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;ES2&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Then, we had to use the new command line option to pass the selected graphics back-end option to the Rust-layers context which we created in the previous step. For this we made changes to the [https://github.com/prashantgupta24/servo/blob/master/components/compositing/compositor.rs compositor.rs] in Compositing folder which is how Servo interacts with the Rust layers. The command line option is passed through the &amp;lt;code&amp;gt;initialize_compositing&amp;lt;/code&amp;gt; function.&lt;br /&gt;
* Now we need to change the platform implementation in [https://github.com/servo/rust-layers/blob/master/src/platform/surface.rs surface.rs] and provide a generic implementation to dynamically select between GL &amp;amp; ES2.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:RefactorGLESMozilla.png]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Requirement Analysis'''==&lt;br /&gt;
&lt;br /&gt;
Earlier, only [https://en.wikipedia.org/wiki/OpenGL OpenGL] implementation was supported for Android targets and we would be extending the [https://en.wikipedia.org/wiki/OpenGL_ES#2.0 ES2] implementation to support it for Linux targets. As a part of the final project, we accomplished the following steps:&lt;br /&gt;
&lt;br /&gt;
* Enable selection of the render api working from the command line, so the user can pick whether to use GL or ES2&lt;br /&gt;
* Modify the necessary files so that the current version of GL or ES2 are returned whenever either of them are selected&lt;br /&gt;
* Make the EGL libs available on Linux for rust-layers to compile rust-egl on Linux build.&lt;br /&gt;
* Separate out the EGLImageNativeSurface implementation from Android and move it to EGL&lt;br /&gt;
* Enable use of EGL or GLX for Linux&lt;br /&gt;
&lt;br /&gt;
=='''Files modified'''==&lt;br /&gt;
&lt;br /&gt;
    Servo/components/utils/opts.rs&lt;br /&gt;
added the new command line option to allow selecting the graphics backend.&lt;br /&gt;
rust-layers/src/rendergl.rs: changed the RenderContext new function to allow the dynamic selection of graphics backend.&lt;br /&gt;
&lt;br /&gt;
=='''Files to be modified'''==&lt;br /&gt;
&lt;br /&gt;
rust-layers/src/platform/surface.rs: providing generic GL implementation that can dynamically select between the 2 interfaces.&lt;br /&gt;
&lt;br /&gt;
=='''Useful libraries'''==&lt;br /&gt;
&lt;br /&gt;
waffle-gl/waffle: A C library for selecting an OpenGL API and window system at runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Design Pattern'''==&lt;br /&gt;
The aim is to use ES2 implementation of rust layers for both android and Linux. So we need to use a design pattern that will allow us to extend the current implementation to support Linux targets too and give the user the flexibility to choose between the two implementations for rendering the backend.&lt;br /&gt;
&lt;br /&gt;
We propose to use [https://en.wikipedia.org/wiki/Decorator_pattern Decorator] pattern. The decorator pattern gives the user the ability to choose between the implementations that are desired, and attach the corresponding implementation to the target dynamically at runtime.&lt;br /&gt;
&lt;br /&gt;
=='''To Be Determined Information'''==&lt;br /&gt;
* Whether waffle-gl is to be imported, or simply used as example for base functionality&lt;br /&gt;
* Where android surface.rs  implements ES2 vs GL (ie, what is the dividing line between a GL graphics implementation, and an ES2 graphics implementation).&lt;br /&gt;
* Acquiring Android interface to test modified “general” GL_ES implementation.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
1.    https://doc.rust-lang.org/stable/book/&amp;lt;br&amp;gt;&lt;br /&gt;
2.    https://en.wikipedia.org/wiki/Rust_(programming_language)&amp;lt;br&amp;gt;&lt;br /&gt;
3.    https://en.wikipedia.org/wiki/Servo_(layout_engine)&amp;lt;br&amp;gt;&lt;br /&gt;
4.    https://github.com/servo/servo/wiki/Refactor-GLES2-student-project&amp;lt;br&amp;gt;&lt;br /&gt;
5.    http://doc.crates.io/guide.html#overriding-dependencies&amp;lt;br&amp;gt;&lt;br /&gt;
6.    http://rustbyexample.com/&amp;lt;br&amp;gt;&lt;br /&gt;
7.    http://javarevisited.blogspot.com/2014/11/strategy-design-pattern-in-java-using-Enum-Example.html&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=99709</id>
		<title>CSC/ECE 517 Fall 2015/M1506-Refactor-GLES2-Implementation</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=99709"/>
		<updated>2015-11-13T23:11:50Z</updated>

		<summary type="html">&lt;p&gt;Asayal: /* Project Description */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''' Refactor GLES2 Student Project with SERVO &amp;amp; RUST ''''&lt;br /&gt;
&lt;br /&gt;
Servo is a prototype web browser engine written in the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript RUST]&amp;lt;/span&amp;gt; language.Servo uses a variety of back-end implementations for drawing graphics depending on the operating system.One of such back-end is only compatible with Android right now, and we want to extend and refactor that back-end to enable on all Linux systems..&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
===Servo===&lt;br /&gt;
[https://en.wikipedia.org/wiki/Servo_(layout_engine) Servo]Servo is an open source prototype web browser layout engine being developed by Mozilla, and it is written in [https://www.rust-lang.org/ Rust] language. The main idea is to create a highly parallel environment, in which different components can be handled by fine grained, isolated tasks. The different components can be rendering, HTML parsing, etc. &lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://doc.rust-lang.org/book/README.html Rust] is an open source systems programming language developed by Mozilla. Servo is written in Rust. The main purpose behind it's design is to be thread safe and concurrent. The emphasis is also on speed, safety and control of memory layout.&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
* The project requirement initially stated that we build and Compile servo. Following are the steps for this:&lt;br /&gt;
Servo is built with [https://mail.mozilla.org/pipermail/rust-dev/2014-March/009090.html Cargo], the Rust package manager. Mozilla's Mach tools are used to orchestrate the build and other tasks.&lt;br /&gt;
&lt;br /&gt;
    git clone https://github.com/servo/servo&lt;br /&gt;
    cd servo&lt;br /&gt;
    ./mach build --dev&lt;br /&gt;
    ./mach run tests/html/about-mozilla.html&lt;br /&gt;
&lt;br /&gt;
* The next requirement was to build the Rust-layers independently of Servo. For this, we &lt;br /&gt;
* Next, we had to over-ride cargo to use our local copy of Rust-layers, so we had to add a cargo override to it. For this, we created a &amp;lt;code&amp;gt;.cargo&amp;lt;/code&amp;gt; folder in our home directory(same place that servo and Rust-layers reside), and added a &amp;lt;code&amp;gt;config&amp;lt;/code&amp;gt; file to that folder. The content of that config file is a path to our local Rust-layers.&lt;br /&gt;
    paths = [path/to/rust_layers]&lt;br /&gt;
* Next, we had to add a new command line argument in Servo, which would allow selecting the graphics background (GL or ES2). For this, we made the following changes:&lt;br /&gt;
- We added a command line option which lets the user enter the option &amp;lt;code&amp;gt;-E&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;--es2&amp;lt;/code&amp;gt; if the user wants to set ES2 as the graphic back end option. GL is set by default, hence if the user doesn't give any argument, Gl is selected as the graphic back end option. Example is as below&lt;br /&gt;
    ./mach run [url] -E&lt;br /&gt;
* Next, we had to add a flag in Rust-layers. This change was made in the file [https://github.com/prashantgupta24/rust-layers/blob/master/src/rendergl.rs Rust/src/rendergl.rs] in the &amp;lt;code&amp;gt;RenderContext::new&amp;lt;/code&amp;gt; function. For this, we did the following change:&lt;br /&gt;
- We defined an enum &amp;lt;code&amp;gt;GraphicOption&amp;lt;/code&amp;gt; which defined two options &amp;lt;code&amp;gt;GL&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ES2&amp;lt;/code&amp;gt; and then based on the boolean value from the servo &amp;lt;code&amp;gt;opts.rs&amp;lt;/code&amp;gt;, we set a variable with the respective enum value &amp;lt;code&amp;gt;GL&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;ES2&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Then, we had to use the new command line option to pass the selected graphics back-end option to the Rust-layers context which we created in the previous step. For this we made changes to the [https://github.com/prashantgupta24/servo/blob/master/components/compositing/compositor.rs compositor.rs] in Compositing folder which is how Servo interacts with the Rust layers. The command line option is passed through the &amp;lt;code&amp;gt;initialize_compositing&amp;lt;/code&amp;gt; function.&lt;br /&gt;
* Now we need to change the platform implementation in [https://github.com/servo/rust-layers/blob/master/src/platform/surface.rs surface.rs] and provide a generic implementation to dynamically select between GL &amp;amp; ES2.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:RefactorGLESMozilla.png]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Requirement Analysis'''==&lt;br /&gt;
&lt;br /&gt;
Earlier, only [https://en.wikipedia.org/wiki/OpenGL OpenGL] implementation was supported for Linux targets and we would be extending the [https://en.wikipedia.org/wiki/OpenGL_ES#2.0 ES2] implementation to support it for linux targets too. As a part of the final project, we propose to perform the following steps:&lt;br /&gt;
&lt;br /&gt;
* Change the platform implementation to provide a more generic way to dynamically select between GL and ES2. &lt;br /&gt;
* Remove the Linux/Android specific #cfg flags.&lt;br /&gt;
* Place a general #cfg flag for both Android and Linux to provide a more generic implementation of dynamic selection between GL and ES2&lt;br /&gt;
* Make changes to EGL platform to make it work on desktop GL&lt;br /&gt;
&lt;br /&gt;
=='''Files modified'''==&lt;br /&gt;
&lt;br /&gt;
Servo/components/utils/opts.rs: added the new command line option to allow selecting the graphics backend.&lt;br /&gt;
rust-layers/src/rendergl.rs: changed the RenderContext new function to allow the dynamic selection of graphics backend.&lt;br /&gt;
&lt;br /&gt;
=='''Files to be modified'''==&lt;br /&gt;
&lt;br /&gt;
rust-layers/src/platform/surface.rs: providing generic GL implementation that can dynamically select between the 2 interfaces.&lt;br /&gt;
&lt;br /&gt;
=='''Useful libraries'''==&lt;br /&gt;
&lt;br /&gt;
waffle-gl/waffle: A C library for selecting an OpenGL API and window system at runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Design Pattern'''==&lt;br /&gt;
The aim is to use ES2 implementation of rust layers for both android and Linux. So we need to use a design pattern that will allow us to extend the current implementation to support Linux targets too and give the user the flexibility to choose between the two implementations for rendering the backend.&lt;br /&gt;
&lt;br /&gt;
We propose to use [https://en.wikipedia.org/wiki/Decorator_pattern Decorator] pattern. The decorator pattern gives the user the ability to choose between the implementations that are desired, and attach the corresponding implementation to the target dynamically at runtime.&lt;br /&gt;
&lt;br /&gt;
=='''To Be Determined Information'''==&lt;br /&gt;
* Whether waffle-gl is to be imported, or simply used as example for base functionality&lt;br /&gt;
* Where android surface.rs  implements ES2 vs GL (ie, what is the dividing line between a GL graphics implementation, and an ES2 graphics implementation).&lt;br /&gt;
* Acquiring Android interface to test modified “general” GL_ES implementation.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
1.    https://doc.rust-lang.org/stable/book/&amp;lt;br&amp;gt;&lt;br /&gt;
2.    https://en.wikipedia.org/wiki/Rust_(programming_language)&amp;lt;br&amp;gt;&lt;br /&gt;
3.    https://en.wikipedia.org/wiki/Servo_(layout_engine)&amp;lt;br&amp;gt;&lt;br /&gt;
4.    https://github.com/servo/servo/wiki/Refactor-GLES2-student-project&amp;lt;br&amp;gt;&lt;br /&gt;
5.    http://doc.crates.io/guide.html#overriding-dependencies&amp;lt;br&amp;gt;&lt;br /&gt;
6.    http://rustbyexample.com/&amp;lt;br&amp;gt;&lt;br /&gt;
7.    http://javarevisited.blogspot.com/2014/11/strategy-design-pattern-in-java-using-Enum-Example.html&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:RefactorGLESMozilla.png&amp;diff=99707</id>
		<title>File:RefactorGLESMozilla.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:RefactorGLESMozilla.png&amp;diff=99707"/>
		<updated>2015-11-13T23:11:27Z</updated>

		<summary type="html">&lt;p&gt;Asayal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=99706</id>
		<title>CSC/ECE 517 Fall 2015/M1506-Refactor-GLES2-Implementation</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=99706"/>
		<updated>2015-11-13T23:10:33Z</updated>

		<summary type="html">&lt;p&gt;Asayal: /* Project Description */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''' Refactor GLES2 Student Project with SERVO &amp;amp; RUST ''''&lt;br /&gt;
&lt;br /&gt;
Servo is a prototype web browser engine written in the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript RUST]&amp;lt;/span&amp;gt; language.Servo uses a variety of back-end implementations for drawing graphics depending on the operating system.One of such back-end is only compatible with Android right now, and we want to extend and refactor that back-end to enable on all Linux systems..&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
===Servo===&lt;br /&gt;
[https://en.wikipedia.org/wiki/Servo_(layout_engine) Servo]Servo is an open source prototype web browser layout engine being developed by Mozilla, and it is written in [https://www.rust-lang.org/ Rust] language. The main idea is to create a highly parallel environment, in which different components can be handled by fine grained, isolated tasks. The different components can be rendering, HTML parsing, etc. &lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://doc.rust-lang.org/book/README.html Rust] is an open source systems programming language developed by Mozilla. Servo is written in Rust. The main purpose behind it's design is to be thread safe and concurrent. The emphasis is also on speed, safety and control of memory layout.&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
* The project requirement initially stated that we build and Compile servo. Following are the steps for this:&lt;br /&gt;
Servo is built with [https://mail.mozilla.org/pipermail/rust-dev/2014-March/009090.html Cargo], the Rust package manager. Mozilla's Mach tools are used to orchestrate the build and other tasks.&lt;br /&gt;
&lt;br /&gt;
    git clone https://github.com/servo/servo&lt;br /&gt;
    cd servo&lt;br /&gt;
    ./mach build --dev&lt;br /&gt;
    ./mach run tests/html/about-mozilla.html&lt;br /&gt;
&lt;br /&gt;
* The next requirement was to build the Rust-layers independently of Servo. For this, we &lt;br /&gt;
* Next, we had to over-ride cargo to use our local copy of Rust-layers, so we had to add a cargo override to it. For this, we created a &amp;lt;code&amp;gt;.cargo&amp;lt;/code&amp;gt; folder in our home directory(same place that servo and Rust-layers reside), and added a &amp;lt;code&amp;gt;config&amp;lt;/code&amp;gt; file to that folder. The content of that config file is a path to our local Rust-layers.&lt;br /&gt;
    paths = [path/to/rust_layers]&lt;br /&gt;
* Next, we had to add a new command line argument in Servo, which would allow selecting the graphics background (GL or ES2). For this, we made the following changes:&lt;br /&gt;
- We added a command line option which lets the user enter the option &amp;lt;code&amp;gt;-E&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;--es2&amp;lt;/code&amp;gt; if the user wants to set ES2 as the graphic back end option. GL is set by default, hence if the user doesn't give any argument, Gl is selected as the graphic back end option. Example is as below&lt;br /&gt;
    ./mach run [url] -E&lt;br /&gt;
* Next, we had to add a flag in Rust-layers. This change was made in the file [https://github.com/prashantgupta24/rust-layers/blob/master/src/rendergl.rs Rust/src/rendergl.rs] in the &amp;lt;code&amp;gt;RenderContext::new&amp;lt;/code&amp;gt; function. For this, we did the following change:&lt;br /&gt;
- We defined an enum &amp;lt;code&amp;gt;GraphicOption&amp;lt;/code&amp;gt; which defined two options &amp;lt;code&amp;gt;GL&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ES2&amp;lt;/code&amp;gt; and then based on the boolean value from the servo &amp;lt;code&amp;gt;opts.rs&amp;lt;/code&amp;gt;, we set a variable with the respective enum value &amp;lt;code&amp;gt;GL&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;ES2&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Then, we had to use the new command line option to pass the selected graphics back-end option to the Rust-layers context which we created in the previous step. For this we made changes to the [https://github.com/prashantgupta24/servo/blob/master/components/compositing/compositor.rs compositor.rs] in Compositing folder which is how Servo interacts with the Rust layers. The command line option is passed through the &amp;lt;code&amp;gt;initialize_compositing&amp;lt;/code&amp;gt; function.&lt;br /&gt;
* Now we need to change the platform implementation in [https://github.com/servo/rust-layers/blob/master/src/platform/surface.rs surface.rs] and provide a generic implementation to dynamically select between GL &amp;amp; ES2.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:M1506_FlowChart.png]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Requirement Analysis'''==&lt;br /&gt;
&lt;br /&gt;
Earlier, only [https://en.wikipedia.org/wiki/OpenGL OpenGL] implementation was supported for Linux targets and we would be extending the [https://en.wikipedia.org/wiki/OpenGL_ES#2.0 ES2] implementation to support it for linux targets too. As a part of the final project, we propose to perform the following steps:&lt;br /&gt;
&lt;br /&gt;
* Change the platform implementation to provide a more generic way to dynamically select between GL and ES2. &lt;br /&gt;
* Remove the Linux/Android specific #cfg flags.&lt;br /&gt;
* Place a general #cfg flag for both Android and Linux to provide a more generic implementation of dynamic selection between GL and ES2&lt;br /&gt;
* Make changes to EGL platform to make it work on desktop GL&lt;br /&gt;
&lt;br /&gt;
=='''Files modified'''==&lt;br /&gt;
&lt;br /&gt;
Servo/components/utils/opts.rs: added the new command line option to allow selecting the graphics backend.&lt;br /&gt;
rust-layers/src/rendergl.rs: changed the RenderContext new function to allow the dynamic selection of graphics backend.&lt;br /&gt;
&lt;br /&gt;
=='''Files to be modified'''==&lt;br /&gt;
&lt;br /&gt;
rust-layers/src/platform/surface.rs: providing generic GL implementation that can dynamically select between the 2 interfaces.&lt;br /&gt;
&lt;br /&gt;
=='''Useful libraries'''==&lt;br /&gt;
&lt;br /&gt;
waffle-gl/waffle: A C library for selecting an OpenGL API and window system at runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Design Pattern'''==&lt;br /&gt;
The aim is to use ES2 implementation of rust layers for both android and Linux. So we need to use a design pattern that will allow us to extend the current implementation to support Linux targets too and give the user the flexibility to choose between the two implementations for rendering the backend.&lt;br /&gt;
&lt;br /&gt;
We propose to use [https://en.wikipedia.org/wiki/Decorator_pattern Decorator] pattern. The decorator pattern gives the user the ability to choose between the implementations that are desired, and attach the corresponding implementation to the target dynamically at runtime.&lt;br /&gt;
&lt;br /&gt;
=='''To Be Determined Information'''==&lt;br /&gt;
* Whether waffle-gl is to be imported, or simply used as example for base functionality&lt;br /&gt;
* Where android surface.rs  implements ES2 vs GL (ie, what is the dividing line between a GL graphics implementation, and an ES2 graphics implementation).&lt;br /&gt;
* Acquiring Android interface to test modified “general” GL_ES implementation.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
1.    https://doc.rust-lang.org/stable/book/&amp;lt;br&amp;gt;&lt;br /&gt;
2.    https://en.wikipedia.org/wiki/Rust_(programming_language)&amp;lt;br&amp;gt;&lt;br /&gt;
3.    https://en.wikipedia.org/wiki/Servo_(layout_engine)&amp;lt;br&amp;gt;&lt;br /&gt;
4.    https://github.com/servo/servo/wiki/Refactor-GLES2-student-project&amp;lt;br&amp;gt;&lt;br /&gt;
5.    http://doc.crates.io/guide.html#overriding-dependencies&amp;lt;br&amp;gt;&lt;br /&gt;
6.    http://rustbyexample.com/&amp;lt;br&amp;gt;&lt;br /&gt;
7.    http://javarevisited.blogspot.com/2014/11/strategy-design-pattern-in-java-using-Enum-Example.html&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:M1506_Flowchart.png&amp;diff=99705</id>
		<title>File:M1506 Flowchart.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:M1506_Flowchart.png&amp;diff=99705"/>
		<updated>2015-11-13T23:10:09Z</updated>

		<summary type="html">&lt;p&gt;Asayal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=99703</id>
		<title>CSC/ECE 517 Fall 2015/M1506-Refactor-GLES2-Implementation</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=99703"/>
		<updated>2015-11-13T23:06:36Z</updated>

		<summary type="html">&lt;p&gt;Asayal: /* Design Pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''' Refactor GLES2 Student Project with SERVO &amp;amp; RUST ''''&lt;br /&gt;
&lt;br /&gt;
Servo is a prototype web browser engine written in the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript RUST]&amp;lt;/span&amp;gt; language.Servo uses a variety of back-end implementations for drawing graphics depending on the operating system.One of such back-end is only compatible with Android right now, and we want to extend and refactor that back-end to enable on all Linux systems..&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
===Servo===&lt;br /&gt;
[https://en.wikipedia.org/wiki/Servo_(layout_engine) Servo]Servo is an open source prototype web browser layout engine being developed by Mozilla, and it is written in [https://www.rust-lang.org/ Rust] language. The main idea is to create a highly parallel environment, in which different components can be handled by fine grained, isolated tasks. The different components can be rendering, HTML parsing, etc. &lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://doc.rust-lang.org/book/README.html Rust] is an open source systems programming language developed by Mozilla. Servo is written in Rust. The main purpose behind it's design is to be thread safe and concurrent. The emphasis is also on speed, safety and control of memory layout.&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
* The project requirement initially stated that we build and Compile servo. Following are the steps for this:&lt;br /&gt;
Servo is built with [https://mail.mozilla.org/pipermail/rust-dev/2014-March/009090.html Cargo], the Rust package manager. Mozilla's Mach tools are used to orchestrate the build and other tasks.&lt;br /&gt;
&lt;br /&gt;
    git clone https://github.com/servo/servo&lt;br /&gt;
    cd servo&lt;br /&gt;
    ./mach build --dev&lt;br /&gt;
    ./mach run tests/html/about-mozilla.html&lt;br /&gt;
&lt;br /&gt;
* The next requirement was to build the Rust-layers independently of Servo. For this, we &lt;br /&gt;
* Next, we had to over-ride cargo to use our local copy of Rust-layers, so we had to add a cargo override to it. For this, we created a &amp;lt;code&amp;gt;.cargo&amp;lt;/code&amp;gt; folder in our home directory(same place that servo and Rust-layers reside), and added a &amp;lt;code&amp;gt;config&amp;lt;/code&amp;gt; file to that folder. The content of that config file is a path to our local Rust-layers.&lt;br /&gt;
    paths = [path/to/rust_layers]&lt;br /&gt;
* Next, we had to add a new command line argument in Servo, which would allow selecting the graphics background (GL or ES2). For this, we made the following changes:&lt;br /&gt;
- We added a command line option which lets the user enter the option &amp;lt;code&amp;gt;-E&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;--es2&amp;lt;/code&amp;gt; if the user wants to set ES2 as the graphic back end option. GL is set by default, hence if the user doesn't give any argument, Gl is selected as the graphic back end option. Example is as below&lt;br /&gt;
    ./mach run [url] -E&lt;br /&gt;
* Next, we had to add a flag in Rust-layers. This change was made in the file [https://github.com/prashantgupta24/rust-layers/blob/master/src/rendergl.rs Rust/src/rendergl.rs] in the &amp;lt;code&amp;gt;RenderContext::new&amp;lt;/code&amp;gt; function. For this, we did the following change:&lt;br /&gt;
- We defined an enum &amp;lt;code&amp;gt;GraphicOption&amp;lt;/code&amp;gt; which defined two options &amp;lt;code&amp;gt;GL&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ES2&amp;lt;/code&amp;gt; and then based on the boolean value from the servo &amp;lt;code&amp;gt;opts.rs&amp;lt;/code&amp;gt;, we set a variable with the respective enum value &amp;lt;code&amp;gt;GL&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;ES2&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Then, we had to use the new command line option to pass the selected graphics back-end option to the Rust-layers context which we created in the previous step. For this we made changes to the [https://github.com/prashantgupta24/servo/blob/master/components/compositing/compositor.rs compositor.rs] in Compositing folder which is how Servo interacts with the Rust layers. The command line option is passed through the &amp;lt;code&amp;gt;initialize_compositing&amp;lt;/code&amp;gt; function.&lt;br /&gt;
* Now we need to change the platform implementation in [https://github.com/servo/rust-layers/blob/master/src/platform/surface.rs surface.rs] and provide a generic implementation to dynamically select between GL &amp;amp; ES2.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:M1506FlowChart.png]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Requirement Analysis'''==&lt;br /&gt;
&lt;br /&gt;
Earlier, only [https://en.wikipedia.org/wiki/OpenGL OpenGL] implementation was supported for Linux targets and we would be extending the [https://en.wikipedia.org/wiki/OpenGL_ES#2.0 ES2] implementation to support it for linux targets too. As a part of the final project, we propose to perform the following steps:&lt;br /&gt;
&lt;br /&gt;
* Change the platform implementation to provide a more generic way to dynamically select between GL and ES2. &lt;br /&gt;
* Remove the Linux/Android specific #cfg flags.&lt;br /&gt;
* Place a general #cfg flag for both Android and Linux to provide a more generic implementation of dynamic selection between GL and ES2&lt;br /&gt;
* Make changes to EGL platform to make it work on desktop GL&lt;br /&gt;
&lt;br /&gt;
=='''Files modified'''==&lt;br /&gt;
&lt;br /&gt;
Servo/components/utils/opts.rs: added the new command line option to allow selecting the graphics backend.&lt;br /&gt;
rust-layers/src/rendergl.rs: changed the RenderContext new function to allow the dynamic selection of graphics backend.&lt;br /&gt;
&lt;br /&gt;
=='''Files to be modified'''==&lt;br /&gt;
&lt;br /&gt;
rust-layers/src/platform/surface.rs: providing generic GL implementation that can dynamically select between the 2 interfaces.&lt;br /&gt;
&lt;br /&gt;
=='''Useful libraries'''==&lt;br /&gt;
&lt;br /&gt;
waffle-gl/waffle: A C library for selecting an OpenGL API and window system at runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Design Pattern'''==&lt;br /&gt;
The aim is to use ES2 implementation of rust layers for both android and Linux. So we need to use a design pattern that will allow us to extend the current implementation to support Linux targets too and give the user the flexibility to choose between the two implementations for rendering the backend.&lt;br /&gt;
&lt;br /&gt;
We propose to use [https://en.wikipedia.org/wiki/Decorator_pattern Decorator] pattern. The decorator pattern gives the user the ability to choose between the implementations that are desired, and attach the corresponding implementation to the target dynamically at runtime.&lt;br /&gt;
&lt;br /&gt;
=='''To Be Determined Information'''==&lt;br /&gt;
* Whether waffle-gl is to be imported, or simply used as example for base functionality&lt;br /&gt;
* Where android surface.rs  implements ES2 vs GL (ie, what is the dividing line between a GL graphics implementation, and an ES2 graphics implementation).&lt;br /&gt;
* Acquiring Android interface to test modified “general” GL_ES implementation.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
1.    https://doc.rust-lang.org/stable/book/&amp;lt;br&amp;gt;&lt;br /&gt;
2.    https://en.wikipedia.org/wiki/Rust_(programming_language)&amp;lt;br&amp;gt;&lt;br /&gt;
3.    https://en.wikipedia.org/wiki/Servo_(layout_engine)&amp;lt;br&amp;gt;&lt;br /&gt;
4.    https://github.com/servo/servo/wiki/Refactor-GLES2-student-project&amp;lt;br&amp;gt;&lt;br /&gt;
5.    http://doc.crates.io/guide.html#overriding-dependencies&amp;lt;br&amp;gt;&lt;br /&gt;
6.    http://rustbyexample.com/&amp;lt;br&amp;gt;&lt;br /&gt;
7.    http://javarevisited.blogspot.com/2014/11/strategy-design-pattern-in-java-using-Enum-Example.html&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=99700</id>
		<title>CSC/ECE 517 Fall 2015/M1506-Refactor-GLES2-Implementation</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=99700"/>
		<updated>2015-11-13T23:00:48Z</updated>

		<summary type="html">&lt;p&gt;Asayal: /* Project Description */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''' Refactor GLES2 Student Project with SERVO &amp;amp; RUST ''''&lt;br /&gt;
&lt;br /&gt;
Servo is a prototype web browser engine written in the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript RUST]&amp;lt;/span&amp;gt; language.Servo uses a variety of back-end implementations for drawing graphics depending on the operating system.One of such back-end is only compatible with Android right now, and we want to extend and refactor that back-end to enable on all Linux systems..&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
===Servo===&lt;br /&gt;
[https://en.wikipedia.org/wiki/Servo_(layout_engine) Servo]Servo is an open source prototype web browser layout engine being developed by Mozilla, and it is written in [https://www.rust-lang.org/ Rust] language. The main idea is to create a highly parallel environment, in which different components can be handled by fine grained, isolated tasks. The different components can be rendering, HTML parsing, etc. &lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://doc.rust-lang.org/book/README.html Rust] is an open source systems programming language developed by Mozilla. Servo is written in Rust. The main purpose behind it's design is to be thread safe and concurrent. The emphasis is also on speed, safety and control of memory layout.&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
* The project requirement initially stated that we build and Compile servo. Following are the steps for this:&lt;br /&gt;
Servo is built with [https://mail.mozilla.org/pipermail/rust-dev/2014-March/009090.html Cargo], the Rust package manager. Mozilla's Mach tools are used to orchestrate the build and other tasks.&lt;br /&gt;
&lt;br /&gt;
    git clone https://github.com/servo/servo&lt;br /&gt;
    cd servo&lt;br /&gt;
    ./mach build --dev&lt;br /&gt;
    ./mach run tests/html/about-mozilla.html&lt;br /&gt;
&lt;br /&gt;
* The next requirement was to build the Rust-layers independently of Servo. For this, we &lt;br /&gt;
* Next, we had to over-ride cargo to use our local copy of Rust-layers, so we had to add a cargo override to it. For this, we created a &amp;lt;code&amp;gt;.cargo&amp;lt;/code&amp;gt; folder in our home directory(same place that servo and Rust-layers reside), and added a &amp;lt;code&amp;gt;config&amp;lt;/code&amp;gt; file to that folder. The content of that config file is a path to our local Rust-layers.&lt;br /&gt;
    paths = [path/to/rust_layers]&lt;br /&gt;
* Next, we had to add a new command line argument in Servo, which would allow selecting the graphics background (GL or ES2). For this, we made the following changes:&lt;br /&gt;
- We added a command line option which lets the user enter the option &amp;lt;code&amp;gt;-E&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;--es2&amp;lt;/code&amp;gt; if the user wants to set ES2 as the graphic back end option. GL is set by default, hence if the user doesn't give any argument, Gl is selected as the graphic back end option. Example is as below&lt;br /&gt;
    ./mach run [url] -E&lt;br /&gt;
* Next, we had to add a flag in Rust-layers. This change was made in the file [https://github.com/prashantgupta24/rust-layers/blob/master/src/rendergl.rs Rust/src/rendergl.rs] in the &amp;lt;code&amp;gt;RenderContext::new&amp;lt;/code&amp;gt; function. For this, we did the following change:&lt;br /&gt;
- We defined an enum &amp;lt;code&amp;gt;GraphicOption&amp;lt;/code&amp;gt; which defined two options &amp;lt;code&amp;gt;GL&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ES2&amp;lt;/code&amp;gt; and then based on the boolean value from the servo &amp;lt;code&amp;gt;opts.rs&amp;lt;/code&amp;gt;, we set a variable with the respective enum value &amp;lt;code&amp;gt;GL&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;ES2&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Then, we had to use the new command line option to pass the selected graphics back-end option to the Rust-layers context which we created in the previous step. For this we made changes to the [https://github.com/prashantgupta24/servo/blob/master/components/compositing/compositor.rs compositor.rs] in Compositing folder which is how Servo interacts with the Rust layers. The command line option is passed through the &amp;lt;code&amp;gt;initialize_compositing&amp;lt;/code&amp;gt; function.&lt;br /&gt;
* Now we need to change the platform implementation in [https://github.com/servo/rust-layers/blob/master/src/platform/surface.rs surface.rs] and provide a generic implementation to dynamically select between GL &amp;amp; ES2.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[File:M1506FlowChart.png]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Requirement Analysis'''==&lt;br /&gt;
&lt;br /&gt;
Earlier, only [https://en.wikipedia.org/wiki/OpenGL OpenGL] implementation was supported for Linux targets and we would be extending the [https://en.wikipedia.org/wiki/OpenGL_ES#2.0 ES2] implementation to support it for linux targets too. As a part of the final project, we propose to perform the following steps:&lt;br /&gt;
&lt;br /&gt;
* Change the platform implementation to provide a more generic way to dynamically select between GL and ES2. &lt;br /&gt;
* Remove the Linux/Android specific #cfg flags.&lt;br /&gt;
* Place a general #cfg flag for both Android and Linux to provide a more generic implementation of dynamic selection between GL and ES2&lt;br /&gt;
* Make changes to EGL platform to make it work on desktop GL&lt;br /&gt;
&lt;br /&gt;
=='''Files modified'''==&lt;br /&gt;
&lt;br /&gt;
Servo/components/utils/opts.rs: added the new command line option to allow selecting the graphics backend.&lt;br /&gt;
rust-layers/src/rendergl.rs: changed the RenderContext new function to allow the dynamic selection of graphics backend.&lt;br /&gt;
&lt;br /&gt;
=='''Files to be modified'''==&lt;br /&gt;
&lt;br /&gt;
rust-layers/src/platform/surface.rs: providing generic GL implementation that can dynamically select between the 2 interfaces.&lt;br /&gt;
&lt;br /&gt;
=='''Useful libraries'''==&lt;br /&gt;
&lt;br /&gt;
waffle-gl/waffle: A C library for selecting an OpenGL API and window system at runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Design Pattern'''==&lt;br /&gt;
The aim is to use ES2 implementation of rust layers for both android and Linux. So we need to use a design pattern that will allow us to extend the current implementation to support Linux targets too and give the user the flexibility to choose between the two implementations for rendering the backend.&lt;br /&gt;
&lt;br /&gt;
We propose to use “Decorator” pattern. The decorator pattern gives the user the ability to choose between the implementations that are desired, and attach the corresponding implementation to the target dynamically at runtime.&lt;br /&gt;
&lt;br /&gt;
=='''To Be Determined Information'''==&lt;br /&gt;
* Whether waffle-gl is to be imported, or simply used as example for base functionality&lt;br /&gt;
* Where android surface.rs  implements ES2 vs GL (ie, what is the dividing line between a GL graphics implementation, and an ES2 graphics implementation).&lt;br /&gt;
* Acquiring Android interface to test modified “general” GL_ES implementation.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
1.    https://doc.rust-lang.org/stable/book/&amp;lt;br&amp;gt;&lt;br /&gt;
2.    https://en.wikipedia.org/wiki/Rust_(programming_language)&amp;lt;br&amp;gt;&lt;br /&gt;
3.    https://en.wikipedia.org/wiki/Servo_(layout_engine)&amp;lt;br&amp;gt;&lt;br /&gt;
4.    https://github.com/servo/servo/wiki/Refactor-GLES2-student-project&amp;lt;br&amp;gt;&lt;br /&gt;
5.    http://doc.crates.io/guide.html#overriding-dependencies&amp;lt;br&amp;gt;&lt;br /&gt;
6.    http://rustbyexample.com/&amp;lt;br&amp;gt;&lt;br /&gt;
7.    http://javarevisited.blogspot.com/2014/11/strategy-design-pattern-in-java-using-Enum-Example.html&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=99698</id>
		<title>CSC/ECE 517 Fall 2015/M1506-Refactor-GLES2-Implementation</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=99698"/>
		<updated>2015-11-13T22:58:51Z</updated>

		<summary type="html">&lt;p&gt;Asayal: /* Project Description */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''' Refactor GLES2 Student Project with SERVO &amp;amp; RUST ''''&lt;br /&gt;
&lt;br /&gt;
Servo is a prototype web browser engine written in the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript RUST]&amp;lt;/span&amp;gt; language.Servo uses a variety of back-end implementations for drawing graphics depending on the operating system.One of such back-end is only compatible with Android right now, and we want to extend and refactor that back-end to enable on all Linux systems..&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
===Servo===&lt;br /&gt;
[https://en.wikipedia.org/wiki/Servo_(layout_engine) Servo]Servo is an open source prototype web browser layout engine being developed by Mozilla, and it is written in [https://www.rust-lang.org/ Rust] language. The main idea is to create a highly parallel environment, in which different components can be handled by fine grained, isolated tasks. The different components can be rendering, HTML parsing, etc. &lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://doc.rust-lang.org/book/README.html Rust] is an open source systems programming language developed by Mozilla. Servo is written in Rust. The main purpose behind it's design is to be thread safe and concurrent. The emphasis is also on speed, safety and control of memory layout.&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
* The project requirement initially stated that we build and Compile servo. Following are the steps for this:&lt;br /&gt;
Servo is built with [https://mail.mozilla.org/pipermail/rust-dev/2014-March/009090.html Cargo], the Rust package manager. Mozilla's Mach tools are used to orchestrate the build and other tasks.&lt;br /&gt;
&lt;br /&gt;
    git clone https://github.com/servo/servo&lt;br /&gt;
    cd servo&lt;br /&gt;
    ./mach build --dev&lt;br /&gt;
    ./mach run tests/html/about-mozilla.html&lt;br /&gt;
&lt;br /&gt;
* The next requirement was to build the Rust-layers independently of Servo. For this, we &lt;br /&gt;
* Next, we had to over-ride cargo to use our local copy of Rust-layers, so we had to add a cargo override to it. For this, we created a &amp;lt;code&amp;gt;.cargo&amp;lt;/code&amp;gt; folder in our home directory(same place that servo and Rust-layers reside), and added a &amp;lt;code&amp;gt;config&amp;lt;/code&amp;gt; file to that folder. The content of that config file is a path to our local Rust-layers.&lt;br /&gt;
    paths = [path/to/rust_layers]&lt;br /&gt;
* Next, we had to add a new command line argument in Servo, which would allow selecting the graphics background (GL or ES2). For this, we made the following changes:&lt;br /&gt;
- We added a command line option which lets the user enter the option &amp;lt;code&amp;gt;-E&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;--es2&amp;lt;/code&amp;gt; if the user wants to set ES2 as the graphic back end option. GL is set by default, hence if the user doesn't give any argument, Gl is selected as the graphic back end option. Example is as below&lt;br /&gt;
    ./mach run [url] -E&lt;br /&gt;
* Next, we had to add a flag in Rust-layers. This change was made in the file [https://github.com/prashantgupta24/rust-layers/blob/master/src/rendergl.rs Rust/src/rendergl.rs] in the &amp;lt;code&amp;gt;RenderContext::new&amp;lt;/code&amp;gt; function. For this, we did the following change:&lt;br /&gt;
- We defined an enum &amp;lt;code&amp;gt;GraphicOption&amp;lt;/code&amp;gt; which defined two options &amp;lt;code&amp;gt;GL&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ES2&amp;lt;/code&amp;gt; and then based on the boolean value from the servo &amp;lt;code&amp;gt;opts.rs&amp;lt;/code&amp;gt;, we set a variable with the respective enum value &amp;lt;code&amp;gt;GL&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;ES2&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Then, we had to use the new command line option to pass the selected graphics back-end option to the Rust-layers context which we created in the previous step. For this we made changes to the [https://github.com/prashantgupta24/servo/blob/master/components/compositing/compositor.rs compositor.rs] in Compositing folder which is how Servo interacts with the Rust layers. The command line option is passed through the &amp;lt;code&amp;gt;initialize_compositing&amp;lt;/code&amp;gt; function.&lt;br /&gt;
* Now we need to change the platform implementation in [https://github.com/servo/rust-layers/blob/master/src/platform/surface.rs surface.rs] and provide a generic implementation to dynamically select between GL &amp;amp; ES2.&lt;br /&gt;
&lt;br /&gt;
[[File:M1506FlowChart.png]]&lt;br /&gt;
&lt;br /&gt;
=='''Requirement Analysis'''==&lt;br /&gt;
&lt;br /&gt;
Earlier, only [https://en.wikipedia.org/wiki/OpenGL OpenGL] implementation was supported for Linux targets and we would be extending the [https://en.wikipedia.org/wiki/OpenGL_ES#2.0 ES2] implementation to support it for linux targets too. As a part of the final project, we propose to perform the following steps:&lt;br /&gt;
&lt;br /&gt;
* Change the platform implementation to provide a more generic way to dynamically select between GL and ES2. &lt;br /&gt;
* Remove the Linux/Android specific #cfg flags.&lt;br /&gt;
* Place a general #cfg flag for both Android and Linux to provide a more generic implementation of dynamic selection between GL and ES2&lt;br /&gt;
* Make changes to EGL platform to make it work on desktop GL&lt;br /&gt;
&lt;br /&gt;
=='''Files modified'''==&lt;br /&gt;
&lt;br /&gt;
Servo/components/utils/opts.rs: added the new command line option to allow selecting the graphics backend.&lt;br /&gt;
rust-layers/src/rendergl.rs: changed the RenderContext new function to allow the dynamic selection of graphics backend.&lt;br /&gt;
&lt;br /&gt;
=='''Files to be modified'''==&lt;br /&gt;
&lt;br /&gt;
rust-layers/src/platform/surface.rs: providing generic GL implementation that can dynamically select between the 2 interfaces.&lt;br /&gt;
&lt;br /&gt;
=='''Useful libraries'''==&lt;br /&gt;
&lt;br /&gt;
waffle-gl/waffle: A C library for selecting an OpenGL API and window system at runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Design Pattern'''==&lt;br /&gt;
The aim is to use ES2 implementation of rust layers for both android and Linux. So we need to use a design pattern that will allow us to extend the current implementation to support Linux targets too and give the user the flexibility to choose between the two implementations for rendering the backend.&lt;br /&gt;
&lt;br /&gt;
We propose to use “Decorator” pattern. The decorator pattern gives the user the ability to choose between the implementations that are desired, and attach the corresponding implementation to the target dynamically at runtime.&lt;br /&gt;
&lt;br /&gt;
=='''To Be Determined Information'''==&lt;br /&gt;
* Whether waffle-gl is to be imported, or simply used as example for base functionality&lt;br /&gt;
* Where android surface.rs  implements ES2 vs GL (ie, what is the dividing line between a GL graphics implementation, and an ES2 graphics implementation).&lt;br /&gt;
* Acquiring Android interface to test modified “general” GL_ES implementation.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
1.    https://doc.rust-lang.org/stable/book/&amp;lt;br&amp;gt;&lt;br /&gt;
2.    https://en.wikipedia.org/wiki/Rust_(programming_language)&amp;lt;br&amp;gt;&lt;br /&gt;
3.    https://en.wikipedia.org/wiki/Servo_(layout_engine)&amp;lt;br&amp;gt;&lt;br /&gt;
4.    https://github.com/servo/servo/wiki/Refactor-GLES2-student-project&amp;lt;br&amp;gt;&lt;br /&gt;
5.    http://doc.crates.io/guide.html#overriding-dependencies&amp;lt;br&amp;gt;&lt;br /&gt;
6.    http://rustbyexample.com/&amp;lt;br&amp;gt;&lt;br /&gt;
7.    http://javarevisited.blogspot.com/2014/11/strategy-design-pattern-in-java-using-Enum-Example.html&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:M1506FlowChart.png&amp;diff=99697</id>
		<title>File:M1506FlowChart.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:M1506FlowChart.png&amp;diff=99697"/>
		<updated>2015-11-13T22:58:03Z</updated>

		<summary type="html">&lt;p&gt;Asayal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Flowchart.png&amp;diff=99695</id>
		<title>File:Flowchart.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Flowchart.png&amp;diff=99695"/>
		<updated>2015-11-13T22:56:40Z</updated>

		<summary type="html">&lt;p&gt;Asayal: uploaded a new version of &amp;amp;quot;File:Flowchart.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=99679</id>
		<title>CSC/ECE 517 Fall 2015/M1506-Refactor-GLES2-Implementation</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=99679"/>
		<updated>2015-11-13T22:27:23Z</updated>

		<summary type="html">&lt;p&gt;Asayal: /* Conclusion */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''' Refactor GLES2 Student Project with SERVO &amp;amp; RUST ''''&lt;br /&gt;
&lt;br /&gt;
Servo is a prototype web browser engine written in the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript RUST]&amp;lt;/span&amp;gt; language.Servo uses a variety of back-end implementations for drawing graphics depending on the operating system.One of such back-end is only compatible with Android right now, and we want to extend and refactor that back-end to enable on all Linux systems..&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
===Servo===&lt;br /&gt;
[https://en.wikipedia.org/wiki/Servo_(layout_engine) Servo]Servo is an open source prototype web browser layout engine being developed by Mozilla, and it is written in [https://www.rust-lang.org/ Rust] language. The main idea is to create a highly parallel environment, in which different components can be handled by fine grained, isolated tasks. The different components can be rendering, HTML parsing, etc. &lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://doc.rust-lang.org/book/README.html Rust] is an open source systems programming language developed by Mozilla. Servo is written in Rust. The main purpose behind it's design is to be thread safe and concurrent. The emphasis is also on speed, safety and control of memory layout.&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
* The project requirement initially stated that we build and Compile servo. Following are the steps for this:&lt;br /&gt;
Servo is built with [https://mail.mozilla.org/pipermail/rust-dev/2014-March/009090.html Cargo], the Rust package manager. Mozilla's Mach tools are used to orchestrate the build and other tasks.&lt;br /&gt;
&lt;br /&gt;
    git clone https://github.com/servo/servo&lt;br /&gt;
    cd servo&lt;br /&gt;
    ./mach build --dev&lt;br /&gt;
    ./mach run tests/html/about-mozilla.html&lt;br /&gt;
&lt;br /&gt;
* The next requirement was to build the Rust-layers independently of Servo. For this, we &lt;br /&gt;
* Next, we had to over-ride cargo to use our local copy of Rust-layers, so we had to add a cargo override to it. For this, we created a &amp;lt;code&amp;gt;.cargo&amp;lt;/code&amp;gt; folder in our home directory(same place that servo and Rust-layers reside), and added a &amp;lt;code&amp;gt;config&amp;lt;/code&amp;gt; file to that folder. The content of that config file is a path to our local Rust-layers.&lt;br /&gt;
    paths = [path/to/rust_layers]&lt;br /&gt;
* Next, we had to add a new command line argument in Servo, which would allow selecting the graphics background (GL or ES2). For this, we made the following changes:&lt;br /&gt;
- We added a command line option which lets the user enter the option &amp;lt;code&amp;gt;-E&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;--es2&amp;lt;/code&amp;gt; if the user wants to set ES2 as the graphic back end option. GL is set by default, hence if the user doesn't give any argument, Gl is selected as the graphic back end option. Example is as below&lt;br /&gt;
    ./mach run [url] -E&lt;br /&gt;
* Next, we had to add a flag in Rust-layers. This change was made in the file [https://github.com/prashantgupta24/rust-layers/blob/master/src/rendergl.rs Rust/src/rendergl.rs] in the &amp;lt;code&amp;gt;RenderContext::new&amp;lt;/code&amp;gt; function. For this, we did the following change:&lt;br /&gt;
- We defined an enum &amp;lt;code&amp;gt;GraphicOption&amp;lt;/code&amp;gt; which defined two options &amp;lt;code&amp;gt;GL&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ES2&amp;lt;/code&amp;gt; and then based on the boolean value from the servo &amp;lt;code&amp;gt;opts.rs&amp;lt;/code&amp;gt;, we set a variable with the respective enum value &amp;lt;code&amp;gt;GL&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;ES2&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Then, we had to use the new command line option to pass the selected graphics back-end option to the Rust-layers context which we created in the previous step. For this we made changes to the [https://github.com/prashantgupta24/servo/blob/master/components/compositing/compositor.rs compositor.rs] in Compositing folder which is how Servo interacts with the Rust layers. The command line option is passed through the &amp;lt;code&amp;gt;initialize_compositing&amp;lt;/code&amp;gt; function.&lt;br /&gt;
* Now &lt;br /&gt;
&lt;br /&gt;
=='''Requirement Analysis'''==&lt;br /&gt;
&lt;br /&gt;
Earlier, only [https://en.wikipedia.org/wiki/OpenGL OpenGL] implementation was supported for Linux targets and we would be extending the [https://en.wikipedia.org/wiki/OpenGL_ES#2.0 ES2] implementation to support it for linux targets too. As a part of the final project, we propose to perform the following steps:&lt;br /&gt;
&lt;br /&gt;
* Change the platform implementation to provide a more generic way to dynamically select between GL and ES2. &lt;br /&gt;
* Remove the Linux/Android specific #cfg flags.&lt;br /&gt;
* Place a general #cfg flag for both Android and Linux to provide a more generic implementation of dynamic selection between GL and ES2&lt;br /&gt;
* Make changes to EGL platform to make it work on desktop GL&lt;br /&gt;
&lt;br /&gt;
=='''Files modified'''==&lt;br /&gt;
&lt;br /&gt;
Servo/components/utils/opts.rs: added the new command line option to allow selecting the graphics backend.&lt;br /&gt;
rust-layers/src/rendergl.rs: changed the RenderContext new function to allow the dynamic selection of graphics backend.&lt;br /&gt;
&lt;br /&gt;
=='''Files to be modified'''==&lt;br /&gt;
&lt;br /&gt;
rust-layers/src/platform/surface.rs: providing generic GL implementation that can dynamically select between the 2 interfaces.&lt;br /&gt;
&lt;br /&gt;
=='''Useful libraries'''==&lt;br /&gt;
&lt;br /&gt;
waffle-gl/waffle: A C library for selecting an OpenGL API and window system at runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Design Pattern'''==&lt;br /&gt;
The aim is to use ES2 implementation of rust layers for both android and Linux. So we need to use a design pattern that will allow us to extend the current implementation to support Linux targets too and give the user the flexibility to choose between the two implementations for rendering the backend.&lt;br /&gt;
&lt;br /&gt;
We propose to use “Decorator” pattern. The decorator pattern gives the user the ability to choose between the implementations that are desired, and attach the corresponding implementation to the target dynamically at runtime.&lt;br /&gt;
&lt;br /&gt;
=='''To Be Determined Information'''==&lt;br /&gt;
* Whether waffle-gl is to be imported, or simply used as example for base functionality&lt;br /&gt;
* Where android surface.rs  implements ES2 vs GL (ie, what is the dividing line between a GL graphics implementation, and an ES2 graphics implementation).&lt;br /&gt;
* Acquiring Android interface to test modified “general” GL_ES implementation.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
1.    https://doc.rust-lang.org/stable/book/&amp;lt;br&amp;gt;&lt;br /&gt;
2.    https://en.wikipedia.org/wiki/Rust_(programming_language)&amp;lt;br&amp;gt;&lt;br /&gt;
3.    https://en.wikipedia.org/wiki/Servo_(layout_engine)&amp;lt;br&amp;gt;&lt;br /&gt;
4.    https://github.com/servo/servo/wiki/Refactor-GLES2-student-project&amp;lt;br&amp;gt;&lt;br /&gt;
5.    http://doc.crates.io/guide.html#overriding-dependencies&amp;lt;br&amp;gt;&lt;br /&gt;
6.    http://rustbyexample.com/&amp;lt;br&amp;gt;&lt;br /&gt;
7.    http://javarevisited.blogspot.com/2014/11/strategy-design-pattern-in-java-using-Enum-Example.html&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=99673</id>
		<title>CSC/ECE 517 Fall 2015/M1506-Refactor-GLES2-Implementation</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=99673"/>
		<updated>2015-11-13T22:20:10Z</updated>

		<summary type="html">&lt;p&gt;Asayal: /* To Be Determined Information */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''' Refactor GLES2 Student Project with SERVO &amp;amp; RUST ''''&lt;br /&gt;
&lt;br /&gt;
Servo is a prototype web browser engine written in the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript RUST]&amp;lt;/span&amp;gt; language.Servo uses a variety of back-end implementations for drawing graphics depending on the operating system.One of such back-end is only compatible with Android right now, and we want to extend and refactor that back-end to enable on all Linux systems..&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
===Servo===&lt;br /&gt;
[https://en.wikipedia.org/wiki/Servo_(layout_engine) Servo]Servo is an open source prototype web browser layout engine being developed by Mozilla, and it is written in [https://www.rust-lang.org/ Rust] language. The main idea is to create a highly parallel environment, in which different components can be handled by fine grained, isolated tasks. The different components can be rendering, HTML parsing, etc. &lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://doc.rust-lang.org/book/README.html Rust] is an open source systems programming language developed by Mozilla. Servo is written in Rust. The main purpose behind it's design is to be thread safe and concurrent. The emphasis is also on speed, safety and control of memory layout.&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
* The project requirement initially stated that we build and Compile servo. Following are the steps for this:&lt;br /&gt;
Servo is built with [https://mail.mozilla.org/pipermail/rust-dev/2014-March/009090.html Cargo], the Rust package manager. Mozilla's Mach tools are used to orchestrate the build and other tasks.&lt;br /&gt;
&lt;br /&gt;
    git clone https://github.com/servo/servo&lt;br /&gt;
    cd servo&lt;br /&gt;
    ./mach build --dev&lt;br /&gt;
    ./mach run tests/html/about-mozilla.html&lt;br /&gt;
&lt;br /&gt;
* The next requirement was to build the Rust-layers independently of Servo. For this, we &lt;br /&gt;
* Next, we had to over-ride cargo to use our local copy of Rust-layers, so we had to add a cargo override to it. For this, we created a &amp;lt;code&amp;gt;.cargo&amp;lt;/code&amp;gt; folder in our home directory(same place that servo and Rust-layers reside), and added a &amp;lt;code&amp;gt;config&amp;lt;/code&amp;gt; file to that folder. The content of that config file is a path to our local Rust-layers.&lt;br /&gt;
    paths = [path/to/rust_layers]&lt;br /&gt;
* Next, we had to add a new command line argument in Servo, which would allow selecting the graphics background (GL or ES2). For this, we made the following changes:&lt;br /&gt;
- We added a command line option which lets the user enter the option &amp;lt;code&amp;gt;-E&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;--es2&amp;lt;/code&amp;gt; if the user wants to set ES2 as the graphic back end option. GL is set by default, hence if the user doesn't give any argument, Gl is selected as the graphic back end option. Example is as below&lt;br /&gt;
    ./mach run [url] -E&lt;br /&gt;
* Next, we had to add a flag in Rust-layers. This change was made in the file [https://github.com/prashantgupta24/rust-layers/blob/master/src/rendergl.rs Rust/src/rendergl.rs] in the &amp;lt;code&amp;gt;RenderContext::new&amp;lt;/code&amp;gt; function. For this, we did the following change:&lt;br /&gt;
- We defined an enum &amp;lt;code&amp;gt;GraphicOption&amp;lt;/code&amp;gt; which defined two options &amp;lt;code&amp;gt;GL&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ES2&amp;lt;/code&amp;gt; and then based on the boolean value from the servo &amp;lt;code&amp;gt;opts.rs&amp;lt;/code&amp;gt;, we set a variable with the respective enum value &amp;lt;code&amp;gt;GL&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;ES2&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Finally, we had to use the new command line option to pass the selected graphics back-end option to the Rust-layers context which we created in the previous step. For this we made changes to the [https://github.com/prashantgupta24/servo/blob/master/components/compositing/compositor.rs compositor.rs] in Compositing folder which is how Servo interacts with the Rust layers. The command line option is passed through the &amp;lt;code&amp;gt;initialize_compositing&amp;lt;/code&amp;gt; function.&lt;br /&gt;
&lt;br /&gt;
=='''Requirement Analysis'''==&lt;br /&gt;
&lt;br /&gt;
Earlier, only [https://en.wikipedia.org/wiki/OpenGL OpenGL] implementation was supported for Linux targets and we would be extending the [https://en.wikipedia.org/wiki/OpenGL_ES#2.0 ES2] implementation to support it for linux targets too. As a part of the final project, we propose to perform the following steps:&lt;br /&gt;
&lt;br /&gt;
* Change the platform implementation to provide a more generic way to dynamically select between GL and ES2. &lt;br /&gt;
* Remove the Linux/Android specific #cfg flags.&lt;br /&gt;
* Place a general #cfg flag for both Android and Linux to provide a more generic implementation of dynamic selection between GL and ES2&lt;br /&gt;
* Make changes to EGL platform to make it work on desktop GL&lt;br /&gt;
&lt;br /&gt;
=='''Files modified'''==&lt;br /&gt;
&lt;br /&gt;
Servo/components/utils/opts.rs: added the new command line option to allow selecting the graphics backend.&lt;br /&gt;
rust-layers/src/rendergl.rs: changed the RenderContext new function to allow the dynamic selection of graphics backend.&lt;br /&gt;
&lt;br /&gt;
=='''Files to be modified'''==&lt;br /&gt;
&lt;br /&gt;
rust-layers/src/platform/surface.rs: providing generic GL implementation that can dynamically select between the 2 interfaces.&lt;br /&gt;
&lt;br /&gt;
=='''Useful libraries'''==&lt;br /&gt;
&lt;br /&gt;
waffle-gl/waffle: A C library for selecting an OpenGL API and window system at runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Design Pattern'''==&lt;br /&gt;
The aim is to use ES2 implementation of rust layers for both android and Linux. So we need to use a design pattern that will allow us to extend the current implementation to support Linux targets too and give the user the flexibility to choose between the two implementations for rendering the backend.&lt;br /&gt;
&lt;br /&gt;
We propose to use “Decorator” pattern. The decorator pattern gives the user the ability to choose between the implementations that are desired, and attach the corresponding implementation to the target dynamically at runtime.&lt;br /&gt;
&lt;br /&gt;
=='''To Be Determined Information'''==&lt;br /&gt;
* Whether waffle-gl is to be imported, or simply used as example for base functionality&lt;br /&gt;
* Where android surface.rs  implements ES2 vs GL (ie, what is the dividing line between a GL graphics implementation, and an ES2 graphics implementation).&lt;br /&gt;
* Acquiring Android interface to test modified “general” GL_ES implementation.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
After making our changes , the user can now dynamically pass in the option of GL or ES2 through the graphic command line option, and this option is passed on through the compositor to the rust layers during initialization. A video demonstration for the code changes is available [https://drive.google.com/file/d/0B9TVPg3YRoHqQUlvQXZkUUJPRzA/view?usp=sharing here]&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
1.    https://doc.rust-lang.org/stable/book/&amp;lt;br&amp;gt;&lt;br /&gt;
2.    https://en.wikipedia.org/wiki/Rust_(programming_language)&amp;lt;br&amp;gt;&lt;br /&gt;
3.    https://en.wikipedia.org/wiki/Servo_(layout_engine)&amp;lt;br&amp;gt;&lt;br /&gt;
4.    https://github.com/servo/servo/wiki/Refactor-GLES2-student-project&amp;lt;br&amp;gt;&lt;br /&gt;
5.    http://doc.crates.io/guide.html#overriding-dependencies&amp;lt;br&amp;gt;&lt;br /&gt;
6.    http://rustbyexample.com/&amp;lt;br&amp;gt;&lt;br /&gt;
7.    http://javarevisited.blogspot.com/2014/11/strategy-design-pattern-in-java-using-Enum-Example.html&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=99672</id>
		<title>CSC/ECE 517 Fall 2015/M1506-Refactor-GLES2-Implementation</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=99672"/>
		<updated>2015-11-13T22:19:46Z</updated>

		<summary type="html">&lt;p&gt;Asayal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''' Refactor GLES2 Student Project with SERVO &amp;amp; RUST ''''&lt;br /&gt;
&lt;br /&gt;
Servo is a prototype web browser engine written in the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript RUST]&amp;lt;/span&amp;gt; language.Servo uses a variety of back-end implementations for drawing graphics depending on the operating system.One of such back-end is only compatible with Android right now, and we want to extend and refactor that back-end to enable on all Linux systems..&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
===Servo===&lt;br /&gt;
[https://en.wikipedia.org/wiki/Servo_(layout_engine) Servo]Servo is an open source prototype web browser layout engine being developed by Mozilla, and it is written in [https://www.rust-lang.org/ Rust] language. The main idea is to create a highly parallel environment, in which different components can be handled by fine grained, isolated tasks. The different components can be rendering, HTML parsing, etc. &lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://doc.rust-lang.org/book/README.html Rust] is an open source systems programming language developed by Mozilla. Servo is written in Rust. The main purpose behind it's design is to be thread safe and concurrent. The emphasis is also on speed, safety and control of memory layout.&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
* The project requirement initially stated that we build and Compile servo. Following are the steps for this:&lt;br /&gt;
Servo is built with [https://mail.mozilla.org/pipermail/rust-dev/2014-March/009090.html Cargo], the Rust package manager. Mozilla's Mach tools are used to orchestrate the build and other tasks.&lt;br /&gt;
&lt;br /&gt;
    git clone https://github.com/servo/servo&lt;br /&gt;
    cd servo&lt;br /&gt;
    ./mach build --dev&lt;br /&gt;
    ./mach run tests/html/about-mozilla.html&lt;br /&gt;
&lt;br /&gt;
* The next requirement was to build the Rust-layers independently of Servo. For this, we &lt;br /&gt;
* Next, we had to over-ride cargo to use our local copy of Rust-layers, so we had to add a cargo override to it. For this, we created a &amp;lt;code&amp;gt;.cargo&amp;lt;/code&amp;gt; folder in our home directory(same place that servo and Rust-layers reside), and added a &amp;lt;code&amp;gt;config&amp;lt;/code&amp;gt; file to that folder. The content of that config file is a path to our local Rust-layers.&lt;br /&gt;
    paths = [path/to/rust_layers]&lt;br /&gt;
* Next, we had to add a new command line argument in Servo, which would allow selecting the graphics background (GL or ES2). For this, we made the following changes:&lt;br /&gt;
- We added a command line option which lets the user enter the option &amp;lt;code&amp;gt;-E&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;--es2&amp;lt;/code&amp;gt; if the user wants to set ES2 as the graphic back end option. GL is set by default, hence if the user doesn't give any argument, Gl is selected as the graphic back end option. Example is as below&lt;br /&gt;
    ./mach run [url] -E&lt;br /&gt;
* Next, we had to add a flag in Rust-layers. This change was made in the file [https://github.com/prashantgupta24/rust-layers/blob/master/src/rendergl.rs Rust/src/rendergl.rs] in the &amp;lt;code&amp;gt;RenderContext::new&amp;lt;/code&amp;gt; function. For this, we did the following change:&lt;br /&gt;
- We defined an enum &amp;lt;code&amp;gt;GraphicOption&amp;lt;/code&amp;gt; which defined two options &amp;lt;code&amp;gt;GL&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ES2&amp;lt;/code&amp;gt; and then based on the boolean value from the servo &amp;lt;code&amp;gt;opts.rs&amp;lt;/code&amp;gt;, we set a variable with the respective enum value &amp;lt;code&amp;gt;GL&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;ES2&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Finally, we had to use the new command line option to pass the selected graphics back-end option to the Rust-layers context which we created in the previous step. For this we made changes to the [https://github.com/prashantgupta24/servo/blob/master/components/compositing/compositor.rs compositor.rs] in Compositing folder which is how Servo interacts with the Rust layers. The command line option is passed through the &amp;lt;code&amp;gt;initialize_compositing&amp;lt;/code&amp;gt; function.&lt;br /&gt;
&lt;br /&gt;
=='''Requirement Analysis'''==&lt;br /&gt;
&lt;br /&gt;
Earlier, only [https://en.wikipedia.org/wiki/OpenGL OpenGL] implementation was supported for Linux targets and we would be extending the [https://en.wikipedia.org/wiki/OpenGL_ES#2.0 ES2] implementation to support it for linux targets too. As a part of the final project, we propose to perform the following steps:&lt;br /&gt;
&lt;br /&gt;
* Change the platform implementation to provide a more generic way to dynamically select between GL and ES2. &lt;br /&gt;
* Remove the Linux/Android specific #cfg flags.&lt;br /&gt;
* Place a general #cfg flag for both Android and Linux to provide a more generic implementation of dynamic selection between GL and ES2&lt;br /&gt;
* Make changes to EGL platform to make it work on desktop GL&lt;br /&gt;
&lt;br /&gt;
=='''Files modified'''==&lt;br /&gt;
&lt;br /&gt;
Servo/components/utils/opts.rs: added the new command line option to allow selecting the graphics backend.&lt;br /&gt;
rust-layers/src/rendergl.rs: changed the RenderContext new function to allow the dynamic selection of graphics backend.&lt;br /&gt;
&lt;br /&gt;
=='''Files to be modified'''==&lt;br /&gt;
&lt;br /&gt;
rust-layers/src/platform/surface.rs: providing generic GL implementation that can dynamically select between the 2 interfaces.&lt;br /&gt;
&lt;br /&gt;
=='''Useful libraries'''==&lt;br /&gt;
&lt;br /&gt;
waffle-gl/waffle: A C library for selecting an OpenGL API and window system at runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Design Pattern'''==&lt;br /&gt;
The aim is to use ES2 implementation of rust layers for both android and Linux. So we need to use a design pattern that will allow us to extend the current implementation to support Linux targets too and give the user the flexibility to choose between the two implementations for rendering the backend.&lt;br /&gt;
&lt;br /&gt;
We propose to use “Decorator” pattern. The decorator pattern gives the user the ability to choose between the implementations that are desired, and attach the corresponding implementation to the target dynamically at runtime.&lt;br /&gt;
&lt;br /&gt;
=='''To Be Determined Information'''==&lt;br /&gt;
Whether waffle-gl is to be imported, or simply used as example for base functionality&lt;br /&gt;
Where android surface.rs  implements ES2 vs GL (ie, what is the dividing line between a GL graphics implementation, and an ES2 graphics implementation).&lt;br /&gt;
Acquiring Android interface to test modified “general” GL_ES implementation.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
After making our changes , the user can now dynamically pass in the option of GL or ES2 through the graphic command line option, and this option is passed on through the compositor to the rust layers during initialization. A video demonstration for the code changes is available [https://drive.google.com/file/d/0B9TVPg3YRoHqQUlvQXZkUUJPRzA/view?usp=sharing here]&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
1.    https://doc.rust-lang.org/stable/book/&amp;lt;br&amp;gt;&lt;br /&gt;
2.    https://en.wikipedia.org/wiki/Rust_(programming_language)&amp;lt;br&amp;gt;&lt;br /&gt;
3.    https://en.wikipedia.org/wiki/Servo_(layout_engine)&amp;lt;br&amp;gt;&lt;br /&gt;
4.    https://github.com/servo/servo/wiki/Refactor-GLES2-student-project&amp;lt;br&amp;gt;&lt;br /&gt;
5.    http://doc.crates.io/guide.html#overriding-dependencies&amp;lt;br&amp;gt;&lt;br /&gt;
6.    http://rustbyexample.com/&amp;lt;br&amp;gt;&lt;br /&gt;
7.    http://javarevisited.blogspot.com/2014/11/strategy-design-pattern-in-java-using-Enum-Example.html&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=99669</id>
		<title>CSC/ECE 517 Fall 2015/M1506-Refactor-GLES2-Implementation</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=99669"/>
		<updated>2015-11-13T22:16:26Z</updated>

		<summary type="html">&lt;p&gt;Asayal: /* Design Pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''' Refactor GLES2 Student Project with SERVO &amp;amp; RUST ''''&lt;br /&gt;
&lt;br /&gt;
Servo is a prototype web browser engine written in the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript RUST]&amp;lt;/span&amp;gt; language.Servo uses a variety of back-end implementations for drawing graphics depending on the operating system.One of such back-end is only compatible with Android right now, and we want to extend and refactor that back-end to enable on all Linux systems..&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
===Servo===&lt;br /&gt;
[https://en.wikipedia.org/wiki/Servo_(layout_engine) Servo]Servo is an open source prototype web browser layout engine being developed by Mozilla, and it is written in [https://www.rust-lang.org/ Rust] language. The main idea is to create a highly parallel environment, in which different components can be handled by fine grained, isolated tasks. The different components can be rendering, HTML parsing, etc. &lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://doc.rust-lang.org/book/README.html Rust] is an open source systems programming language developed by Mozilla. Servo is written in Rust. The main purpose behind it's design is to be thread safe and concurrent. The emphasis is also on speed, safety and control of memory layout.&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
* The project requirement initially stated that we build and Compile servo. Following are the steps for this:&lt;br /&gt;
Servo is built with [https://mail.mozilla.org/pipermail/rust-dev/2014-March/009090.html Cargo], the Rust package manager. Mozilla's Mach tools are used to orchestrate the build and other tasks.&lt;br /&gt;
&lt;br /&gt;
    git clone https://github.com/servo/servo&lt;br /&gt;
    cd servo&lt;br /&gt;
    ./mach build --dev&lt;br /&gt;
    ./mach run tests/html/about-mozilla.html&lt;br /&gt;
&lt;br /&gt;
* The next requirement was to build the Rust-layers independently of Servo. For this, we &lt;br /&gt;
* Next, we had to over-ride cargo to use our local copy of Rust-layers, so we had to add a cargo override to it. For this, we created a &amp;lt;code&amp;gt;.cargo&amp;lt;/code&amp;gt; folder in our home directory(same place that servo and Rust-layers reside), and added a &amp;lt;code&amp;gt;config&amp;lt;/code&amp;gt; file to that folder. The content of that config file is a path to our local Rust-layers.&lt;br /&gt;
    paths = [path/to/rust_layers]&lt;br /&gt;
* Next, we had to add a new command line argument in Servo, which would allow selecting the graphics background (GL or ES2). For this, we made the following changes:&lt;br /&gt;
- We added a command line option which lets the user enter the option &amp;lt;code&amp;gt;-E&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;--es2&amp;lt;/code&amp;gt; if the user wants to set ES2 as the graphic back end option. GL is set by default, hence if the user doesn't give any argument, Gl is selected as the graphic back end option. Example is as below&lt;br /&gt;
    ./mach run [url] -E&lt;br /&gt;
* Next, we had to add a flag in Rust-layers. This change was made in the file [https://github.com/prashantgupta24/rust-layers/blob/master/src/rendergl.rs Rust/src/rendergl.rs] in the &amp;lt;code&amp;gt;RenderContext::new&amp;lt;/code&amp;gt; function. For this, we did the following change:&lt;br /&gt;
- We defined an enum &amp;lt;code&amp;gt;GraphicOption&amp;lt;/code&amp;gt; which defined two options &amp;lt;code&amp;gt;GL&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ES2&amp;lt;/code&amp;gt; and then based on the boolean value from the servo &amp;lt;code&amp;gt;opts.rs&amp;lt;/code&amp;gt;, we set a variable with the respective enum value &amp;lt;code&amp;gt;GL&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;ES2&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Finally, we had to use the new command line option to pass the selected graphics back-end option to the Rust-layers context which we created in the previous step. For this we made changes to the [https://github.com/prashantgupta24/servo/blob/master/components/compositing/compositor.rs compositor.rs] in Compositing folder which is how Servo interacts with the Rust layers. The command line option is passed through the &amp;lt;code&amp;gt;initialize_compositing&amp;lt;/code&amp;gt; function.&lt;br /&gt;
&lt;br /&gt;
=='''Requirement Analysis'''==&lt;br /&gt;
&lt;br /&gt;
Earlier, only [https://en.wikipedia.org/wiki/OpenGL OpenGL] implementation was supported for Linux targets and we would be extending the [https://en.wikipedia.org/wiki/OpenGL_ES#2.0 ES2] implementation to support it for linux targets too. As a part of the final project, we propose to perform the following steps:&lt;br /&gt;
&lt;br /&gt;
* Change the platform implementation to provide a more generic way to dynamically select between GL and ES2. &lt;br /&gt;
* Remove the Linux/Android specific #cfg flags.&lt;br /&gt;
* Place a general #cfg flag for both Android and Linux to provide a more generic implementation of dynamic selection between GL and ES2&lt;br /&gt;
* Make changes to EGL platform to make it work on desktop GL&lt;br /&gt;
&lt;br /&gt;
=='''Files modified'''==&lt;br /&gt;
&lt;br /&gt;
Servo/components/utils/opts.rs: added the new command line option to allow selecting the graphics backend.&lt;br /&gt;
rust-layers/src/rendergl.rs: changed the RenderContext new function to allow the dynamic selection of graphics backend.&lt;br /&gt;
&lt;br /&gt;
=='''Files to be modified'''==&lt;br /&gt;
&lt;br /&gt;
rust-layers/src/platform/surface.rs: providing generic GL implementation that can dynamically select between the 2 interfaces.&lt;br /&gt;
&lt;br /&gt;
=='''Useful libraries'''==&lt;br /&gt;
&lt;br /&gt;
waffle-gl/waffle: A C library for selecting an OpenGL API and window system at runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Design Pattern'''==&lt;br /&gt;
The aim is to use ES2 implementation of rust layers for both android and Linux. So we need to use a design pattern that will allow us to extend the current implementation to support Linux targets too and give the user the flexibility to choose between the two implementations for rendering the backend.&lt;br /&gt;
&lt;br /&gt;
We propose to use “Decorator” pattern. The decorator pattern gives the user the ability to choose between the implementations that are desired, and attach the corresponding implementation to the target dynamically at runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
After making our changes , the user can now dynamically pass in the option of GL or ES2 through the graphic command line option, and this option is passed on through the compositor to the rust layers during initialization. A video demonstration for the code changes is available [https://drive.google.com/file/d/0B9TVPg3YRoHqQUlvQXZkUUJPRzA/view?usp=sharing here]&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
1.    https://doc.rust-lang.org/stable/book/&amp;lt;br&amp;gt;&lt;br /&gt;
2.    https://en.wikipedia.org/wiki/Rust_(programming_language)&amp;lt;br&amp;gt;&lt;br /&gt;
3.    https://en.wikipedia.org/wiki/Servo_(layout_engine)&amp;lt;br&amp;gt;&lt;br /&gt;
4.    https://github.com/servo/servo/wiki/Refactor-GLES2-student-project&amp;lt;br&amp;gt;&lt;br /&gt;
5.    http://doc.crates.io/guide.html#overriding-dependencies&amp;lt;br&amp;gt;&lt;br /&gt;
6.    http://rustbyexample.com/&amp;lt;br&amp;gt;&lt;br /&gt;
7.    http://javarevisited.blogspot.com/2014/11/strategy-design-pattern-in-java-using-Enum-Example.html&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=99668</id>
		<title>CSC/ECE 517 Fall 2015/M1506-Refactor-GLES2-Implementation</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=99668"/>
		<updated>2015-11-13T22:14:57Z</updated>

		<summary type="html">&lt;p&gt;Asayal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''' Refactor GLES2 Student Project with SERVO &amp;amp; RUST ''''&lt;br /&gt;
&lt;br /&gt;
Servo is a prototype web browser engine written in the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript RUST]&amp;lt;/span&amp;gt; language.Servo uses a variety of back-end implementations for drawing graphics depending on the operating system.One of such back-end is only compatible with Android right now, and we want to extend and refactor that back-end to enable on all Linux systems..&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
===Servo===&lt;br /&gt;
[https://en.wikipedia.org/wiki/Servo_(layout_engine) Servo]Servo is an open source prototype web browser layout engine being developed by Mozilla, and it is written in [https://www.rust-lang.org/ Rust] language. The main idea is to create a highly parallel environment, in which different components can be handled by fine grained, isolated tasks. The different components can be rendering, HTML parsing, etc. &lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://doc.rust-lang.org/book/README.html Rust] is an open source systems programming language developed by Mozilla. Servo is written in Rust. The main purpose behind it's design is to be thread safe and concurrent. The emphasis is also on speed, safety and control of memory layout.&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
* The project requirement initially stated that we build and Compile servo. Following are the steps for this:&lt;br /&gt;
Servo is built with [https://mail.mozilla.org/pipermail/rust-dev/2014-March/009090.html Cargo], the Rust package manager. Mozilla's Mach tools are used to orchestrate the build and other tasks.&lt;br /&gt;
&lt;br /&gt;
    git clone https://github.com/servo/servo&lt;br /&gt;
    cd servo&lt;br /&gt;
    ./mach build --dev&lt;br /&gt;
    ./mach run tests/html/about-mozilla.html&lt;br /&gt;
&lt;br /&gt;
* The next requirement was to build the Rust-layers independently of Servo. For this, we &lt;br /&gt;
* Next, we had to over-ride cargo to use our local copy of Rust-layers, so we had to add a cargo override to it. For this, we created a &amp;lt;code&amp;gt;.cargo&amp;lt;/code&amp;gt; folder in our home directory(same place that servo and Rust-layers reside), and added a &amp;lt;code&amp;gt;config&amp;lt;/code&amp;gt; file to that folder. The content of that config file is a path to our local Rust-layers.&lt;br /&gt;
    paths = [path/to/rust_layers]&lt;br /&gt;
* Next, we had to add a new command line argument in Servo, which would allow selecting the graphics background (GL or ES2). For this, we made the following changes:&lt;br /&gt;
- We added a command line option which lets the user enter the option &amp;lt;code&amp;gt;-E&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;--es2&amp;lt;/code&amp;gt; if the user wants to set ES2 as the graphic back end option. GL is set by default, hence if the user doesn't give any argument, Gl is selected as the graphic back end option. Example is as below&lt;br /&gt;
    ./mach run [url] -E&lt;br /&gt;
* Next, we had to add a flag in Rust-layers. This change was made in the file [https://github.com/prashantgupta24/rust-layers/blob/master/src/rendergl.rs Rust/src/rendergl.rs] in the &amp;lt;code&amp;gt;RenderContext::new&amp;lt;/code&amp;gt; function. For this, we did the following change:&lt;br /&gt;
- We defined an enum &amp;lt;code&amp;gt;GraphicOption&amp;lt;/code&amp;gt; which defined two options &amp;lt;code&amp;gt;GL&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ES2&amp;lt;/code&amp;gt; and then based on the boolean value from the servo &amp;lt;code&amp;gt;opts.rs&amp;lt;/code&amp;gt;, we set a variable with the respective enum value &amp;lt;code&amp;gt;GL&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;ES2&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Finally, we had to use the new command line option to pass the selected graphics back-end option to the Rust-layers context which we created in the previous step. For this we made changes to the [https://github.com/prashantgupta24/servo/blob/master/components/compositing/compositor.rs compositor.rs] in Compositing folder which is how Servo interacts with the Rust layers. The command line option is passed through the &amp;lt;code&amp;gt;initialize_compositing&amp;lt;/code&amp;gt; function.&lt;br /&gt;
&lt;br /&gt;
=='''Requirement Analysis'''==&lt;br /&gt;
&lt;br /&gt;
Earlier, only [https://en.wikipedia.org/wiki/OpenGL OpenGL] implementation was supported for Linux targets and we would be extending the [https://en.wikipedia.org/wiki/OpenGL_ES#2.0 ES2] implementation to support it for linux targets too. As a part of the final project, we propose to perform the following steps:&lt;br /&gt;
&lt;br /&gt;
* Change the platform implementation to provide a more generic way to dynamically select between GL and ES2. &lt;br /&gt;
* Remove the Linux/Android specific #cfg flags.&lt;br /&gt;
* Place a general #cfg flag for both Android and Linux to provide a more generic implementation of dynamic selection between GL and ES2&lt;br /&gt;
* Make changes to EGL platform to make it work on desktop GL&lt;br /&gt;
&lt;br /&gt;
=='''Files modified'''==&lt;br /&gt;
&lt;br /&gt;
Servo/components/utils/opts.rs: added the new command line option to allow selecting the graphics backend.&lt;br /&gt;
rust-layers/src/rendergl.rs: changed the RenderContext new function to allow the dynamic selection of graphics backend.&lt;br /&gt;
&lt;br /&gt;
=='''Files to be modified'''==&lt;br /&gt;
&lt;br /&gt;
rust-layers/src/platform/surface.rs: providing generic GL implementation that can dynamically select between the 2 interfaces.&lt;br /&gt;
&lt;br /&gt;
=='''Useful libraries'''==&lt;br /&gt;
&lt;br /&gt;
waffle-gl/waffle: A C library for selecting an OpenGL API and window system at runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Design Pattern'''==&lt;br /&gt;
We attempted to follow good OO practices by implementing the [https://en.wikipedia.org/wiki/Strategy_pattern Strategy design pattern] using Enum. &lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
After making our changes , the user can now dynamically pass in the option of GL or ES2 through the graphic command line option, and this option is passed on through the compositor to the rust layers during initialization. A video demonstration for the code changes is available [https://drive.google.com/file/d/0B9TVPg3YRoHqQUlvQXZkUUJPRzA/view?usp=sharing here]&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
1.    https://doc.rust-lang.org/stable/book/&amp;lt;br&amp;gt;&lt;br /&gt;
2.    https://en.wikipedia.org/wiki/Rust_(programming_language)&amp;lt;br&amp;gt;&lt;br /&gt;
3.    https://en.wikipedia.org/wiki/Servo_(layout_engine)&amp;lt;br&amp;gt;&lt;br /&gt;
4.    https://github.com/servo/servo/wiki/Refactor-GLES2-student-project&amp;lt;br&amp;gt;&lt;br /&gt;
5.    http://doc.crates.io/guide.html#overriding-dependencies&amp;lt;br&amp;gt;&lt;br /&gt;
6.    http://rustbyexample.com/&amp;lt;br&amp;gt;&lt;br /&gt;
7.    http://javarevisited.blogspot.com/2014/11/strategy-design-pattern-in-java-using-Enum-Example.html&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=99667</id>
		<title>CSC/ECE 517 Fall 2015/M1506-Refactor-GLES2-Implementation</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=99667"/>
		<updated>2015-11-13T22:07:39Z</updated>

		<summary type="html">&lt;p&gt;Asayal: /* Requirement Analysis */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''' Refactor GLES2 Student Project with SERVO &amp;amp; RUST ''''&lt;br /&gt;
&lt;br /&gt;
Servo is a prototype web browser engine written in the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript RUST]&amp;lt;/span&amp;gt; language.Servo uses a variety of back-end implementations for drawing graphics depending on the operating system.One of such back-end is only compatible with Android right now, and we want to extend and refactor that back-end to enable on all Linux systems..&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
===Servo===&lt;br /&gt;
[https://en.wikipedia.org/wiki/Servo_(layout_engine) Servo]Servo is an open source prototype web browser layout engine being developed by Mozilla, and it is written in [https://www.rust-lang.org/ Rust] language. The main idea is to create a highly parallel environment, in which different components can be handled by fine grained, isolated tasks. The different components can be rendering, HTML parsing, etc. &lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://doc.rust-lang.org/book/README.html Rust] is an open source systems programming language developed by Mozilla. Servo is written in Rust. The main purpose behind it's design is to be thread safe and concurrent. The emphasis is also on speed, safety and control of memory layout.&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
* The project requirement initially stated that we build and Compile servo. Following are the steps for this:&lt;br /&gt;
Servo is built with [https://mail.mozilla.org/pipermail/rust-dev/2014-March/009090.html Cargo], the Rust package manager. Mozilla's Mach tools are used to orchestrate the build and other tasks.&lt;br /&gt;
&lt;br /&gt;
    git clone https://github.com/servo/servo&lt;br /&gt;
    cd servo&lt;br /&gt;
    ./mach build --dev&lt;br /&gt;
    ./mach run tests/html/about-mozilla.html&lt;br /&gt;
&lt;br /&gt;
* The next requirement was to build the Rust-layers independently of Servo. For this, we &lt;br /&gt;
* Next, we had to over-ride cargo to use our local copy of Rust-layers, so we had to add a cargo override to it. For this, we created a &amp;lt;code&amp;gt;.cargo&amp;lt;/code&amp;gt; folder in our home directory(same place that servo and Rust-layers reside), and added a &amp;lt;code&amp;gt;config&amp;lt;/code&amp;gt; file to that folder. The content of that config file is a path to our local Rust-layers.&lt;br /&gt;
    paths = [path/to/rust_layers]&lt;br /&gt;
* Next, we had to add a new command line argument in Servo, which would allow selecting the graphics background (GL or ES2). For this, we made the following changes:&lt;br /&gt;
- We added a command line option which lets the user enter the option &amp;lt;code&amp;gt;-E&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;--es2&amp;lt;/code&amp;gt; if the user wants to set ES2 as the graphic back end option. GL is set by default, hence if the user doesn't give any argument, Gl is selected as the graphic back end option. Example is as below&lt;br /&gt;
    ./mach run [url] -E&lt;br /&gt;
* Next, we had to add a flag in Rust-layers. This change was made in the file [https://github.com/prashantgupta24/rust-layers/blob/master/src/rendergl.rs Rust/src/rendergl.rs] in the &amp;lt;code&amp;gt;RenderContext::new&amp;lt;/code&amp;gt; function. For this, we did the following change:&lt;br /&gt;
- We defined an enum &amp;lt;code&amp;gt;GraphicOption&amp;lt;/code&amp;gt; which defined two options &amp;lt;code&amp;gt;GL&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ES2&amp;lt;/code&amp;gt; and then based on the boolean value from the servo &amp;lt;code&amp;gt;opts.rs&amp;lt;/code&amp;gt;, we set a variable with the respective enum value &amp;lt;code&amp;gt;GL&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;ES2&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Finally, we had to use the new command line option to pass the selected graphics back-end option to the Rust-layers context which we created in the previous step. For this we made changes to the [https://github.com/prashantgupta24/servo/blob/master/components/compositing/compositor.rs compositor.rs] in Compositing folder which is how Servo interacts with the Rust layers. The command line option is passed through the &amp;lt;code&amp;gt;initialize_compositing&amp;lt;/code&amp;gt; function.&lt;br /&gt;
&lt;br /&gt;
=='''Requirement Analysis'''==&lt;br /&gt;
&lt;br /&gt;
Earlier, only [https://en.wikipedia.org/wiki/OpenGL OpenGL] implementation was supported for Linux targets and we would be extending the [https://en.wikipedia.org/wiki/OpenGL_ES#2.0 ES2] implementation to support it for linux targets too. As a part of the final project, we propose to perform the following steps:&lt;br /&gt;
&lt;br /&gt;
* Change the platform implementation to provide a more generic way to dynamically select between GL and ES2. &lt;br /&gt;
* Remove the Linux/Android specific #cfg flags.&lt;br /&gt;
* Place a general #cfg flag for both Android and Linux to provide a more generic implementation of dynamic selection between GL and ES2&lt;br /&gt;
* Make changes to EGL platform to make it work on desktop GL&lt;br /&gt;
&lt;br /&gt;
=='''Design Pattern'''==&lt;br /&gt;
We attempted to follow good OO practices by implementing the [https://en.wikipedia.org/wiki/Strategy_pattern Strategy design pattern] using Enum. &lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
After making our changes , the user can now dynamically pass in the option of GL or ES2 through the graphic command line option, and this option is passed on through the compositor to the rust layers during initialization. A video demonstration for the code changes is available [https://drive.google.com/file/d/0B9TVPg3YRoHqQUlvQXZkUUJPRzA/view?usp=sharing here]&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
1.    https://doc.rust-lang.org/stable/book/&amp;lt;br&amp;gt;&lt;br /&gt;
2.    https://en.wikipedia.org/wiki/Rust_(programming_language)&amp;lt;br&amp;gt;&lt;br /&gt;
3.    https://en.wikipedia.org/wiki/Servo_(layout_engine)&amp;lt;br&amp;gt;&lt;br /&gt;
4.    https://github.com/servo/servo/wiki/Refactor-GLES2-student-project&amp;lt;br&amp;gt;&lt;br /&gt;
5.    http://doc.crates.io/guide.html#overriding-dependencies&amp;lt;br&amp;gt;&lt;br /&gt;
6.    http://rustbyexample.com/&amp;lt;br&amp;gt;&lt;br /&gt;
7.    http://javarevisited.blogspot.com/2014/11/strategy-design-pattern-in-java-using-Enum-Example.html&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=99666</id>
		<title>CSC/ECE 517 Fall 2015/M1506-Refactor-GLES2-Implementation</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=99666"/>
		<updated>2015-11-13T22:07:07Z</updated>

		<summary type="html">&lt;p&gt;Asayal: /* Requirement Analysis */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''' Refactor GLES2 Student Project with SERVO &amp;amp; RUST ''''&lt;br /&gt;
&lt;br /&gt;
Servo is a prototype web browser engine written in the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript RUST]&amp;lt;/span&amp;gt; language.Servo uses a variety of back-end implementations for drawing graphics depending on the operating system.One of such back-end is only compatible with Android right now, and we want to extend and refactor that back-end to enable on all Linux systems..&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
===Servo===&lt;br /&gt;
[https://en.wikipedia.org/wiki/Servo_(layout_engine) Servo]Servo is an open source prototype web browser layout engine being developed by Mozilla, and it is written in [https://www.rust-lang.org/ Rust] language. The main idea is to create a highly parallel environment, in which different components can be handled by fine grained, isolated tasks. The different components can be rendering, HTML parsing, etc. &lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://doc.rust-lang.org/book/README.html Rust] is an open source systems programming language developed by Mozilla. Servo is written in Rust. The main purpose behind it's design is to be thread safe and concurrent. The emphasis is also on speed, safety and control of memory layout.&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
* The project requirement initially stated that we build and Compile servo. Following are the steps for this:&lt;br /&gt;
Servo is built with [https://mail.mozilla.org/pipermail/rust-dev/2014-March/009090.html Cargo], the Rust package manager. Mozilla's Mach tools are used to orchestrate the build and other tasks.&lt;br /&gt;
&lt;br /&gt;
    git clone https://github.com/servo/servo&lt;br /&gt;
    cd servo&lt;br /&gt;
    ./mach build --dev&lt;br /&gt;
    ./mach run tests/html/about-mozilla.html&lt;br /&gt;
&lt;br /&gt;
* The next requirement was to build the Rust-layers independently of Servo. For this, we &lt;br /&gt;
* Next, we had to over-ride cargo to use our local copy of Rust-layers, so we had to add a cargo override to it. For this, we created a &amp;lt;code&amp;gt;.cargo&amp;lt;/code&amp;gt; folder in our home directory(same place that servo and Rust-layers reside), and added a &amp;lt;code&amp;gt;config&amp;lt;/code&amp;gt; file to that folder. The content of that config file is a path to our local Rust-layers.&lt;br /&gt;
    paths = [path/to/rust_layers]&lt;br /&gt;
* Next, we had to add a new command line argument in Servo, which would allow selecting the graphics background (GL or ES2). For this, we made the following changes:&lt;br /&gt;
- We added a command line option which lets the user enter the option &amp;lt;code&amp;gt;-E&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;--es2&amp;lt;/code&amp;gt; if the user wants to set ES2 as the graphic back end option. GL is set by default, hence if the user doesn't give any argument, Gl is selected as the graphic back end option. Example is as below&lt;br /&gt;
    ./mach run [url] -E&lt;br /&gt;
* Next, we had to add a flag in Rust-layers. This change was made in the file [https://github.com/prashantgupta24/rust-layers/blob/master/src/rendergl.rs Rust/src/rendergl.rs] in the &amp;lt;code&amp;gt;RenderContext::new&amp;lt;/code&amp;gt; function. For this, we did the following change:&lt;br /&gt;
- We defined an enum &amp;lt;code&amp;gt;GraphicOption&amp;lt;/code&amp;gt; which defined two options &amp;lt;code&amp;gt;GL&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ES2&amp;lt;/code&amp;gt; and then based on the boolean value from the servo &amp;lt;code&amp;gt;opts.rs&amp;lt;/code&amp;gt;, we set a variable with the respective enum value &amp;lt;code&amp;gt;GL&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;ES2&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Finally, we had to use the new command line option to pass the selected graphics back-end option to the Rust-layers context which we created in the previous step. For this we made changes to the [https://github.com/prashantgupta24/servo/blob/master/components/compositing/compositor.rs compositor.rs] in Compositing folder which is how Servo interacts with the Rust layers. The command line option is passed through the &amp;lt;code&amp;gt;initialize_compositing&amp;lt;/code&amp;gt; function.&lt;br /&gt;
&lt;br /&gt;
=='''Requirement Analysis'''==&lt;br /&gt;
&lt;br /&gt;
Earlier, only [https://en.wikipedia.org/wiki/OpenGL OpenGL] implementation was supported for Linux targets and we would be extending the ES2 implementation to support it for linux targets too. As a part of the final project, we propose to perform the following steps:&lt;br /&gt;
&lt;br /&gt;
* Change the platform implementation to provide a more generic way to dynamically select between GL and ES2. &lt;br /&gt;
* Remove the Linux/Android specific #cfg flags.&lt;br /&gt;
* Place a general #cfg flag for both Android and Linux to provide a more generic implementation of dynamic selection between GL and ES2&lt;br /&gt;
* Make changes to EGL platform to make it work on desktop GL&lt;br /&gt;
&lt;br /&gt;
=='''Design Pattern'''==&lt;br /&gt;
We attempted to follow good OO practices by implementing the [https://en.wikipedia.org/wiki/Strategy_pattern Strategy design pattern] using Enum. &lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
After making our changes , the user can now dynamically pass in the option of GL or ES2 through the graphic command line option, and this option is passed on through the compositor to the rust layers during initialization. A video demonstration for the code changes is available [https://drive.google.com/file/d/0B9TVPg3YRoHqQUlvQXZkUUJPRzA/view?usp=sharing here]&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
1.    https://doc.rust-lang.org/stable/book/&amp;lt;br&amp;gt;&lt;br /&gt;
2.    https://en.wikipedia.org/wiki/Rust_(programming_language)&amp;lt;br&amp;gt;&lt;br /&gt;
3.    https://en.wikipedia.org/wiki/Servo_(layout_engine)&amp;lt;br&amp;gt;&lt;br /&gt;
4.    https://github.com/servo/servo/wiki/Refactor-GLES2-student-project&amp;lt;br&amp;gt;&lt;br /&gt;
5.    http://doc.crates.io/guide.html#overriding-dependencies&amp;lt;br&amp;gt;&lt;br /&gt;
6.    http://rustbyexample.com/&amp;lt;br&amp;gt;&lt;br /&gt;
7.    http://javarevisited.blogspot.com/2014/11/strategy-design-pattern-in-java-using-Enum-Example.html&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=99665</id>
		<title>CSC/ECE 517 Fall 2015/M1506-Refactor-GLES2-Implementation</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=99665"/>
		<updated>2015-11-13T22:03:56Z</updated>

		<summary type="html">&lt;p&gt;Asayal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''' Refactor GLES2 Student Project with SERVO &amp;amp; RUST ''''&lt;br /&gt;
&lt;br /&gt;
Servo is a prototype web browser engine written in the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript RUST]&amp;lt;/span&amp;gt; language.Servo uses a variety of back-end implementations for drawing graphics depending on the operating system.One of such back-end is only compatible with Android right now, and we want to extend and refactor that back-end to enable on all Linux systems..&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
===Servo===&lt;br /&gt;
[https://en.wikipedia.org/wiki/Servo_(layout_engine) Servo]Servo is an open source prototype web browser layout engine being developed by Mozilla, and it is written in [https://www.rust-lang.org/ Rust] language. The main idea is to create a highly parallel environment, in which different components can be handled by fine grained, isolated tasks. The different components can be rendering, HTML parsing, etc. &lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://doc.rust-lang.org/book/README.html Rust] is an open source systems programming language developed by Mozilla. Servo is written in Rust. The main purpose behind it's design is to be thread safe and concurrent. The emphasis is also on speed, safety and control of memory layout.&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
* The project requirement initially stated that we build and Compile servo. Following are the steps for this:&lt;br /&gt;
Servo is built with [https://mail.mozilla.org/pipermail/rust-dev/2014-March/009090.html Cargo], the Rust package manager. Mozilla's Mach tools are used to orchestrate the build and other tasks.&lt;br /&gt;
&lt;br /&gt;
    git clone https://github.com/servo/servo&lt;br /&gt;
    cd servo&lt;br /&gt;
    ./mach build --dev&lt;br /&gt;
    ./mach run tests/html/about-mozilla.html&lt;br /&gt;
&lt;br /&gt;
* The next requirement was to build the Rust-layers independently of Servo. For this, we &lt;br /&gt;
* Next, we had to over-ride cargo to use our local copy of Rust-layers, so we had to add a cargo override to it. For this, we created a &amp;lt;code&amp;gt;.cargo&amp;lt;/code&amp;gt; folder in our home directory(same place that servo and Rust-layers reside), and added a &amp;lt;code&amp;gt;config&amp;lt;/code&amp;gt; file to that folder. The content of that config file is a path to our local Rust-layers.&lt;br /&gt;
    paths = [path/to/rust_layers]&lt;br /&gt;
* Next, we had to add a new command line argument in Servo, which would allow selecting the graphics background (GL or ES2). For this, we made the following changes:&lt;br /&gt;
- We added a command line option which lets the user enter the option &amp;lt;code&amp;gt;-E&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;--es2&amp;lt;/code&amp;gt; if the user wants to set ES2 as the graphic back end option. GL is set by default, hence if the user doesn't give any argument, Gl is selected as the graphic back end option. Example is as below&lt;br /&gt;
    ./mach run [url] -E&lt;br /&gt;
* Next, we had to add a flag in Rust-layers. This change was made in the file [https://github.com/prashantgupta24/rust-layers/blob/master/src/rendergl.rs Rust/src/rendergl.rs] in the &amp;lt;code&amp;gt;RenderContext::new&amp;lt;/code&amp;gt; function. For this, we did the following change:&lt;br /&gt;
- We defined an enum &amp;lt;code&amp;gt;GraphicOption&amp;lt;/code&amp;gt; which defined two options &amp;lt;code&amp;gt;GL&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ES2&amp;lt;/code&amp;gt; and then based on the boolean value from the servo &amp;lt;code&amp;gt;opts.rs&amp;lt;/code&amp;gt;, we set a variable with the respective enum value &amp;lt;code&amp;gt;GL&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;ES2&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Finally, we had to use the new command line option to pass the selected graphics back-end option to the Rust-layers context which we created in the previous step. For this we made changes to the [https://github.com/prashantgupta24/servo/blob/master/components/compositing/compositor.rs compositor.rs] in Compositing folder which is how Servo interacts with the Rust layers. The command line option is passed through the &amp;lt;code&amp;gt;initialize_compositing&amp;lt;/code&amp;gt; function.&lt;br /&gt;
&lt;br /&gt;
=='''Requirement Analysis'''==&lt;br /&gt;
&lt;br /&gt;
Earlier, only OpenGL implementation was supported for Linux targets and we would be extending the ES2 implementation to support it for linux targets too. As a part of the final project, we propose to perform the following steps:&lt;br /&gt;
&lt;br /&gt;
* Change the platform implementation to provide a more generic way to dynamically select between GL and ES2. &lt;br /&gt;
* Remove the Linux/Android specific #cfg flags.&lt;br /&gt;
* Place a general #cfg flag for both Android and Linux to provide a more generic implementation of dynamic selection between GL and ES2&lt;br /&gt;
* Make changes to EGL platform to make it work on desktop GL&lt;br /&gt;
&lt;br /&gt;
=='''Design Pattern'''==&lt;br /&gt;
We attempted to follow good OO practices by implementing the [https://en.wikipedia.org/wiki/Strategy_pattern Strategy design pattern] using Enum. &lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
After making our changes , the user can now dynamically pass in the option of GL or ES2 through the graphic command line option, and this option is passed on through the compositor to the rust layers during initialization. A video demonstration for the code changes is available [https://drive.google.com/file/d/0B9TVPg3YRoHqQUlvQXZkUUJPRzA/view?usp=sharing here]&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
1.    https://doc.rust-lang.org/stable/book/&amp;lt;br&amp;gt;&lt;br /&gt;
2.    https://en.wikipedia.org/wiki/Rust_(programming_language)&amp;lt;br&amp;gt;&lt;br /&gt;
3.    https://en.wikipedia.org/wiki/Servo_(layout_engine)&amp;lt;br&amp;gt;&lt;br /&gt;
4.    https://github.com/servo/servo/wiki/Refactor-GLES2-student-project&amp;lt;br&amp;gt;&lt;br /&gt;
5.    http://doc.crates.io/guide.html#overriding-dependencies&amp;lt;br&amp;gt;&lt;br /&gt;
6.    http://rustbyexample.com/&amp;lt;br&amp;gt;&lt;br /&gt;
7.    http://javarevisited.blogspot.com/2014/11/strategy-design-pattern-in-java-using-Enum-Example.html&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=99619</id>
		<title>CSC/ECE 517 Fall 2015/M1506-Refactor-GLES2-Implementation</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/M1506-Refactor-GLES2-Implementation&amp;diff=99619"/>
		<updated>2015-11-13T21:23:15Z</updated>

		<summary type="html">&lt;p&gt;Asayal: Created page with &amp;quot;'''' Refactor GLES2 Student Project with SERVO &amp;amp; RUST ''''  Servo is a prototype web browser engine written in the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScri...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''' Refactor GLES2 Student Project with SERVO &amp;amp; RUST ''''&lt;br /&gt;
&lt;br /&gt;
Servo is a prototype web browser engine written in the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript RUST]&amp;lt;/span&amp;gt; language.Servo uses a variety of back-end implementations for drawing graphics depending on the operating system.One of such back-end is only compatible with Android right now, and we want to extend and refactor that back-end to enable on all Linux systems..&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
===Servo===&lt;br /&gt;
[https://en.wikipedia.org/wiki/Servo_(layout_engine) Servo]Servo is an open source prototype web browser layout engine being developed by Mozilla, and it is written in [https://www.rust-lang.org/ Rust] language. The main idea is to create a highly parallel environment, in which different components can be handled by fine grained, isolated tasks. The different components can be rendering, HTML parsing, etc. &lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://doc.rust-lang.org/book/README.html Rust] is an open source systems programming language developed by Mozilla. Servo is written in Rust. The main purpose behind it's design is to be thread safe and concurrent. The emphasis is also on speed, safety and control of memory layout.&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
* The project requirement initially stated that we build and Compile servo. Following are the steps for this:&lt;br /&gt;
Servo is built with [https://mail.mozilla.org/pipermail/rust-dev/2014-March/009090.html Cargo], the Rust package manager. Mozilla's Mach tools are used to orchestrate the build and other tasks.&lt;br /&gt;
&lt;br /&gt;
    git clone https://github.com/servo/servo&lt;br /&gt;
    cd servo&lt;br /&gt;
    ./mach build --dev&lt;br /&gt;
    ./mach run tests/html/about-mozilla.html&lt;br /&gt;
&lt;br /&gt;
* The next requirement was to build the Rust-layers independently of Servo. For this, we &lt;br /&gt;
* Next, we had to over-ride cargo to use our local copy of Rust-layers, so we had to add a cargo override to it. For this, we created a &amp;lt;code&amp;gt;.cargo&amp;lt;/code&amp;gt; folder in our home directory(same place that servo and Rust-layers reside), and added a &amp;lt;code&amp;gt;config&amp;lt;/code&amp;gt; file to that folder. The content of that config file is a path to our local Rust-layers.&lt;br /&gt;
    paths = [path/to/rust_layers]&lt;br /&gt;
* Next, we had to add a new command line argument in Servo, which would allow selecting the graphics background (GL or ES2). For this, we made the following changes:&lt;br /&gt;
- We added a command line option which lets the user enter the option &amp;lt;code&amp;gt;-E&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;--es2&amp;lt;/code&amp;gt; if the user wants to set ES2 as the graphic back end option. GL is set by default, hence if the user doesn't give any argument, Gl is selected as the graphic back end option. Example is as below&lt;br /&gt;
    ./mach run [url] -E&lt;br /&gt;
* Next, we had to add a flag in Rust-layers. This change was made in the file [https://github.com/prashantgupta24/rust-layers/blob/master/src/rendergl.rs Rust/src/rendergl.rs] in the &amp;lt;code&amp;gt;RenderContext::new&amp;lt;/code&amp;gt; function. For this, we did the following change:&lt;br /&gt;
- We defined an enum &amp;lt;code&amp;gt;GraphicOption&amp;lt;/code&amp;gt; which defined two options &amp;lt;code&amp;gt;GL&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ES2&amp;lt;/code&amp;gt; and then based on the boolean value from the servo &amp;lt;code&amp;gt;opts.rs&amp;lt;/code&amp;gt;, we set a variable with the respective enum value &amp;lt;code&amp;gt;GL&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;ES2&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Finally, we had to use the new command line option to pass the selected graphics back-end option to the Rust-layers context which we created in the previous step. For this we made changes to the [https://github.com/prashantgupta24/servo/blob/master/components/compositing/compositor.rs compositor.rs] in Compositing folder which is how Servo interacts with the Rust layers. The command line option is passed through the &amp;lt;code&amp;gt;initialize_compositing&amp;lt;/code&amp;gt; function.&lt;br /&gt;
&lt;br /&gt;
=='''Design Pattern'''==&lt;br /&gt;
We attempted to follow good OO practices by implementing the [https://en.wikipedia.org/wiki/Strategy_pattern Strategy design pattern] using Enum. &lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
After making our changes , the user can now dynamically pass in the option of GL or ES2 through the graphic command line option, and this option is passed on through the compositor to the rust layers during initialization. A video demonstration for the code changes is available [https://drive.google.com/file/d/0B9TVPg3YRoHqQUlvQXZkUUJPRzA/view?usp=sharing here]&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
1.    https://doc.rust-lang.org/stable/book/&amp;lt;br&amp;gt;&lt;br /&gt;
2.    https://en.wikipedia.org/wiki/Rust_(programming_language)&amp;lt;br&amp;gt;&lt;br /&gt;
3.    https://en.wikipedia.org/wiki/Servo_(layout_engine)&amp;lt;br&amp;gt;&lt;br /&gt;
4.    https://github.com/servo/servo/wiki/Refactor-GLES2-student-project&amp;lt;br&amp;gt;&lt;br /&gt;
5.    http://doc.crates.io/guide.html#overriding-dependencies&amp;lt;br&amp;gt;&lt;br /&gt;
6.    http://rustbyexample.com/&amp;lt;br&amp;gt;&lt;br /&gt;
7.    http://javarevisited.blogspot.com/2014/11/strategy-design-pattern-in-java-using-Enum-Example.html&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1553_AAJ&amp;diff=97517</id>
		<title>CSC/ECE 517 Fall 2015/oss E1553 AAJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1553_AAJ&amp;diff=97517"/>
		<updated>2015-10-31T16:12:47Z</updated>

		<summary type="html">&lt;p&gt;Asayal: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1553. Refactoring the Versions Controller==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Introduction to Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
The following tasks were accomplished in this project:&lt;br /&gt;
&lt;br /&gt;
* Improved the clarity of code by improving the variable and parameter names.&lt;br /&gt;
* Long character strings were taken and given appropriate names.&lt;br /&gt;
* Handled pagination by a separate helper module, which can be used by multiple controllers.&lt;br /&gt;
* Implemented action_allowed for access_control  to prevent unauthorized access of methods.&lt;br /&gt;
* Prevented displaying of all versions for all users and tables when a user views the index page.&lt;br /&gt;
* Added missing CRUD methods to Versions Controller&lt;br /&gt;
* Added RSPEC testcases for testing changes done in Versions Controller&lt;br /&gt;
&lt;br /&gt;
===About Versions Controller===&lt;br /&gt;
This class manages different versions of reviews.  If a reviewer reviews a submission, and after that, the author revises the submission, the next time the reviewer does a review (s)he will create a new version.  Sometimes it’s necessary to find the current version of a review; sometimes it’s necessary to find all versions.  Similarly, a user may want to delete the current version of a review, or all versions of a review.&lt;br /&gt;
Pagination of versions helps the user to view a subset of versions at a time. Considering the huge number of versions in the system, it is very useful to have a pagination mechanism and a filtering mechanism which can be applied on the whole set of versions. The idea is to display the versions in an ordered, comprehensible and logical manner. In Expertiza the gem ‘will_paginate’ is used to achieve pagination.&lt;br /&gt;
&lt;br /&gt;
===Current Implementation===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=====Functionality=====&lt;br /&gt;
* Any user irrespective of his/ her privileges can view all the versions.&lt;br /&gt;
::The versions which a particular user can view should be restricted based on the privileges of the user. For instance, only a user with Administrator privileges should be able to view all the versions in the system. However, that is not the case now. Every user can view all the versions irrespective of whether the user is a student or an administrator.&lt;br /&gt;
* Any user can delete any version&lt;br /&gt;
::The versions which a particular user can delete should be restricted based on the privileges of the user. For instance, a student should not be allowed to delete any version. According to the current implementation any user can delete any version in the system.&lt;br /&gt;
* Filtering of versions were restricted to the current user&lt;br /&gt;
::The filtering options on versions were restricted to the current user. Sometimes a user might want to view versions associated with other users. For instance, an instructor might want to view the list of versions created by a particular student. This is not possible with the current implementation.&lt;br /&gt;
&lt;br /&gt;
=====Drawbacks and Solutions=====&lt;br /&gt;
* '''Problem 1''': The method paginate_list is doing more than one thing.&lt;br /&gt;
::The method paginate_list was building a complex search criteria based on the input params, getting the list of versions from the Database matching this search criteria and then calling the Page API. All these tasks in a single method made it difficult to understand.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# For filtering the versions list with proper search and pagination.&lt;br /&gt;
  def paginate_list(id, user_id, item_type, event, datetime)&lt;br /&gt;
    # Set up the search criteria&lt;br /&gt;
    criteria = ''&lt;br /&gt;
    criteria = criteria + &amp;quot;id = #{id} AND &amp;quot; if id &amp;amp;&amp;amp; id.to_i &amp;gt; 0&lt;br /&gt;
    if current_user_role? == 'Super-Administrator'&lt;br /&gt;
      criteria = criteria + &amp;quot;whodunnit = #{user_id} AND &amp;quot; if user_id &amp;amp;&amp;amp; user_id.to_i &amp;gt; 0&lt;br /&gt;
    end&lt;br /&gt;
    criteria = criteria + &amp;quot;whodunnit = #{current_user.try(:id)} AND &amp;quot; if current_user.try(:id) &amp;amp;&amp;amp; current_user.try(:id).to_i &amp;gt; 0&lt;br /&gt;
    criteria = criteria + &amp;quot;item_type = '#{item_type}' AND &amp;quot; if item_type &amp;amp;&amp;amp; !(item_type.eql? 'Any')&lt;br /&gt;
    criteria = criteria + &amp;quot;event = '#{event}' AND &amp;quot; if event &amp;amp;&amp;amp; !(event.eql? 'Any')&lt;br /&gt;
    criteria = criteria + &amp;quot;created_at &amp;gt;= '#{time_to_string(params[:start_time])}' AND &amp;quot;&lt;br /&gt;
    criteria = criteria + &amp;quot;created_at &amp;lt;= '#{time_to_string(params[:end_time])}' AND &amp;quot;&lt;br /&gt;
&lt;br /&gt;
    if current_role == 'Instructor' || current_role == 'Administrator'&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # Remove the last ' AND '&lt;br /&gt;
    criteria = criteria[0..-5]&lt;br /&gt;
&lt;br /&gt;
    versions = Version.page(params[:page]).order('id').per_page(25).where(criteria)&lt;br /&gt;
    versions&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* '''Solution''': The implementation has been changed in such a way that the versions which a user is allowed to see depends on the privileges of the user. The approach we have taken is as follows:&lt;br /&gt;
**An administrator can see all the versions&lt;br /&gt;
**An instructor can see all the versions created by him and other users who are in his course or are participants in the assignments he creates.&lt;br /&gt;
**A TA can see all the versions created by him and other users who are in the course for which he/ she assists.&lt;br /&gt;
**A Student can see all the versions created by him/ her.&lt;br /&gt;
* '''Problem 2''': The search criteria created in the method paginate_list was difficult to comprehend.&lt;br /&gt;
::The code which builds the search criteria in the method paginate_list uses many string literals and conditions and is hardly intuitive. The programmer will have to spend some time to understand what the code is really doing.&lt;br /&gt;
* '''Solution''': The implementation has been changed. A student is not allowed to delete any versions now. Other types of users, for instance administrators, instructors and TAs are allowed to delete only the versions they are authorized to view.&lt;br /&gt;
* '''Problem 3''': The paginate method can be moved to a helper class.&lt;br /&gt;
::VersionsController is not the only component which require to paginate items. There are other components too. For instance, the UsersController has to paginate the list of users. Hence the Paginate method can be moved to a helper class which can be accessed by other components as well.&lt;br /&gt;
* '''Solution''': The filtering options has also been enhanced. The current user can now choose as part of the version search filter any user from a list of users if the current user is authorized to see the versions created by that user.&lt;br /&gt;
&lt;br /&gt;
===New Implementation===&lt;br /&gt;
*The method paginate_list has been split into 2 methods now. &lt;br /&gt;
** BuildSearchCriteria – as the name suggests the sole purpose of this method is to build a search criteria based on the input search filters when the current user initiates a search in versions.&lt;br /&gt;
** paginate_list – this method will call the paginate API.&lt;br /&gt;
:First the search criteria is built, then the criteria is applied to versions in the database to get all versions which matches the criteria and then the retrieved versions are paginated.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # pagination.&lt;br /&gt;
  def paginate_list(versions)&lt;br /&gt;
    paginate(versions, VERSIONS_PER_PAGE);&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def BuildSearchCriteria(id, user_id, item_type, event)&lt;br /&gt;
    # Set up the search criteria&lt;br /&gt;
    search_criteria = ''&lt;br /&gt;
    search_criteria = search_criteria + add_id_filter_if_valid(id).to_s&lt;br /&gt;
    if current_user_role? == 'Super-Administrator'&lt;br /&gt;
      search_criteria = search_criteria + add_user_filter_for_super_admin(user_id).to_s&lt;br /&gt;
    end&lt;br /&gt;
    search_criteria = search_criteria + add_user_filter&lt;br /&gt;
    search_criteria = search_criteria + add_version_type_filter(item_type).to_s&lt;br /&gt;
    search_criteria = search_criteria + add_event_filter(event).to_s&lt;br /&gt;
    search_criteria = search_criteria + add_date_time_filter&lt;br /&gt;
    search_criteria&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The string literals and conditions in the method paginate_list were replaced with methods with intuitive names so that the programmer can understand the code more easily. We also removed an empty if clause and a redundant statement.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def add_id_filter_if_valid (id)&lt;br /&gt;
    &amp;quot;id = #{id} AND &amp;quot; if id &amp;amp;&amp;amp; id.to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_user_filter_for_super_admin (user_id)&lt;br /&gt;
    &amp;quot;whodunnit = #{user_id} AND &amp;quot; if user_id &amp;amp;&amp;amp; user_id.to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_user_filter&lt;br /&gt;
    &amp;quot;whodunnit = #{current_user.try(:id)} AND &amp;quot; if current_user.try(:id) &amp;amp;&amp;amp; current_user.try(:id).to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_event_filter (event)&lt;br /&gt;
    &amp;quot;event = '#{event}' AND &amp;quot; if event &amp;amp;&amp;amp; !(event.eql? 'Any')&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_date_time_filter&lt;br /&gt;
    &amp;quot;created_at &amp;gt;= '#{time_to_string(params[:start_time])}' AND &amp;quot; +&lt;br /&gt;
        &amp;quot;created_at &amp;lt;= '#{time_to_string(params[:end_time])}'&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_version_type_filter (version_type)&lt;br /&gt;
    &amp;quot;item_type = '#{version_type}' AND &amp;quot; if version_type &amp;amp;&amp;amp; !(version_type.eql? 'Any')&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The paginate method has been moved to the helper class Pagination_Helper. This new method can be now reused by the different components like UsersController etc. The method receives two parameters, first the list to paginate and second the number of items to be displayed in a page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module PaginationHelper&lt;br /&gt;
&lt;br /&gt;
  def paginate (items, number_of_items_per_page)&lt;br /&gt;
    items.page(params[:page]).per_page(number_of_items_per_page)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code improvements===&lt;br /&gt;
* Introduced a constant VERSIONS_PER_PAGE and assigned the value 25 to it. The pagination algorithm for VersionsController displays at most 25 versions in a page. The existing implementation uses the value 25 straight in the code and there are few problems associated with such an approach.&lt;br /&gt;
** It is not easy to understand what 25 is unless the programmer takes a close look at the code.&lt;br /&gt;
** In case if the value 25 is used at more than one places and in future a new requirement comes to show at most 30 versions in a page, all the values will have to be modified. It is not very DRY.&lt;br /&gt;
* The VersionsController was overriding AccessHelper - action_allowed? method to return true in all the cases. This was violating the whole purpose of the method action_allowed?. The purpose of this method is to determine whether the user who is triggering a CRUD operation is allowed to do so. So when the current user invokes a CRUD operation, the action_allowed? method is invoked first and if the method returns true the CRUD operation is triggered or else the user is intimated with a message and gracefully exited. Hence, when the action_allowed? method is overridden to return true always, it results in providing unauthorized access to certain users.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def action_allowed?&lt;br /&gt;
    true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:With the new implementation the AccessHelper - action_allowed? method has been modified in such a way that unauthorized access is prevented. As per the new algorithm, 'new', 'create', 'edit', 'update' cannot be invoked by any user. These operations can be accessed only by ‘papertrail’ gem. Only an ‘Administrator’ or ‘Super-Administrator’ can call 'destroy_all' method. All the other methods are accessible to ‘Administrator’,  ‘Super-Administrator’, ‘Instructor’, ‘Teaching Assistant’ and ‘Student’.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    case params[:action]&lt;br /&gt;
    when 'new', 'create', 'edit', 'update'&lt;br /&gt;
    #Modifications can only be done by papertrail&lt;br /&gt;
      return false&lt;br /&gt;
    when 'destroy_all'&lt;br /&gt;
      ['Super-Administrator',&lt;br /&gt;
       'Administrator'].include? current_role_name&lt;br /&gt;
    else&lt;br /&gt;
      #Allow all others&lt;br /&gt;
      ['Super-Administrator',&lt;br /&gt;
       'Administrator',&lt;br /&gt;
       'Instructor',&lt;br /&gt;
       'Teaching Assistant',&lt;br /&gt;
       'Student'].include? current_role_name&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Automated Testing using RSPEC===&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/WintersLt/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[http://bit.ly/myexpertiza  Demo link] &lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;br /&gt;
#[https://relishapp.com/rspec Rspec Documentation]&lt;br /&gt;
#Clean Code: A handbook of agile software craftsmanship. Author: Robert C Martin&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1553_AAJ&amp;diff=97456</id>
		<title>CSC/ECE 517 Fall 2015/oss E1553 AAJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1553_AAJ&amp;diff=97456"/>
		<updated>2015-10-31T04:55:37Z</updated>

		<summary type="html">&lt;p&gt;Asayal: /* Introduction to Expertiza */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1553. Refactoring the Versions Controller==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Introduction to Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
The following tasks were accomplished in this project:&lt;br /&gt;
&lt;br /&gt;
* Improved the clarity of code by improving the variable and parameter names.&lt;br /&gt;
* Long character strings were taken and given appropriate names.&lt;br /&gt;
* Handled pagination by a separate helper module, which can be used by multiple controllers.&lt;br /&gt;
* Implemented action_allowed for access_control  to prevent unauthorized access of methods.&lt;br /&gt;
* Prevented displaying of all versions for all users and tables when a user views the index page.&lt;br /&gt;
* Added missing CRUD methods to Versions Controller&lt;br /&gt;
* Added RSPEC testcases for testing changes done in Versions Controller&lt;br /&gt;
&lt;br /&gt;
===About Versions Controller===&lt;br /&gt;
This class manages different versions of reviews.  If a reviewer reviews a submission, and after that, the author revises the submission, the next time the reviewer does a review (s)he will create a new version.  Sometimes it’s necessary to find the current version of a review; sometimes it’s necessary to find all versions.  Similarly, a user may want to delete the current version of a review, or all versions of a review.&lt;br /&gt;
Pagination of versions helps the user to view a subset of versions at a time. Considering the huge number of versions in the system, it is very useful to have a pagination mechanism and a filtering mechanism which can be applied on the whole set of versions. The idea is to display the versions in an ordered, comprehensible and logical manner. In Expertiza the gem ‘will_paginate’ is used to achieve pagination.&lt;br /&gt;
&lt;br /&gt;
===Current Implementation===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=====Functionality=====&lt;br /&gt;
* Any user irrespective of his/ her privileges can view all the versions.&lt;br /&gt;
::The versions which a particular user can view should be restricted based on the privileges of the user. For instance, only a user with Administrator privileges should be able to view all the versions in the system. However, that is not the case now. Every user can view all the versions irrespective of whether the user is a student or an administrator.&lt;br /&gt;
* Any user can delete any version&lt;br /&gt;
::The versions which a particular user can delete should be restricted based on the privileges of the user. For instance, a student should not be allowed to delete any version. According to the current implementation any user can delete any version in the system.&lt;br /&gt;
* Filtering of versions were restricted to the current user&lt;br /&gt;
::The filtering options on versions were restricted to the current user. Sometimes a user might want to view versions associated with other users. For instance, an instructor might want to view the list of versions created by a particular student. This is not possible with the current implementation.&lt;br /&gt;
&lt;br /&gt;
=====Drawbacks and Solutions=====&lt;br /&gt;
* '''Problem 1''': The method paginate_list is doing more than one thing.&lt;br /&gt;
::The method paginate_list was building a complex search criteria based on the input params, getting the list of versions from the Database matching this search criteria and then calling the Page API. All these tasks in a single method made it difficult to understand.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# For filtering the versions list with proper search and pagination.&lt;br /&gt;
  def paginate_list(id, user_id, item_type, event, datetime)&lt;br /&gt;
    # Set up the search criteria&lt;br /&gt;
    criteria = ''&lt;br /&gt;
    criteria = criteria + &amp;quot;id = #{id} AND &amp;quot; if id &amp;amp;&amp;amp; id.to_i &amp;gt; 0&lt;br /&gt;
    if current_user_role? == 'Super-Administrator'&lt;br /&gt;
      criteria = criteria + &amp;quot;whodunnit = #{user_id} AND &amp;quot; if user_id &amp;amp;&amp;amp; user_id.to_i &amp;gt; 0&lt;br /&gt;
    end&lt;br /&gt;
    criteria = criteria + &amp;quot;whodunnit = #{current_user.try(:id)} AND &amp;quot; if current_user.try(:id) &amp;amp;&amp;amp; current_user.try(:id).to_i &amp;gt; 0&lt;br /&gt;
    criteria = criteria + &amp;quot;item_type = '#{item_type}' AND &amp;quot; if item_type &amp;amp;&amp;amp; !(item_type.eql? 'Any')&lt;br /&gt;
    criteria = criteria + &amp;quot;event = '#{event}' AND &amp;quot; if event &amp;amp;&amp;amp; !(event.eql? 'Any')&lt;br /&gt;
    criteria = criteria + &amp;quot;created_at &amp;gt;= '#{time_to_string(params[:start_time])}' AND &amp;quot;&lt;br /&gt;
    criteria = criteria + &amp;quot;created_at &amp;lt;= '#{time_to_string(params[:end_time])}' AND &amp;quot;&lt;br /&gt;
&lt;br /&gt;
    if current_role == 'Instructor' || current_role == 'Administrator'&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # Remove the last ' AND '&lt;br /&gt;
    criteria = criteria[0..-5]&lt;br /&gt;
&lt;br /&gt;
    versions = Version.page(params[:page]).order('id').per_page(25).where(criteria)&lt;br /&gt;
    versions&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* '''Solution''': The implementation has been changed in such a way that the versions which a user is allowed to see depends on the privileges of the user. The approach we have taken is as follows:&lt;br /&gt;
**An administrator can see all the versions&lt;br /&gt;
**An instructor can see all the versions created by him and other users who are in his course or are participants in the assignments he creates.&lt;br /&gt;
**A TA can see all the versions created by him and other users who are in the course for which he/ she assists.&lt;br /&gt;
**A Student can see all the versions created by him/ her.&lt;br /&gt;
* '''Problem 2''': The search criteria created in the method paginate_list was difficult to comprehend.&lt;br /&gt;
::The code which builds the search criteria in the method paginate_list uses many string literals and conditions and is hardly intuitive. The programmer will have to spend some time to understand what the code is really doing.&lt;br /&gt;
* '''Solution''': The implementation has been changed. A student is not allowed to delete any versions now. Other types of users, for instance administrators, instructors and TAs are allowed to delete only the versions they are authorized to view.&lt;br /&gt;
* '''Problem 3''': The paginate method can be moved to a helper class.&lt;br /&gt;
::VersionsController is not the only component which require to paginate items. There are other components too. For instance, the UsersController has to paginate the list of users. Hence the Paginate method can be moved to a helper class which can be accessed by other components as well.&lt;br /&gt;
* '''Solution''': The filtering options has also been enhanced. The current user can now choose as part of the version search filter any user from a list of users if the current user is authorized to see the versions created by that user.&lt;br /&gt;
&lt;br /&gt;
===New Implementation===&lt;br /&gt;
*The method paginate_list has been split into 2 methods now. &lt;br /&gt;
** BuildSearchCriteria – as the name suggests the sole purpose of this method is to build a search criteria based on the input search filters when the current user initiates a search in versions.&lt;br /&gt;
** paginate_list – this method will call the paginate API.&lt;br /&gt;
:First the search criteria is built, then the criteria is applied to versions in the database to get all versions which matches the criteria and then the retrieved versions are paginated.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # pagination.&lt;br /&gt;
  def paginate_list(versions)&lt;br /&gt;
    paginate(versions, VERSIONS_PER_PAGE);&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def BuildSearchCriteria(id, user_id, item_type, event)&lt;br /&gt;
    # Set up the search criteria&lt;br /&gt;
    search_criteria = ''&lt;br /&gt;
    search_criteria = search_criteria + add_id_filter_if_valid(id).to_s&lt;br /&gt;
    if current_user_role? == 'Super-Administrator'&lt;br /&gt;
      search_criteria = search_criteria + add_user_filter_for_super_admin(user_id).to_s&lt;br /&gt;
    end&lt;br /&gt;
    search_criteria = search_criteria + add_user_filter&lt;br /&gt;
    search_criteria = search_criteria + add_version_type_filter(item_type).to_s&lt;br /&gt;
    search_criteria = search_criteria + add_event_filter(event).to_s&lt;br /&gt;
    search_criteria = search_criteria + add_date_time_filter&lt;br /&gt;
    search_criteria&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The string literals and conditions in the method paginate_list were replaced with methods with intuitive names so that the programmer can understand the code more easily. We also removed an empty if clause and a redundant statement.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def add_id_filter_if_valid (id)&lt;br /&gt;
    &amp;quot;id = #{id} AND &amp;quot; if id &amp;amp;&amp;amp; id.to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_user_filter_for_super_admin (user_id)&lt;br /&gt;
    &amp;quot;whodunnit = #{user_id} AND &amp;quot; if user_id &amp;amp;&amp;amp; user_id.to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_user_filter&lt;br /&gt;
    &amp;quot;whodunnit = #{current_user.try(:id)} AND &amp;quot; if current_user.try(:id) &amp;amp;&amp;amp; current_user.try(:id).to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_event_filter (event)&lt;br /&gt;
    &amp;quot;event = '#{event}' AND &amp;quot; if event &amp;amp;&amp;amp; !(event.eql? 'Any')&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_date_time_filter&lt;br /&gt;
    &amp;quot;created_at &amp;gt;= '#{time_to_string(params[:start_time])}' AND &amp;quot; +&lt;br /&gt;
        &amp;quot;created_at &amp;lt;= '#{time_to_string(params[:end_time])}'&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_version_type_filter (version_type)&lt;br /&gt;
    &amp;quot;item_type = '#{version_type}' AND &amp;quot; if version_type &amp;amp;&amp;amp; !(version_type.eql? 'Any')&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The paginate method has been moved to the helper class Pagination_Helper. This new method can be now reused by the different components like UsersController etc. The method receives two parameters, first the list to paginate and second the number of items to be displayed in a page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module PaginationHelper&lt;br /&gt;
&lt;br /&gt;
  def paginate (items, number_of_items_per_page)&lt;br /&gt;
    items.page(params[:page]).per_page(number_of_items_per_page)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code improvements===&lt;br /&gt;
* Introduced a constant VERSIONS_PER_PAGE and assigned the value 25 to it. The pagination algorithm for VersionsController displays at most 25 versions in a page. The existing implementation uses the value 25 straight in the code and there are few problems associated with such an approach.&lt;br /&gt;
** It is not easy to understand what 25 is unless the programmer takes a close look at the code.&lt;br /&gt;
** In case if the value 25 is used at more than one places and in future a new requirement comes to show at most 30 versions in a page, all the values will have to be modified. It is not very DRY.&lt;br /&gt;
* The VersionsController was overriding AccessHelper - action_allowed? method to return true in all the cases. This was violating the whole purpose of the method action_allowed?. The purpose of this method is to determine whether the user who is triggering a CRUD operation is allowed to do so. So when the current user invokes a CRUD operation, the action_allowed? method is invoked first and if the method returns true the CRUD operation is triggered or else the user is intimated with a message and gracefully exited. Hence, when the action_allowed? method is overridden to return true always, it results in providing unauthorized access to certain users.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def action_allowed?&lt;br /&gt;
    true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:With the new implementation the AccessHelper - action_allowed? method has been modified in such a way that unauthorized access is prevented. As per the new algorithm, 'new', 'create', 'edit', 'update' cannot be invoked by any user. These operations can be accessed only by ‘papertrail’ gem. Only an ‘Administrator’ or ‘Super-Administrator’ can call 'destroy_all' method. All the other methods are accessible to ‘Administrator’,  ‘Super-Administrator’, ‘Instructor’, ‘Teaching Assistant’ and ‘Student’.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    case params[:action]&lt;br /&gt;
    when 'new', 'create', 'edit', 'update'&lt;br /&gt;
    #Modifications can only be done by papertrail&lt;br /&gt;
      return false&lt;br /&gt;
    when 'destroy_all'&lt;br /&gt;
      ['Super-Administrator',&lt;br /&gt;
       'Administrator'].include? current_role_name&lt;br /&gt;
    else&lt;br /&gt;
      #Allow all others&lt;br /&gt;
      ['Super-Administrator',&lt;br /&gt;
       'Administrator',&lt;br /&gt;
       'Instructor',&lt;br /&gt;
       'Teaching Assistant',&lt;br /&gt;
       'Student'].include? current_role_name&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Automated Testing using RSPEC===&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/WintersLt/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[http://bit.ly/myexpertiza  Demo link] &lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;br /&gt;
#[https://relishapp.com/rspec Rspec Documentation]&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1553_AAJ&amp;diff=97454</id>
		<title>CSC/ECE 517 Fall 2015/oss E1553 AAJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1553_AAJ&amp;diff=97454"/>
		<updated>2015-10-31T04:45:21Z</updated>

		<summary type="html">&lt;p&gt;Asayal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1553. Refactoring the Versions Controller==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Introduction to Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a large project developed as a combined effort of students and faculty using the [http://rubyonrails.org/ Ruby on Rails] framework. The main advantage of using Expertiza, in an educational environment, is for the instructor to introduce peer reviewing among the students. Expertiza allows the instructor to create and customize assignments, create a list of topics the students can sign up for, have students work on teams and then review each other's assignments at the end. Expertiza supports submission of almost any document type, including the URLs and wiki pages. Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the [http://www.ncsu.edu/ NCSU] [http://litre.ncsu.edu/ Learning in a Technology-Rich Environment] (LITRE) program, the NCSU [http://ofd.ncsu.edu/teaching-learning/ Faculty Center for Teaching and Learning], the NCSU [http://stem.ncsu.edu/ STEM] Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
The following tasks were accomplished in this project:&lt;br /&gt;
&lt;br /&gt;
* Improved the clarity of code by improving the variable and parameter names.&lt;br /&gt;
* Long character strings were taken and given appropriate names.&lt;br /&gt;
* Handled pagination by a separate helper module, which can be used by multiple controllers.&lt;br /&gt;
* Implemented action_allowed for access_control  to prevent unauthorized access of methods.&lt;br /&gt;
* Prevented displaying of all versions for all users and tables when a user views the index page.&lt;br /&gt;
* Added missing CRUD methods to Versions Controller&lt;br /&gt;
* Added RSPEC testcases for testing changes done in Versions Controller&lt;br /&gt;
&lt;br /&gt;
===About Versions Controller===&lt;br /&gt;
This class manages different versions of reviews.  If a reviewer reviews a submission, and after that, the author revises the submission, the next time the reviewer does a review (s)he will create a new version.  Sometimes it’s necessary to find the current version of a review; sometimes it’s necessary to find all versions.  Similarly, a user may want to delete the current version of a review, or all versions of a review.&lt;br /&gt;
Pagination of versions helps the user to view a subset of versions at a time. Considering the huge number of versions in the system, it is very useful to have a pagination mechanism and a filtering mechanism which can be applied on the whole set of versions. The idea is to display the versions in an ordered, comprehensible and logical manner. In Expertiza the gem ‘will_paginate’ is used to achieve pagination.&lt;br /&gt;
&lt;br /&gt;
===Current Implementation===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=====Functionality=====&lt;br /&gt;
* Any user irrespective of his/ her privileges can view all the versions.&lt;br /&gt;
::The versions which a particular user can view should be restricted based on the privileges of the user. For instance, only a user with Administrator privileges should be able to view all the versions in the system. However, that is not the case now. Every user can view all the versions irrespective of whether the user is a student or an administrator.&lt;br /&gt;
* Any user can delete any version&lt;br /&gt;
::The versions which a particular user can delete should be restricted based on the privileges of the user. For instance, a student should not be allowed to delete any version. According to the current implementation any user can delete any version in the system.&lt;br /&gt;
* Filtering of versions were restricted to the current user&lt;br /&gt;
::The filtering options on versions were restricted to the current user. Sometimes a user might want to view versions associated with other users. For instance, an instructor might want to view the list of versions created by a particular student. This is not possible with the current implementation.&lt;br /&gt;
&lt;br /&gt;
=====Drawbacks and Solutions=====&lt;br /&gt;
* '''Problem 1''': The method paginate_list is doing more than one thing.&lt;br /&gt;
::The method paginate_list was building a complex search criteria based on the input params, getting the list of versions from the Database matching this search criteria and then calling the Page API. All these tasks in a single method made it difficult to understand.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# For filtering the versions list with proper search and pagination.&lt;br /&gt;
  def paginate_list(id, user_id, item_type, event, datetime)&lt;br /&gt;
    # Set up the search criteria&lt;br /&gt;
    criteria = ''&lt;br /&gt;
    criteria = criteria + &amp;quot;id = #{id} AND &amp;quot; if id &amp;amp;&amp;amp; id.to_i &amp;gt; 0&lt;br /&gt;
    if current_user_role? == 'Super-Administrator'&lt;br /&gt;
      criteria = criteria + &amp;quot;whodunnit = #{user_id} AND &amp;quot; if user_id &amp;amp;&amp;amp; user_id.to_i &amp;gt; 0&lt;br /&gt;
    end&lt;br /&gt;
    criteria = criteria + &amp;quot;whodunnit = #{current_user.try(:id)} AND &amp;quot; if current_user.try(:id) &amp;amp;&amp;amp; current_user.try(:id).to_i &amp;gt; 0&lt;br /&gt;
    criteria = criteria + &amp;quot;item_type = '#{item_type}' AND &amp;quot; if item_type &amp;amp;&amp;amp; !(item_type.eql? 'Any')&lt;br /&gt;
    criteria = criteria + &amp;quot;event = '#{event}' AND &amp;quot; if event &amp;amp;&amp;amp; !(event.eql? 'Any')&lt;br /&gt;
    criteria = criteria + &amp;quot;created_at &amp;gt;= '#{time_to_string(params[:start_time])}' AND &amp;quot;&lt;br /&gt;
    criteria = criteria + &amp;quot;created_at &amp;lt;= '#{time_to_string(params[:end_time])}' AND &amp;quot;&lt;br /&gt;
&lt;br /&gt;
    if current_role == 'Instructor' || current_role == 'Administrator'&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # Remove the last ' AND '&lt;br /&gt;
    criteria = criteria[0..-5]&lt;br /&gt;
&lt;br /&gt;
    versions = Version.page(params[:page]).order('id').per_page(25).where(criteria)&lt;br /&gt;
    versions&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* '''Solution''': The implementation has been changed in such a way that the versions which a user is allowed to see depends on the privileges of the user. The approach we have taken is as follows:&lt;br /&gt;
**An administrator can see all the versions&lt;br /&gt;
**An instructor can see all the versions created by him and other users who are in his course or are participants in the assignments he creates.&lt;br /&gt;
**A TA can see all the versions created by him and other users who are in the course for which he/ she assists.&lt;br /&gt;
**A Student can see all the versions created by him/ her.&lt;br /&gt;
* '''Problem 2''': The search criteria created in the method paginate_list was difficult to comprehend.&lt;br /&gt;
::The code which builds the search criteria in the method paginate_list uses many string literals and conditions and is hardly intuitive. The programmer will have to spend some time to understand what the code is really doing.&lt;br /&gt;
* '''Solution''': The implementation has been changed. A student is not allowed to delete any versions now. Other types of users, for instance administrators, instructors and TAs are allowed to delete only the versions they are authorized to view.&lt;br /&gt;
* '''Problem 3''': The paginate method can be moved to a helper class.&lt;br /&gt;
::VersionsController is not the only component which require to paginate items. There are other components too. For instance, the UsersController has to paginate the list of users. Hence the Paginate method can be moved to a helper class which can be accessed by other components as well.&lt;br /&gt;
* '''Solution''': The filtering options has also been enhanced. The current user can now choose as part of the version search filter any user from a list of users if the current user is authorized to see the versions created by that user.&lt;br /&gt;
&lt;br /&gt;
===New Implementation===&lt;br /&gt;
*The method paginate_list has been split into 2 methods now. &lt;br /&gt;
** BuildSearchCriteria – as the name suggests the sole purpose of this method is to build a search criteria based on the input search filters when the current user initiates a search in versions.&lt;br /&gt;
** paginate_list – this method will call the paginate API.&lt;br /&gt;
:First the search criteria is built, then the criteria is applied to versions in the database to get all versions which matches the criteria and then the retrieved versions are paginated.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # pagination.&lt;br /&gt;
  def paginate_list(versions)&lt;br /&gt;
    paginate(versions, VERSIONS_PER_PAGE);&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def BuildSearchCriteria(id, user_id, item_type, event)&lt;br /&gt;
    # Set up the search criteria&lt;br /&gt;
    search_criteria = ''&lt;br /&gt;
    search_criteria = search_criteria + add_id_filter_if_valid(id).to_s&lt;br /&gt;
    if current_user_role? == 'Super-Administrator'&lt;br /&gt;
      search_criteria = search_criteria + add_user_filter_for_super_admin(user_id).to_s&lt;br /&gt;
    end&lt;br /&gt;
    search_criteria = search_criteria + add_user_filter&lt;br /&gt;
    search_criteria = search_criteria + add_version_type_filter(item_type).to_s&lt;br /&gt;
    search_criteria = search_criteria + add_event_filter(event).to_s&lt;br /&gt;
    search_criteria = search_criteria + add_date_time_filter&lt;br /&gt;
    search_criteria&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The string literals and conditions in the method paginate_list were replaced with methods with intuitive names so that the programmer can understand the code more easily. We also removed an empty if clause and a redundant statement.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def add_id_filter_if_valid (id)&lt;br /&gt;
    &amp;quot;id = #{id} AND &amp;quot; if id &amp;amp;&amp;amp; id.to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_user_filter_for_super_admin (user_id)&lt;br /&gt;
    &amp;quot;whodunnit = #{user_id} AND &amp;quot; if user_id &amp;amp;&amp;amp; user_id.to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_user_filter&lt;br /&gt;
    &amp;quot;whodunnit = #{current_user.try(:id)} AND &amp;quot; if current_user.try(:id) &amp;amp;&amp;amp; current_user.try(:id).to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_event_filter (event)&lt;br /&gt;
    &amp;quot;event = '#{event}' AND &amp;quot; if event &amp;amp;&amp;amp; !(event.eql? 'Any')&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_date_time_filter&lt;br /&gt;
    &amp;quot;created_at &amp;gt;= '#{time_to_string(params[:start_time])}' AND &amp;quot; +&lt;br /&gt;
        &amp;quot;created_at &amp;lt;= '#{time_to_string(params[:end_time])}'&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_version_type_filter (version_type)&lt;br /&gt;
    &amp;quot;item_type = '#{version_type}' AND &amp;quot; if version_type &amp;amp;&amp;amp; !(version_type.eql? 'Any')&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The paginate method has been moved to the helper class Pagination_Helper. This new method can be now reused by the different components like UsersController etc. The method receives two parameters, first the list to paginate and second the number of items to be displayed in a page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module PaginationHelper&lt;br /&gt;
&lt;br /&gt;
  def paginate (items, number_of_items_per_page)&lt;br /&gt;
    items.page(params[:page]).per_page(number_of_items_per_page)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code improvements===&lt;br /&gt;
* Introduced a constant VERSIONS_PER_PAGE and assigned the value 25 to it. The pagination algorithm for VersionsController displays at most 25 versions in a page. The existing implementation uses the value 25 straight in the code and there are few problems associated with such an approach.&lt;br /&gt;
** It is not easy to understand what 25 is unless the programmer takes a close look at the code.&lt;br /&gt;
** In case if the value 25 is used at more than one places and in future a new requirement comes to show at most 30 versions in a page, all the values will have to be modified. It is not very DRY.&lt;br /&gt;
* The VersionsController was overriding AccessHelper - action_allowed? method to return true in all the cases. This was violating the whole purpose of the method action_allowed?. The purpose of this method is to determine whether the user who is triggering a CRUD operation is allowed to do so. So when the current user invokes a CRUD operation, the action_allowed? method is invoked first and if the method returns true the CRUD operation is triggered or else the user is intimated with a message and gracefully exited. Hence, when the action_allowed? method is overridden to return true always, it results in providing unauthorized access to certain users.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def action_allowed?&lt;br /&gt;
    true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:With the new implementation the AccessHelper - action_allowed? method has been modified in such a way that unauthorized access is prevented. As per the new algorithm, 'new', 'create', 'edit', 'update' cannot be invoked by any user. These operations can be accessed only by ‘papertrail’ gem. Only an ‘Administrator’ or ‘Super-Administrator’ can call 'destroy_all' method. All the other methods are accessible to ‘Administrator’,  ‘Super-Administrator’, ‘Instructor’, ‘Teaching Assistant’ and ‘Student’.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    case params[:action]&lt;br /&gt;
    when 'new', 'create', 'edit', 'update'&lt;br /&gt;
    #Modifications can only be done by papertrail&lt;br /&gt;
      return false&lt;br /&gt;
    when 'destroy_all'&lt;br /&gt;
      ['Super-Administrator',&lt;br /&gt;
       'Administrator'].include? current_role_name&lt;br /&gt;
    else&lt;br /&gt;
      #Allow all others&lt;br /&gt;
      ['Super-Administrator',&lt;br /&gt;
       'Administrator',&lt;br /&gt;
       'Instructor',&lt;br /&gt;
       'Teaching Assistant',&lt;br /&gt;
       'Student'].include? current_role_name&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Automated Testing using RSPEC===&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/WintersLt/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[http://bit.ly/myexpertiza  Demo link] &lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;br /&gt;
#[https://relishapp.com/rspec Rspec Documentation]&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1553_AAJ&amp;diff=97453</id>
		<title>CSC/ECE 517 Fall 2015/oss E1553 AAJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1553_AAJ&amp;diff=97453"/>
		<updated>2015-10-31T04:41:42Z</updated>

		<summary type="html">&lt;p&gt;Asayal: /* Automated Testing using Rspec */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1553. Refactoring the Versions Controller==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Introduction to Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a large project developed as a combined effort of students and faculty using the [http://rubyonrails.org/ Ruby on Rails] framework. The main advantage of using Expertiza, in an educational environment, is for the instructor to introduce peer reviewing among the students. Expertiza allows the instructor to create and customize assignments, create a list of topics the students can sign up for, have students work on teams and then review each other's assignments at the end. Expertiza supports submission of almost any document type, including the URLs and wiki pages. Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the [http://www.ncsu.edu/ NCSU] [http://litre.ncsu.edu/ Learning in a Technology-Rich Environment] (LITRE) program, the NCSU [http://ofd.ncsu.edu/teaching-learning/ Faculty Center for Teaching and Learning], the NCSU [http://stem.ncsu.edu/ STEM] Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
The following tasks were accomplished in this project:&lt;br /&gt;
&lt;br /&gt;
* Improved the clarity of code by improving the variable and parameter names.&lt;br /&gt;
* Long character strings were taken and given appropriate names.&lt;br /&gt;
* Handled pagination by a separate helper module, which can be used by multiple controllers.&lt;br /&gt;
* Implemented action_allowed for access_control  to prevent unauthorized access of methods.&lt;br /&gt;
* Prevented displaying of all versions for all users and tables when a user views the index page.&lt;br /&gt;
* Added missing CRUD methods to Versions Controller&lt;br /&gt;
* Added RSPEC testcases for testing changes done in Versions Controller&lt;br /&gt;
&lt;br /&gt;
===About Versions Controller===&lt;br /&gt;
This class manages different versions of reviews.  If a reviewer reviews a submission, and after that, the author revises the submission, the next time the reviewer does a review (s)he will create a new version.  Sometimes it’s necessary to find the current version of a review; sometimes it’s necessary to find all versions.  Similarly, a user may want to delete the current version of a review, or all versions of a review.&lt;br /&gt;
Pagination of versions helps the user to view a subset of versions at a time. Considering the huge number of versions in the system, it is very useful to have a pagination mechanism and a filtering mechanism which can be applied on the whole set of versions. The idea is to display the versions in an ordered, comprehensible and logical manner. In Expertiza the gem ‘will_paginate’ is used to achieve pagination.&lt;br /&gt;
&lt;br /&gt;
===Current Implementation===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=====Functionality=====&lt;br /&gt;
* Any user irrespective of his/ her privileges can view all the versions.&lt;br /&gt;
::The versions which a particular user can view should be restricted based on the privileges of the user. For instance, only a user with Administrator privileges should be able to view all the versions in the system. However, that is not the case now. Every user can view all the versions irrespective of whether the user is a student or an administrator.&lt;br /&gt;
* Any user can delete any version&lt;br /&gt;
::The versions which a particular user can delete should be restricted based on the privileges of the user. For instance, a student should not be allowed to delete any version. According to the current implementation any user can delete any version in the system.&lt;br /&gt;
* Filtering of versions were restricted to the current user&lt;br /&gt;
::The filtering options on versions were restricted to the current user. Sometimes a user might want to view versions associated with other users. For instance, an instructor might want to view the list of versions created by a particular student. This is not possible with the current implementation.&lt;br /&gt;
&lt;br /&gt;
=====Drawbacks and Solutions=====&lt;br /&gt;
* '''Problem 1''': The method paginate_list is doing more than one thing.&lt;br /&gt;
::The method paginate_list was building a complex search criteria based on the input params, getting the list of versions from the Database matching this search criteria and then calling the Page API. All these tasks in a single method made it difficult to understand.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# For filtering the versions list with proper search and pagination.&lt;br /&gt;
  def paginate_list(id, user_id, item_type, event, datetime)&lt;br /&gt;
    # Set up the search criteria&lt;br /&gt;
    criteria = ''&lt;br /&gt;
    criteria = criteria + &amp;quot;id = #{id} AND &amp;quot; if id &amp;amp;&amp;amp; id.to_i &amp;gt; 0&lt;br /&gt;
    if current_user_role? == 'Super-Administrator'&lt;br /&gt;
      criteria = criteria + &amp;quot;whodunnit = #{user_id} AND &amp;quot; if user_id &amp;amp;&amp;amp; user_id.to_i &amp;gt; 0&lt;br /&gt;
    end&lt;br /&gt;
    criteria = criteria + &amp;quot;whodunnit = #{current_user.try(:id)} AND &amp;quot; if current_user.try(:id) &amp;amp;&amp;amp; current_user.try(:id).to_i &amp;gt; 0&lt;br /&gt;
    criteria = criteria + &amp;quot;item_type = '#{item_type}' AND &amp;quot; if item_type &amp;amp;&amp;amp; !(item_type.eql? 'Any')&lt;br /&gt;
    criteria = criteria + &amp;quot;event = '#{event}' AND &amp;quot; if event &amp;amp;&amp;amp; !(event.eql? 'Any')&lt;br /&gt;
    criteria = criteria + &amp;quot;created_at &amp;gt;= '#{time_to_string(params[:start_time])}' AND &amp;quot;&lt;br /&gt;
    criteria = criteria + &amp;quot;created_at &amp;lt;= '#{time_to_string(params[:end_time])}' AND &amp;quot;&lt;br /&gt;
&lt;br /&gt;
    if current_role == 'Instructor' || current_role == 'Administrator'&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # Remove the last ' AND '&lt;br /&gt;
    criteria = criteria[0..-5]&lt;br /&gt;
&lt;br /&gt;
    versions = Version.page(params[:page]).order('id').per_page(25).where(criteria)&lt;br /&gt;
    versions&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* '''Solution''': The implementation has been changed in such a way that the versions which a user is allowed to see depends on the privileges of the user. The approach we have taken is as follows:&lt;br /&gt;
**An administrator can see all the versions&lt;br /&gt;
**An instructor can see all the versions created by him and other users who are in his course or are participants in the assignments he creates.&lt;br /&gt;
**A TA can see all the versions created by him and other users who are in the course for which he/ she assists.&lt;br /&gt;
**A Student can see all the versions created by him/ her.&lt;br /&gt;
* '''Problem 2''': The search criteria created in the method paginate_list was difficult to comprehend.&lt;br /&gt;
::The code which builds the search criteria in the method paginate_list uses many string literals and conditions and is hardly intuitive. The programmer will have to spend some time to understand what the code is really doing.&lt;br /&gt;
* '''Solution''': The implementation has been changed. A student is not allowed to delete any versions now. Other types of users, for instance administrators, instructors and TAs are allowed to delete only the versions they are authorized to view.&lt;br /&gt;
* '''Problem 3''': The paginate method can be moved to a helper class.&lt;br /&gt;
::VersionsController is not the only component which require to paginate items. There are other components too. For instance, the UsersController has to paginate the list of users. Hence the Paginate method can be moved to a helper class which can be accessed by other components as well.&lt;br /&gt;
* '''Solution''': The filtering options has also been enhanced. The current user can now choose as part of the version search filter any user from a list of users if the current user is authorized to see the versions created by that user.&lt;br /&gt;
&lt;br /&gt;
===New Implementation===&lt;br /&gt;
*The method paginate_list has been split into 2 methods now. &lt;br /&gt;
** BuildSearchCriteria – as the name suggests the sole purpose of this method is to build a search criteria based on the input search filters when the current user initiates a search in versions.&lt;br /&gt;
** paginate_list – this method will call the paginate API.&lt;br /&gt;
:First the search criteria is built, then the criteria is applied to versions in the database to get all versions which matches the criteria and then the retrieved versions are paginated.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # pagination.&lt;br /&gt;
  def paginate_list(versions)&lt;br /&gt;
    paginate(versions, VERSIONS_PER_PAGE);&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def BuildSearchCriteria(id, user_id, item_type, event)&lt;br /&gt;
    # Set up the search criteria&lt;br /&gt;
    search_criteria = ''&lt;br /&gt;
    search_criteria = search_criteria + add_id_filter_if_valid(id).to_s&lt;br /&gt;
    if current_user_role? == 'Super-Administrator'&lt;br /&gt;
      search_criteria = search_criteria + add_user_filter_for_super_admin(user_id).to_s&lt;br /&gt;
    end&lt;br /&gt;
    search_criteria = search_criteria + add_user_filter&lt;br /&gt;
    search_criteria = search_criteria + add_version_type_filter(item_type).to_s&lt;br /&gt;
    search_criteria = search_criteria + add_event_filter(event).to_s&lt;br /&gt;
    search_criteria = search_criteria + add_date_time_filter&lt;br /&gt;
    search_criteria&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The string literals and conditions in the method paginate_list were replaced with methods with intuitive names so that the programmer can understand the code more easily. We also removed an empty if clause and a redundant statement.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def add_id_filter_if_valid (id)&lt;br /&gt;
    &amp;quot;id = #{id} AND &amp;quot; if id &amp;amp;&amp;amp; id.to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_user_filter_for_super_admin (user_id)&lt;br /&gt;
    &amp;quot;whodunnit = #{user_id} AND &amp;quot; if user_id &amp;amp;&amp;amp; user_id.to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_user_filter&lt;br /&gt;
    &amp;quot;whodunnit = #{current_user.try(:id)} AND &amp;quot; if current_user.try(:id) &amp;amp;&amp;amp; current_user.try(:id).to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_event_filter (event)&lt;br /&gt;
    &amp;quot;event = '#{event}' AND &amp;quot; if event &amp;amp;&amp;amp; !(event.eql? 'Any')&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_date_time_filter&lt;br /&gt;
    &amp;quot;created_at &amp;gt;= '#{time_to_string(params[:start_time])}' AND &amp;quot; +&lt;br /&gt;
        &amp;quot;created_at &amp;lt;= '#{time_to_string(params[:end_time])}'&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_version_type_filter (version_type)&lt;br /&gt;
    &amp;quot;item_type = '#{version_type}' AND &amp;quot; if version_type &amp;amp;&amp;amp; !(version_type.eql? 'Any')&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The paginate method has been moved to the helper class Pagination_Helper. This new method can be now reused by the different components like UsersController etc. The method receives two parameters, first the list to paginate and second the number of items to be displayed in a page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module PaginationHelper&lt;br /&gt;
&lt;br /&gt;
  def paginate (items, number_of_items_per_page)&lt;br /&gt;
    items.page(params[:page]).per_page(number_of_items_per_page)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Code improvements===&lt;br /&gt;
* Introduced a constant VERSIONS_PER_PAGE and assigned the value 25 to it. The pagination algorithm for VersionsController displays at most 25 versions in a page. The existing implementation uses the value 25 straight in the code and there are few problems associated with such an approach.&lt;br /&gt;
** It is not easy to understand what 25 is unless the programmer takes a close look at the code.&lt;br /&gt;
** In case if the value 25 is used at more than one places and in future a new requirement comes to show at most 30 versions in a page, all the values will have to be modified. It is not very DRY.&lt;br /&gt;
* The VersionsController was overriding AccessHelper - action_allowed? method to return true in all the cases. This was violating the whole purpose of the method action_allowed?. The purpose of this method is to determine whether the user who is triggering a CRUD operation is allowed to do so. So when the current user invokes a CRUD operation, the action_allowed? method is invoked first and if the method returns true the CRUD operation is triggered or else the user is intimated with a message and gracefully exited. Hence, when the action_allowed? method is overridden to return true always, it results in providing unauthorized access to certain users.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def action_allowed?&lt;br /&gt;
    true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:With the new implementation the AccessHelper - action_allowed? method has been modified in such a way that unauthorized access is prevented. As per the new algorithm, 'new', 'create', 'edit', 'update' cannot be invoked by any user. These operations can be accessed only by ‘papertrail’ gem. Only an ‘Administrator’ or ‘Super-Administrator’ can call 'destroy_all' method. All the other methods are accessible to ‘Administrator’,  ‘Super-Administrator’, ‘Instructor’, ‘Teaching Assistant’ and ‘Student’.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    case params[:action]&lt;br /&gt;
    when 'new', 'create', 'edit', 'update'&lt;br /&gt;
    #Modifications can only be done by papertrail&lt;br /&gt;
      return false&lt;br /&gt;
    when 'destroy_all'&lt;br /&gt;
      ['Super-Administrator',&lt;br /&gt;
       'Administrator'].include? current_role_name&lt;br /&gt;
    else&lt;br /&gt;
      #Allow all others&lt;br /&gt;
      ['Super-Administrator',&lt;br /&gt;
       'Administrator',&lt;br /&gt;
       'Instructor',&lt;br /&gt;
       'Teaching Assistant',&lt;br /&gt;
       'Student'].include? current_role_name&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Automated Testing using RSPEC===&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/WintersLt/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[http://bit.ly/myexpertiza  Demo link] &lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;br /&gt;
#[https://relishapp.com/rspec Rspec Documentation]&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1553_AAJ&amp;diff=97452</id>
		<title>CSC/ECE 517 Fall 2015/oss E1553 AAJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1553_AAJ&amp;diff=97452"/>
		<updated>2015-10-31T04:41:21Z</updated>

		<summary type="html">&lt;p&gt;Asayal: /* Drawbacks and Solutions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1553. Refactoring the Versions Controller==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Introduction to Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a large project developed as a combined effort of students and faculty using the [http://rubyonrails.org/ Ruby on Rails] framework. The main advantage of using Expertiza, in an educational environment, is for the instructor to introduce peer reviewing among the students. Expertiza allows the instructor to create and customize assignments, create a list of topics the students can sign up for, have students work on teams and then review each other's assignments at the end. Expertiza supports submission of almost any document type, including the URLs and wiki pages. Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the [http://www.ncsu.edu/ NCSU] [http://litre.ncsu.edu/ Learning in a Technology-Rich Environment] (LITRE) program, the NCSU [http://ofd.ncsu.edu/teaching-learning/ Faculty Center for Teaching and Learning], the NCSU [http://stem.ncsu.edu/ STEM] Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
The following tasks were accomplished in this project:&lt;br /&gt;
&lt;br /&gt;
* Improved the clarity of code by improving the variable and parameter names.&lt;br /&gt;
* Long character strings were taken and given appropriate names.&lt;br /&gt;
* Handled pagination by a separate helper module, which can be used by multiple controllers.&lt;br /&gt;
* Implemented action_allowed for access_control  to prevent unauthorized access of methods.&lt;br /&gt;
* Prevented displaying of all versions for all users and tables when a user views the index page.&lt;br /&gt;
* Added missing CRUD methods to Versions Controller&lt;br /&gt;
* Added RSPEC testcases for testing changes done in Versions Controller&lt;br /&gt;
&lt;br /&gt;
===About Versions Controller===&lt;br /&gt;
This class manages different versions of reviews.  If a reviewer reviews a submission, and after that, the author revises the submission, the next time the reviewer does a review (s)he will create a new version.  Sometimes it’s necessary to find the current version of a review; sometimes it’s necessary to find all versions.  Similarly, a user may want to delete the current version of a review, or all versions of a review.&lt;br /&gt;
Pagination of versions helps the user to view a subset of versions at a time. Considering the huge number of versions in the system, it is very useful to have a pagination mechanism and a filtering mechanism which can be applied on the whole set of versions. The idea is to display the versions in an ordered, comprehensible and logical manner. In Expertiza the gem ‘will_paginate’ is used to achieve pagination.&lt;br /&gt;
&lt;br /&gt;
===Current Implementation===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=====Functionality=====&lt;br /&gt;
* Any user irrespective of his/ her privileges can view all the versions.&lt;br /&gt;
::The versions which a particular user can view should be restricted based on the privileges of the user. For instance, only a user with Administrator privileges should be able to view all the versions in the system. However, that is not the case now. Every user can view all the versions irrespective of whether the user is a student or an administrator.&lt;br /&gt;
* Any user can delete any version&lt;br /&gt;
::The versions which a particular user can delete should be restricted based on the privileges of the user. For instance, a student should not be allowed to delete any version. According to the current implementation any user can delete any version in the system.&lt;br /&gt;
* Filtering of versions were restricted to the current user&lt;br /&gt;
::The filtering options on versions were restricted to the current user. Sometimes a user might want to view versions associated with other users. For instance, an instructor might want to view the list of versions created by a particular student. This is not possible with the current implementation.&lt;br /&gt;
&lt;br /&gt;
=====Drawbacks and Solutions=====&lt;br /&gt;
* '''Problem 1''': The method paginate_list is doing more than one thing.&lt;br /&gt;
::The method paginate_list was building a complex search criteria based on the input params, getting the list of versions from the Database matching this search criteria and then calling the Page API. All these tasks in a single method made it difficult to understand.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# For filtering the versions list with proper search and pagination.&lt;br /&gt;
  def paginate_list(id, user_id, item_type, event, datetime)&lt;br /&gt;
    # Set up the search criteria&lt;br /&gt;
    criteria = ''&lt;br /&gt;
    criteria = criteria + &amp;quot;id = #{id} AND &amp;quot; if id &amp;amp;&amp;amp; id.to_i &amp;gt; 0&lt;br /&gt;
    if current_user_role? == 'Super-Administrator'&lt;br /&gt;
      criteria = criteria + &amp;quot;whodunnit = #{user_id} AND &amp;quot; if user_id &amp;amp;&amp;amp; user_id.to_i &amp;gt; 0&lt;br /&gt;
    end&lt;br /&gt;
    criteria = criteria + &amp;quot;whodunnit = #{current_user.try(:id)} AND &amp;quot; if current_user.try(:id) &amp;amp;&amp;amp; current_user.try(:id).to_i &amp;gt; 0&lt;br /&gt;
    criteria = criteria + &amp;quot;item_type = '#{item_type}' AND &amp;quot; if item_type &amp;amp;&amp;amp; !(item_type.eql? 'Any')&lt;br /&gt;
    criteria = criteria + &amp;quot;event = '#{event}' AND &amp;quot; if event &amp;amp;&amp;amp; !(event.eql? 'Any')&lt;br /&gt;
    criteria = criteria + &amp;quot;created_at &amp;gt;= '#{time_to_string(params[:start_time])}' AND &amp;quot;&lt;br /&gt;
    criteria = criteria + &amp;quot;created_at &amp;lt;= '#{time_to_string(params[:end_time])}' AND &amp;quot;&lt;br /&gt;
&lt;br /&gt;
    if current_role == 'Instructor' || current_role == 'Administrator'&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # Remove the last ' AND '&lt;br /&gt;
    criteria = criteria[0..-5]&lt;br /&gt;
&lt;br /&gt;
    versions = Version.page(params[:page]).order('id').per_page(25).where(criteria)&lt;br /&gt;
    versions&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* '''Solution''': The implementation has been changed in such a way that the versions which a user is allowed to see depends on the privileges of the user. The approach we have taken is as follows:&lt;br /&gt;
**An administrator can see all the versions&lt;br /&gt;
**An instructor can see all the versions created by him and other users who are in his course or are participants in the assignments he creates.&lt;br /&gt;
**A TA can see all the versions created by him and other users who are in the course for which he/ she assists.&lt;br /&gt;
**A Student can see all the versions created by him/ her.&lt;br /&gt;
* '''Problem 2''': The search criteria created in the method paginate_list was difficult to comprehend.&lt;br /&gt;
::The code which builds the search criteria in the method paginate_list uses many string literals and conditions and is hardly intuitive. The programmer will have to spend some time to understand what the code is really doing.&lt;br /&gt;
* '''Solution''': The implementation has been changed. A student is not allowed to delete any versions now. Other types of users, for instance administrators, instructors and TAs are allowed to delete only the versions they are authorized to view.&lt;br /&gt;
* '''Problem 3''': The paginate method can be moved to a helper class.&lt;br /&gt;
::VersionsController is not the only component which require to paginate items. There are other components too. For instance, the UsersController has to paginate the list of users. Hence the Paginate method can be moved to a helper class which can be accessed by other components as well.&lt;br /&gt;
* '''Solution''': The filtering options has also been enhanced. The current user can now choose as part of the version search filter any user from a list of users if the current user is authorized to see the versions created by that user.&lt;br /&gt;
&lt;br /&gt;
===New Implementation===&lt;br /&gt;
*The method paginate_list has been split into 2 methods now. &lt;br /&gt;
** BuildSearchCriteria – as the name suggests the sole purpose of this method is to build a search criteria based on the input search filters when the current user initiates a search in versions.&lt;br /&gt;
** paginate_list – this method will call the paginate API.&lt;br /&gt;
:First the search criteria is built, then the criteria is applied to versions in the database to get all versions which matches the criteria and then the retrieved versions are paginated.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # pagination.&lt;br /&gt;
  def paginate_list(versions)&lt;br /&gt;
    paginate(versions, VERSIONS_PER_PAGE);&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def BuildSearchCriteria(id, user_id, item_type, event)&lt;br /&gt;
    # Set up the search criteria&lt;br /&gt;
    search_criteria = ''&lt;br /&gt;
    search_criteria = search_criteria + add_id_filter_if_valid(id).to_s&lt;br /&gt;
    if current_user_role? == 'Super-Administrator'&lt;br /&gt;
      search_criteria = search_criteria + add_user_filter_for_super_admin(user_id).to_s&lt;br /&gt;
    end&lt;br /&gt;
    search_criteria = search_criteria + add_user_filter&lt;br /&gt;
    search_criteria = search_criteria + add_version_type_filter(item_type).to_s&lt;br /&gt;
    search_criteria = search_criteria + add_event_filter(event).to_s&lt;br /&gt;
    search_criteria = search_criteria + add_date_time_filter&lt;br /&gt;
    search_criteria&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The string literals and conditions in the method paginate_list were replaced with methods with intuitive names so that the programmer can understand the code more easily. We also removed an empty if clause and a redundant statement.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def add_id_filter_if_valid (id)&lt;br /&gt;
    &amp;quot;id = #{id} AND &amp;quot; if id &amp;amp;&amp;amp; id.to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_user_filter_for_super_admin (user_id)&lt;br /&gt;
    &amp;quot;whodunnit = #{user_id} AND &amp;quot; if user_id &amp;amp;&amp;amp; user_id.to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_user_filter&lt;br /&gt;
    &amp;quot;whodunnit = #{current_user.try(:id)} AND &amp;quot; if current_user.try(:id) &amp;amp;&amp;amp; current_user.try(:id).to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_event_filter (event)&lt;br /&gt;
    &amp;quot;event = '#{event}' AND &amp;quot; if event &amp;amp;&amp;amp; !(event.eql? 'Any')&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_date_time_filter&lt;br /&gt;
    &amp;quot;created_at &amp;gt;= '#{time_to_string(params[:start_time])}' AND &amp;quot; +&lt;br /&gt;
        &amp;quot;created_at &amp;lt;= '#{time_to_string(params[:end_time])}'&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_version_type_filter (version_type)&lt;br /&gt;
    &amp;quot;item_type = '#{version_type}' AND &amp;quot; if version_type &amp;amp;&amp;amp; !(version_type.eql? 'Any')&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The paginate method has been moved to the helper class Pagination_Helper. This new method can be now reused by the different components like UsersController etc. The method receives two parameters, first the list to paginate and second the number of items to be displayed in a page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module PaginationHelper&lt;br /&gt;
&lt;br /&gt;
  def paginate (items, number_of_items_per_page)&lt;br /&gt;
    items.page(params[:page]).per_page(number_of_items_per_page)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Code improvements===&lt;br /&gt;
* Introduced a constant VERSIONS_PER_PAGE and assigned the value 25 to it. The pagination algorithm for VersionsController displays at most 25 versions in a page. The existing implementation uses the value 25 straight in the code and there are few problems associated with such an approach.&lt;br /&gt;
** It is not easy to understand what 25 is unless the programmer takes a close look at the code.&lt;br /&gt;
** In case if the value 25 is used at more than one places and in future a new requirement comes to show at most 30 versions in a page, all the values will have to be modified. It is not very DRY.&lt;br /&gt;
* The VersionsController was overriding AccessHelper - action_allowed? method to return true in all the cases. This was violating the whole purpose of the method action_allowed?. The purpose of this method is to determine whether the user who is triggering a CRUD operation is allowed to do so. So when the current user invokes a CRUD operation, the action_allowed? method is invoked first and if the method returns true the CRUD operation is triggered or else the user is intimated with a message and gracefully exited. Hence, when the action_allowed? method is overridden to return true always, it results in providing unauthorized access to certain users.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def action_allowed?&lt;br /&gt;
    true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:With the new implementation the AccessHelper - action_allowed? method has been modified in such a way that unauthorized access is prevented. As per the new algorithm, 'new', 'create', 'edit', 'update' cannot be invoked by any user. These operations can be accessed only by ‘papertrail’ gem. Only an ‘Administrator’ or ‘Super-Administrator’ can call 'destroy_all' method. All the other methods are accessible to ‘Administrator’,  ‘Super-Administrator’, ‘Instructor’, ‘Teaching Assistant’ and ‘Student’.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    case params[:action]&lt;br /&gt;
    when 'new', 'create', 'edit', 'update'&lt;br /&gt;
    #Modifications can only be done by papertrail&lt;br /&gt;
      return false&lt;br /&gt;
    when 'destroy_all'&lt;br /&gt;
      ['Super-Administrator',&lt;br /&gt;
       'Administrator'].include? current_role_name&lt;br /&gt;
    else&lt;br /&gt;
      #Allow all others&lt;br /&gt;
      ['Super-Administrator',&lt;br /&gt;
       'Administrator',&lt;br /&gt;
       'Instructor',&lt;br /&gt;
       'Teaching Assistant',&lt;br /&gt;
       'Student'].include? current_role_name&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Automated Testing using Rspec===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/WintersLt/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[http://bit.ly/myexpertiza  Demo link] &lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;br /&gt;
#[https://relishapp.com/rspec Rspec Documentation]&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1553_AAJ&amp;diff=97451</id>
		<title>CSC/ECE 517 Fall 2015/oss E1553 AAJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1553_AAJ&amp;diff=97451"/>
		<updated>2015-10-31T04:41:09Z</updated>

		<summary type="html">&lt;p&gt;Asayal: /* Functionality */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1553. Refactoring the Versions Controller==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Introduction to Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a large project developed as a combined effort of students and faculty using the [http://rubyonrails.org/ Ruby on Rails] framework. The main advantage of using Expertiza, in an educational environment, is for the instructor to introduce peer reviewing among the students. Expertiza allows the instructor to create and customize assignments, create a list of topics the students can sign up for, have students work on teams and then review each other's assignments at the end. Expertiza supports submission of almost any document type, including the URLs and wiki pages. Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the [http://www.ncsu.edu/ NCSU] [http://litre.ncsu.edu/ Learning in a Technology-Rich Environment] (LITRE) program, the NCSU [http://ofd.ncsu.edu/teaching-learning/ Faculty Center for Teaching and Learning], the NCSU [http://stem.ncsu.edu/ STEM] Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
The following tasks were accomplished in this project:&lt;br /&gt;
&lt;br /&gt;
* Improved the clarity of code by improving the variable and parameter names.&lt;br /&gt;
* Long character strings were taken and given appropriate names.&lt;br /&gt;
* Handled pagination by a separate helper module, which can be used by multiple controllers.&lt;br /&gt;
* Implemented action_allowed for access_control  to prevent unauthorized access of methods.&lt;br /&gt;
* Prevented displaying of all versions for all users and tables when a user views the index page.&lt;br /&gt;
* Added missing CRUD methods to Versions Controller&lt;br /&gt;
* Added RSPEC testcases for testing changes done in Versions Controller&lt;br /&gt;
&lt;br /&gt;
===About Versions Controller===&lt;br /&gt;
This class manages different versions of reviews.  If a reviewer reviews a submission, and after that, the author revises the submission, the next time the reviewer does a review (s)he will create a new version.  Sometimes it’s necessary to find the current version of a review; sometimes it’s necessary to find all versions.  Similarly, a user may want to delete the current version of a review, or all versions of a review.&lt;br /&gt;
Pagination of versions helps the user to view a subset of versions at a time. Considering the huge number of versions in the system, it is very useful to have a pagination mechanism and a filtering mechanism which can be applied on the whole set of versions. The idea is to display the versions in an ordered, comprehensible and logical manner. In Expertiza the gem ‘will_paginate’ is used to achieve pagination.&lt;br /&gt;
&lt;br /&gt;
===Current Implementation===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=====Functionality=====&lt;br /&gt;
* Any user irrespective of his/ her privileges can view all the versions.&lt;br /&gt;
::The versions which a particular user can view should be restricted based on the privileges of the user. For instance, only a user with Administrator privileges should be able to view all the versions in the system. However, that is not the case now. Every user can view all the versions irrespective of whether the user is a student or an administrator.&lt;br /&gt;
* Any user can delete any version&lt;br /&gt;
::The versions which a particular user can delete should be restricted based on the privileges of the user. For instance, a student should not be allowed to delete any version. According to the current implementation any user can delete any version in the system.&lt;br /&gt;
* Filtering of versions were restricted to the current user&lt;br /&gt;
::The filtering options on versions were restricted to the current user. Sometimes a user might want to view versions associated with other users. For instance, an instructor might want to view the list of versions created by a particular student. This is not possible with the current implementation.&lt;br /&gt;
&lt;br /&gt;
====Drawbacks and Solutions====&lt;br /&gt;
* '''Problem 1''': The method paginate_list is doing more than one thing.&lt;br /&gt;
::The method paginate_list was building a complex search criteria based on the input params, getting the list of versions from the Database matching this search criteria and then calling the Page API. All these tasks in a single method made it difficult to understand.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# For filtering the versions list with proper search and pagination.&lt;br /&gt;
  def paginate_list(id, user_id, item_type, event, datetime)&lt;br /&gt;
    # Set up the search criteria&lt;br /&gt;
    criteria = ''&lt;br /&gt;
    criteria = criteria + &amp;quot;id = #{id} AND &amp;quot; if id &amp;amp;&amp;amp; id.to_i &amp;gt; 0&lt;br /&gt;
    if current_user_role? == 'Super-Administrator'&lt;br /&gt;
      criteria = criteria + &amp;quot;whodunnit = #{user_id} AND &amp;quot; if user_id &amp;amp;&amp;amp; user_id.to_i &amp;gt; 0&lt;br /&gt;
    end&lt;br /&gt;
    criteria = criteria + &amp;quot;whodunnit = #{current_user.try(:id)} AND &amp;quot; if current_user.try(:id) &amp;amp;&amp;amp; current_user.try(:id).to_i &amp;gt; 0&lt;br /&gt;
    criteria = criteria + &amp;quot;item_type = '#{item_type}' AND &amp;quot; if item_type &amp;amp;&amp;amp; !(item_type.eql? 'Any')&lt;br /&gt;
    criteria = criteria + &amp;quot;event = '#{event}' AND &amp;quot; if event &amp;amp;&amp;amp; !(event.eql? 'Any')&lt;br /&gt;
    criteria = criteria + &amp;quot;created_at &amp;gt;= '#{time_to_string(params[:start_time])}' AND &amp;quot;&lt;br /&gt;
    criteria = criteria + &amp;quot;created_at &amp;lt;= '#{time_to_string(params[:end_time])}' AND &amp;quot;&lt;br /&gt;
&lt;br /&gt;
    if current_role == 'Instructor' || current_role == 'Administrator'&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # Remove the last ' AND '&lt;br /&gt;
    criteria = criteria[0..-5]&lt;br /&gt;
&lt;br /&gt;
    versions = Version.page(params[:page]).order('id').per_page(25).where(criteria)&lt;br /&gt;
    versions&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* '''Solution''': The implementation has been changed in such a way that the versions which a user is allowed to see depends on the privileges of the user. The approach we have taken is as follows:&lt;br /&gt;
**An administrator can see all the versions&lt;br /&gt;
**An instructor can see all the versions created by him and other users who are in his course or are participants in the assignments he creates.&lt;br /&gt;
**A TA can see all the versions created by him and other users who are in the course for which he/ she assists.&lt;br /&gt;
**A Student can see all the versions created by him/ her.&lt;br /&gt;
* '''Problem 2''': The search criteria created in the method paginate_list was difficult to comprehend.&lt;br /&gt;
::The code which builds the search criteria in the method paginate_list uses many string literals and conditions and is hardly intuitive. The programmer will have to spend some time to understand what the code is really doing.&lt;br /&gt;
* '''Solution''': The implementation has been changed. A student is not allowed to delete any versions now. Other types of users, for instance administrators, instructors and TAs are allowed to delete only the versions they are authorized to view.&lt;br /&gt;
* '''Problem 3''': The paginate method can be moved to a helper class.&lt;br /&gt;
::VersionsController is not the only component which require to paginate items. There are other components too. For instance, the UsersController has to paginate the list of users. Hence the Paginate method can be moved to a helper class which can be accessed by other components as well.&lt;br /&gt;
* '''Solution''': The filtering options has also been enhanced. The current user can now choose as part of the version search filter any user from a list of users if the current user is authorized to see the versions created by that user.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===New Implementation===&lt;br /&gt;
*The method paginate_list has been split into 2 methods now. &lt;br /&gt;
** BuildSearchCriteria – as the name suggests the sole purpose of this method is to build a search criteria based on the input search filters when the current user initiates a search in versions.&lt;br /&gt;
** paginate_list – this method will call the paginate API.&lt;br /&gt;
:First the search criteria is built, then the criteria is applied to versions in the database to get all versions which matches the criteria and then the retrieved versions are paginated.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # pagination.&lt;br /&gt;
  def paginate_list(versions)&lt;br /&gt;
    paginate(versions, VERSIONS_PER_PAGE);&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def BuildSearchCriteria(id, user_id, item_type, event)&lt;br /&gt;
    # Set up the search criteria&lt;br /&gt;
    search_criteria = ''&lt;br /&gt;
    search_criteria = search_criteria + add_id_filter_if_valid(id).to_s&lt;br /&gt;
    if current_user_role? == 'Super-Administrator'&lt;br /&gt;
      search_criteria = search_criteria + add_user_filter_for_super_admin(user_id).to_s&lt;br /&gt;
    end&lt;br /&gt;
    search_criteria = search_criteria + add_user_filter&lt;br /&gt;
    search_criteria = search_criteria + add_version_type_filter(item_type).to_s&lt;br /&gt;
    search_criteria = search_criteria + add_event_filter(event).to_s&lt;br /&gt;
    search_criteria = search_criteria + add_date_time_filter&lt;br /&gt;
    search_criteria&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The string literals and conditions in the method paginate_list were replaced with methods with intuitive names so that the programmer can understand the code more easily. We also removed an empty if clause and a redundant statement.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def add_id_filter_if_valid (id)&lt;br /&gt;
    &amp;quot;id = #{id} AND &amp;quot; if id &amp;amp;&amp;amp; id.to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_user_filter_for_super_admin (user_id)&lt;br /&gt;
    &amp;quot;whodunnit = #{user_id} AND &amp;quot; if user_id &amp;amp;&amp;amp; user_id.to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_user_filter&lt;br /&gt;
    &amp;quot;whodunnit = #{current_user.try(:id)} AND &amp;quot; if current_user.try(:id) &amp;amp;&amp;amp; current_user.try(:id).to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_event_filter (event)&lt;br /&gt;
    &amp;quot;event = '#{event}' AND &amp;quot; if event &amp;amp;&amp;amp; !(event.eql? 'Any')&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_date_time_filter&lt;br /&gt;
    &amp;quot;created_at &amp;gt;= '#{time_to_string(params[:start_time])}' AND &amp;quot; +&lt;br /&gt;
        &amp;quot;created_at &amp;lt;= '#{time_to_string(params[:end_time])}'&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_version_type_filter (version_type)&lt;br /&gt;
    &amp;quot;item_type = '#{version_type}' AND &amp;quot; if version_type &amp;amp;&amp;amp; !(version_type.eql? 'Any')&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The paginate method has been moved to the helper class Pagination_Helper. This new method can be now reused by the different components like UsersController etc. The method receives two parameters, first the list to paginate and second the number of items to be displayed in a page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module PaginationHelper&lt;br /&gt;
&lt;br /&gt;
  def paginate (items, number_of_items_per_page)&lt;br /&gt;
    items.page(params[:page]).per_page(number_of_items_per_page)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Code improvements===&lt;br /&gt;
* Introduced a constant VERSIONS_PER_PAGE and assigned the value 25 to it. The pagination algorithm for VersionsController displays at most 25 versions in a page. The existing implementation uses the value 25 straight in the code and there are few problems associated with such an approach.&lt;br /&gt;
** It is not easy to understand what 25 is unless the programmer takes a close look at the code.&lt;br /&gt;
** In case if the value 25 is used at more than one places and in future a new requirement comes to show at most 30 versions in a page, all the values will have to be modified. It is not very DRY.&lt;br /&gt;
* The VersionsController was overriding AccessHelper - action_allowed? method to return true in all the cases. This was violating the whole purpose of the method action_allowed?. The purpose of this method is to determine whether the user who is triggering a CRUD operation is allowed to do so. So when the current user invokes a CRUD operation, the action_allowed? method is invoked first and if the method returns true the CRUD operation is triggered or else the user is intimated with a message and gracefully exited. Hence, when the action_allowed? method is overridden to return true always, it results in providing unauthorized access to certain users.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def action_allowed?&lt;br /&gt;
    true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:With the new implementation the AccessHelper - action_allowed? method has been modified in such a way that unauthorized access is prevented. As per the new algorithm, 'new', 'create', 'edit', 'update' cannot be invoked by any user. These operations can be accessed only by ‘papertrail’ gem. Only an ‘Administrator’ or ‘Super-Administrator’ can call 'destroy_all' method. All the other methods are accessible to ‘Administrator’,  ‘Super-Administrator’, ‘Instructor’, ‘Teaching Assistant’ and ‘Student’.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    case params[:action]&lt;br /&gt;
    when 'new', 'create', 'edit', 'update'&lt;br /&gt;
    #Modifications can only be done by papertrail&lt;br /&gt;
      return false&lt;br /&gt;
    when 'destroy_all'&lt;br /&gt;
      ['Super-Administrator',&lt;br /&gt;
       'Administrator'].include? current_role_name&lt;br /&gt;
    else&lt;br /&gt;
      #Allow all others&lt;br /&gt;
      ['Super-Administrator',&lt;br /&gt;
       'Administrator',&lt;br /&gt;
       'Instructor',&lt;br /&gt;
       'Teaching Assistant',&lt;br /&gt;
       'Student'].include? current_role_name&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Automated Testing using Rspec===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/WintersLt/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[http://bit.ly/myexpertiza  Demo link] &lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;br /&gt;
#[https://relishapp.com/rspec Rspec Documentation]&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1553_AAJ&amp;diff=97449</id>
		<title>CSC/ECE 517 Fall 2015/oss E1553 AAJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1553_AAJ&amp;diff=97449"/>
		<updated>2015-10-31T04:40:39Z</updated>

		<summary type="html">&lt;p&gt;Asayal: /* Problem Statement */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1553. Refactoring the Versions Controller==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Introduction to Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a large project developed as a combined effort of students and faculty using the [http://rubyonrails.org/ Ruby on Rails] framework. The main advantage of using Expertiza, in an educational environment, is for the instructor to introduce peer reviewing among the students. Expertiza allows the instructor to create and customize assignments, create a list of topics the students can sign up for, have students work on teams and then review each other's assignments at the end. Expertiza supports submission of almost any document type, including the URLs and wiki pages. Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the [http://www.ncsu.edu/ NCSU] [http://litre.ncsu.edu/ Learning in a Technology-Rich Environment] (LITRE) program, the NCSU [http://ofd.ncsu.edu/teaching-learning/ Faculty Center for Teaching and Learning], the NCSU [http://stem.ncsu.edu/ STEM] Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
The following tasks were accomplished in this project:&lt;br /&gt;
&lt;br /&gt;
* Improved the clarity of code by improving the variable and parameter names.&lt;br /&gt;
* Long character strings were taken and given appropriate names.&lt;br /&gt;
* Handled pagination by a separate helper module, which can be used by multiple controllers.&lt;br /&gt;
* Implemented action_allowed for access_control  to prevent unauthorized access of methods.&lt;br /&gt;
* Prevented displaying of all versions for all users and tables when a user views the index page.&lt;br /&gt;
* Added missing CRUD methods to Versions Controller&lt;br /&gt;
* Added RSPEC testcases for testing changes done in Versions Controller&lt;br /&gt;
&lt;br /&gt;
===About Versions Controller===&lt;br /&gt;
This class manages different versions of reviews.  If a reviewer reviews a submission, and after that, the author revises the submission, the next time the reviewer does a review (s)he will create a new version.  Sometimes it’s necessary to find the current version of a review; sometimes it’s necessary to find all versions.  Similarly, a user may want to delete the current version of a review, or all versions of a review.&lt;br /&gt;
Pagination of versions helps the user to view a subset of versions at a time. Considering the huge number of versions in the system, it is very useful to have a pagination mechanism and a filtering mechanism which can be applied on the whole set of versions. The idea is to display the versions in an ordered, comprehensible and logical manner. In Expertiza the gem ‘will_paginate’ is used to achieve pagination.&lt;br /&gt;
&lt;br /&gt;
===Current Implementation===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Functionality====&lt;br /&gt;
* Any user irrespective of his/ her privileges can view all the versions.&lt;br /&gt;
::The versions which a particular user can view should be restricted based on the privileges of the user. For instance, only a user with Administrator privileges should be able to view all the versions in the system. However, that is not the case now. Every user can view all the versions irrespective of whether the user is a student or an administrator.&lt;br /&gt;
* Any user can delete any version&lt;br /&gt;
::The versions which a particular user can delete should be restricted based on the privileges of the user. For instance, a student should not be allowed to delete any version. According to the current implementation any user can delete any version in the system.&lt;br /&gt;
* Filtering of versions were restricted to the current user&lt;br /&gt;
::The filtering options on versions were restricted to the current user. Sometimes a user might want to view versions associated with other users. For instance, an instructor might want to view the list of versions created by a particular student. This is not possible with the current implementation.&lt;br /&gt;
&lt;br /&gt;
====Drawbacks and Solutions====&lt;br /&gt;
* '''Problem 1''': The method paginate_list is doing more than one thing.&lt;br /&gt;
::The method paginate_list was building a complex search criteria based on the input params, getting the list of versions from the Database matching this search criteria and then calling the Page API. All these tasks in a single method made it difficult to understand.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# For filtering the versions list with proper search and pagination.&lt;br /&gt;
  def paginate_list(id, user_id, item_type, event, datetime)&lt;br /&gt;
    # Set up the search criteria&lt;br /&gt;
    criteria = ''&lt;br /&gt;
    criteria = criteria + &amp;quot;id = #{id} AND &amp;quot; if id &amp;amp;&amp;amp; id.to_i &amp;gt; 0&lt;br /&gt;
    if current_user_role? == 'Super-Administrator'&lt;br /&gt;
      criteria = criteria + &amp;quot;whodunnit = #{user_id} AND &amp;quot; if user_id &amp;amp;&amp;amp; user_id.to_i &amp;gt; 0&lt;br /&gt;
    end&lt;br /&gt;
    criteria = criteria + &amp;quot;whodunnit = #{current_user.try(:id)} AND &amp;quot; if current_user.try(:id) &amp;amp;&amp;amp; current_user.try(:id).to_i &amp;gt; 0&lt;br /&gt;
    criteria = criteria + &amp;quot;item_type = '#{item_type}' AND &amp;quot; if item_type &amp;amp;&amp;amp; !(item_type.eql? 'Any')&lt;br /&gt;
    criteria = criteria + &amp;quot;event = '#{event}' AND &amp;quot; if event &amp;amp;&amp;amp; !(event.eql? 'Any')&lt;br /&gt;
    criteria = criteria + &amp;quot;created_at &amp;gt;= '#{time_to_string(params[:start_time])}' AND &amp;quot;&lt;br /&gt;
    criteria = criteria + &amp;quot;created_at &amp;lt;= '#{time_to_string(params[:end_time])}' AND &amp;quot;&lt;br /&gt;
&lt;br /&gt;
    if current_role == 'Instructor' || current_role == 'Administrator'&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # Remove the last ' AND '&lt;br /&gt;
    criteria = criteria[0..-5]&lt;br /&gt;
&lt;br /&gt;
    versions = Version.page(params[:page]).order('id').per_page(25).where(criteria)&lt;br /&gt;
    versions&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* '''Solution''': The implementation has been changed in such a way that the versions which a user is allowed to see depends on the privileges of the user. The approach we have taken is as follows:&lt;br /&gt;
**An administrator can see all the versions&lt;br /&gt;
**An instructor can see all the versions created by him and other users who are in his course or are participants in the assignments he creates.&lt;br /&gt;
**A TA can see all the versions created by him and other users who are in the course for which he/ she assists.&lt;br /&gt;
**A Student can see all the versions created by him/ her.&lt;br /&gt;
* '''Problem 2''': The search criteria created in the method paginate_list was difficult to comprehend.&lt;br /&gt;
::The code which builds the search criteria in the method paginate_list uses many string literals and conditions and is hardly intuitive. The programmer will have to spend some time to understand what the code is really doing.&lt;br /&gt;
* '''Solution''': The implementation has been changed. A student is not allowed to delete any versions now. Other types of users, for instance administrators, instructors and TAs are allowed to delete only the versions they are authorized to view.&lt;br /&gt;
* '''Problem 3''': The paginate method can be moved to a helper class.&lt;br /&gt;
::VersionsController is not the only component which require to paginate items. There are other components too. For instance, the UsersController has to paginate the list of users. Hence the Paginate method can be moved to a helper class which can be accessed by other components as well.&lt;br /&gt;
* '''Solution''': The filtering options has also been enhanced. The current user can now choose as part of the version search filter any user from a list of users if the current user is authorized to see the versions created by that user.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===New Implementation===&lt;br /&gt;
*The method paginate_list has been split into 2 methods now. &lt;br /&gt;
** BuildSearchCriteria – as the name suggests the sole purpose of this method is to build a search criteria based on the input search filters when the current user initiates a search in versions.&lt;br /&gt;
** paginate_list – this method will call the paginate API.&lt;br /&gt;
:First the search criteria is built, then the criteria is applied to versions in the database to get all versions which matches the criteria and then the retrieved versions are paginated.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # pagination.&lt;br /&gt;
  def paginate_list(versions)&lt;br /&gt;
    paginate(versions, VERSIONS_PER_PAGE);&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def BuildSearchCriteria(id, user_id, item_type, event)&lt;br /&gt;
    # Set up the search criteria&lt;br /&gt;
    search_criteria = ''&lt;br /&gt;
    search_criteria = search_criteria + add_id_filter_if_valid(id).to_s&lt;br /&gt;
    if current_user_role? == 'Super-Administrator'&lt;br /&gt;
      search_criteria = search_criteria + add_user_filter_for_super_admin(user_id).to_s&lt;br /&gt;
    end&lt;br /&gt;
    search_criteria = search_criteria + add_user_filter&lt;br /&gt;
    search_criteria = search_criteria + add_version_type_filter(item_type).to_s&lt;br /&gt;
    search_criteria = search_criteria + add_event_filter(event).to_s&lt;br /&gt;
    search_criteria = search_criteria + add_date_time_filter&lt;br /&gt;
    search_criteria&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The string literals and conditions in the method paginate_list were replaced with methods with intuitive names so that the programmer can understand the code more easily. We also removed an empty if clause and a redundant statement.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def add_id_filter_if_valid (id)&lt;br /&gt;
    &amp;quot;id = #{id} AND &amp;quot; if id &amp;amp;&amp;amp; id.to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_user_filter_for_super_admin (user_id)&lt;br /&gt;
    &amp;quot;whodunnit = #{user_id} AND &amp;quot; if user_id &amp;amp;&amp;amp; user_id.to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_user_filter&lt;br /&gt;
    &amp;quot;whodunnit = #{current_user.try(:id)} AND &amp;quot; if current_user.try(:id) &amp;amp;&amp;amp; current_user.try(:id).to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_event_filter (event)&lt;br /&gt;
    &amp;quot;event = '#{event}' AND &amp;quot; if event &amp;amp;&amp;amp; !(event.eql? 'Any')&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_date_time_filter&lt;br /&gt;
    &amp;quot;created_at &amp;gt;= '#{time_to_string(params[:start_time])}' AND &amp;quot; +&lt;br /&gt;
        &amp;quot;created_at &amp;lt;= '#{time_to_string(params[:end_time])}'&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_version_type_filter (version_type)&lt;br /&gt;
    &amp;quot;item_type = '#{version_type}' AND &amp;quot; if version_type &amp;amp;&amp;amp; !(version_type.eql? 'Any')&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The paginate method has been moved to the helper class Pagination_Helper. This new method can be now reused by the different components like UsersController etc. The method receives two parameters, first the list to paginate and second the number of items to be displayed in a page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module PaginationHelper&lt;br /&gt;
&lt;br /&gt;
  def paginate (items, number_of_items_per_page)&lt;br /&gt;
    items.page(params[:page]).per_page(number_of_items_per_page)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Code improvements===&lt;br /&gt;
* Introduced a constant VERSIONS_PER_PAGE and assigned the value 25 to it. The pagination algorithm for VersionsController displays at most 25 versions in a page. The existing implementation uses the value 25 straight in the code and there are few problems associated with such an approach.&lt;br /&gt;
** It is not easy to understand what 25 is unless the programmer takes a close look at the code.&lt;br /&gt;
** In case if the value 25 is used at more than one places and in future a new requirement comes to show at most 30 versions in a page, all the values will have to be modified. It is not very DRY.&lt;br /&gt;
* The VersionsController was overriding AccessHelper - action_allowed? method to return true in all the cases. This was violating the whole purpose of the method action_allowed?. The purpose of this method is to determine whether the user who is triggering a CRUD operation is allowed to do so. So when the current user invokes a CRUD operation, the action_allowed? method is invoked first and if the method returns true the CRUD operation is triggered or else the user is intimated with a message and gracefully exited. Hence, when the action_allowed? method is overridden to return true always, it results in providing unauthorized access to certain users.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def action_allowed?&lt;br /&gt;
    true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:With the new implementation the AccessHelper - action_allowed? method has been modified in such a way that unauthorized access is prevented. As per the new algorithm, 'new', 'create', 'edit', 'update' cannot be invoked by any user. These operations can be accessed only by ‘papertrail’ gem. Only an ‘Administrator’ or ‘Super-Administrator’ can call 'destroy_all' method. All the other methods are accessible to ‘Administrator’,  ‘Super-Administrator’, ‘Instructor’, ‘Teaching Assistant’ and ‘Student’.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    case params[:action]&lt;br /&gt;
    when 'new', 'create', 'edit', 'update'&lt;br /&gt;
    #Modifications can only be done by papertrail&lt;br /&gt;
      return false&lt;br /&gt;
    when 'destroy_all'&lt;br /&gt;
      ['Super-Administrator',&lt;br /&gt;
       'Administrator'].include? current_role_name&lt;br /&gt;
    else&lt;br /&gt;
      #Allow all others&lt;br /&gt;
      ['Super-Administrator',&lt;br /&gt;
       'Administrator',&lt;br /&gt;
       'Instructor',&lt;br /&gt;
       'Teaching Assistant',&lt;br /&gt;
       'Student'].include? current_role_name&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Automated Testing using Rspec===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/WintersLt/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[http://bit.ly/myexpertiza  Demo link] &lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;br /&gt;
#[https://relishapp.com/rspec Rspec Documentation]&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1553_AAJ&amp;diff=97446</id>
		<title>CSC/ECE 517 Fall 2015/oss E1553 AAJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1553_AAJ&amp;diff=97446"/>
		<updated>2015-10-31T04:28:36Z</updated>

		<summary type="html">&lt;p&gt;Asayal: /* About Versions Controller */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1553. Refactoring the Versions Controller==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Introduction to Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a large project developed as a combined effort of students and faculty using the [http://rubyonrails.org/ Ruby on Rails] framework. The main advantage of using Expertiza, in an educational environment, is for the instructor to introduce peer reviewing among the students. Expertiza allows the instructor to create and customize assignments, create a list of topics the students can sign up for, have students work on teams and then review each other's assignments at the end. Expertiza supports submission of almost any document type, including the URLs and wiki pages. Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the [http://www.ncsu.edu/ NCSU] [http://litre.ncsu.edu/ Learning in a Technology-Rich Environment] (LITRE) program, the NCSU [http://ofd.ncsu.edu/teaching-learning/ Faculty Center for Teaching and Learning], the NCSU [http://stem.ncsu.edu/ STEM] Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===About Versions Controller===&lt;br /&gt;
This class manages different versions of reviews.  If a reviewer reviews a submission, and after that, the author revises the submission, the next time the reviewer does a review (s)he will create a new version.  Sometimes it’s necessary to find the current version of a review; sometimes it’s necessary to find all versions.  Similarly, a user may want to delete the current version of a review, or all versions of a review.&lt;br /&gt;
Pagination of versions helps the user to view a subset of versions at a time. Considering the huge number of versions in the system, it is very useful to have a pagination mechanism and a filtering mechanism which can be applied on the whole set of versions. The idea is to display the versions in an ordered, comprehensible and logical manner. In Expertiza the gem ‘will_paginate’ is used to achieve pagination.&lt;br /&gt;
&lt;br /&gt;
===Current Implementation===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Functionality====&lt;br /&gt;
* Any user irrespective of his/ her privileges can view all the versions.&lt;br /&gt;
::The versions which a particular user can view should be restricted based on the privileges of the user. For instance, only a user with Administrator privileges should be able to view all the versions in the system. However, that is not the case now. Every user can view all the versions irrespective of whether the user is a student or an administrator.&lt;br /&gt;
* Any user can delete any version&lt;br /&gt;
::The versions which a particular user can delete should be restricted based on the privileges of the user. For instance, a student should not be allowed to delete any version. According to the current implementation any user can delete any version in the system.&lt;br /&gt;
* Filtering of versions were restricted to the current user&lt;br /&gt;
::The filtering options on versions were restricted to the current user. Sometimes a user might want to view versions associated with other users. For instance, an instructor might want to view the list of versions created by a particular student. This is not possible with the current implementation.&lt;br /&gt;
&lt;br /&gt;
====Drawbacks and Solutions====&lt;br /&gt;
* '''Problem 1''': The method paginate_list is doing more than one thing.&lt;br /&gt;
::The method paginate_list was building a complex search criteria based on the input params, getting the list of versions from the Database matching this search criteria and then calling the Page API. All these tasks in a single method made it difficult to understand.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# For filtering the versions list with proper search and pagination.&lt;br /&gt;
  def paginate_list(id, user_id, item_type, event, datetime)&lt;br /&gt;
    # Set up the search criteria&lt;br /&gt;
    criteria = ''&lt;br /&gt;
    criteria = criteria + &amp;quot;id = #{id} AND &amp;quot; if id &amp;amp;&amp;amp; id.to_i &amp;gt; 0&lt;br /&gt;
    if current_user_role? == 'Super-Administrator'&lt;br /&gt;
      criteria = criteria + &amp;quot;whodunnit = #{user_id} AND &amp;quot; if user_id &amp;amp;&amp;amp; user_id.to_i &amp;gt; 0&lt;br /&gt;
    end&lt;br /&gt;
    criteria = criteria + &amp;quot;whodunnit = #{current_user.try(:id)} AND &amp;quot; if current_user.try(:id) &amp;amp;&amp;amp; current_user.try(:id).to_i &amp;gt; 0&lt;br /&gt;
    criteria = criteria + &amp;quot;item_type = '#{item_type}' AND &amp;quot; if item_type &amp;amp;&amp;amp; !(item_type.eql? 'Any')&lt;br /&gt;
    criteria = criteria + &amp;quot;event = '#{event}' AND &amp;quot; if event &amp;amp;&amp;amp; !(event.eql? 'Any')&lt;br /&gt;
    criteria = criteria + &amp;quot;created_at &amp;gt;= '#{time_to_string(params[:start_time])}' AND &amp;quot;&lt;br /&gt;
    criteria = criteria + &amp;quot;created_at &amp;lt;= '#{time_to_string(params[:end_time])}' AND &amp;quot;&lt;br /&gt;
&lt;br /&gt;
    if current_role == 'Instructor' || current_role == 'Administrator'&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # Remove the last ' AND '&lt;br /&gt;
    criteria = criteria[0..-5]&lt;br /&gt;
&lt;br /&gt;
    versions = Version.page(params[:page]).order('id').per_page(25).where(criteria)&lt;br /&gt;
    versions&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* '''Solution''': The implementation has been changed in such a way that the versions which a user is allowed to see depends on the privileges of the user. The approach we have taken is as follows:&lt;br /&gt;
**An administrator can see all the versions&lt;br /&gt;
**An instructor can see all the versions created by him and other users who are in his course or are participants in the assignments he creates.&lt;br /&gt;
**A TA can see all the versions created by him and other users who are in the course for which he/ she assists.&lt;br /&gt;
**A Student can see all the versions created by him/ her.&lt;br /&gt;
* '''Problem 2''': The search criteria created in the method paginate_list was difficult to comprehend.&lt;br /&gt;
::The code which builds the search criteria in the method paginate_list uses many string literals and conditions and is hardly intuitive. The programmer will have to spend some time to understand what the code is really doing.&lt;br /&gt;
* '''Solution''': The implementation has been changed. A student is not allowed to delete any versions now. Other types of users, for instance administrators, instructors and TAs are allowed to delete only the versions they are authorized to view.&lt;br /&gt;
* '''Problem 3''': The paginate method can be moved to a helper class.&lt;br /&gt;
::VersionsController is not the only component which require to paginate items. There are other components too. For instance, the UsersController has to paginate the list of users. Hence the Paginate method can be moved to a helper class which can be accessed by other components as well.&lt;br /&gt;
* '''Solution''': The filtering options has also been enhanced. The current user can now choose as part of the version search filter any user from a list of users if the current user is authorized to see the versions created by that user.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===New Implementation===&lt;br /&gt;
*The method paginate_list has been split into 2 methods now. &lt;br /&gt;
** BuildSearchCriteria – as the name suggests the sole purpose of this method is to build a search criteria based on the input search filters when the current user initiates a search in versions.&lt;br /&gt;
** paginate_list – this method will call the paginate API.&lt;br /&gt;
:First the search criteria is built, then the criteria is applied to versions in the database to get all versions which matches the criteria and then the retrieved versions are paginated.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # pagination.&lt;br /&gt;
  def paginate_list(versions)&lt;br /&gt;
    paginate(versions, VERSIONS_PER_PAGE);&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def BuildSearchCriteria(id, user_id, item_type, event)&lt;br /&gt;
    # Set up the search criteria&lt;br /&gt;
    search_criteria = ''&lt;br /&gt;
    search_criteria = search_criteria + add_id_filter_if_valid(id).to_s&lt;br /&gt;
    if current_user_role? == 'Super-Administrator'&lt;br /&gt;
      search_criteria = search_criteria + add_user_filter_for_super_admin(user_id).to_s&lt;br /&gt;
    end&lt;br /&gt;
    search_criteria = search_criteria + add_user_filter&lt;br /&gt;
    search_criteria = search_criteria + add_version_type_filter(item_type).to_s&lt;br /&gt;
    search_criteria = search_criteria + add_event_filter(event).to_s&lt;br /&gt;
    search_criteria = search_criteria + add_date_time_filter&lt;br /&gt;
    search_criteria&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The string literals and conditions in the method paginate_list were replaced with methods with intuitive names so that the programmer can understand the code more easily. We also removed an empty if clause and a redundant statement.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def add_id_filter_if_valid (id)&lt;br /&gt;
    &amp;quot;id = #{id} AND &amp;quot; if id &amp;amp;&amp;amp; id.to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_user_filter_for_super_admin (user_id)&lt;br /&gt;
    &amp;quot;whodunnit = #{user_id} AND &amp;quot; if user_id &amp;amp;&amp;amp; user_id.to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_user_filter&lt;br /&gt;
    &amp;quot;whodunnit = #{current_user.try(:id)} AND &amp;quot; if current_user.try(:id) &amp;amp;&amp;amp; current_user.try(:id).to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_event_filter (event)&lt;br /&gt;
    &amp;quot;event = '#{event}' AND &amp;quot; if event &amp;amp;&amp;amp; !(event.eql? 'Any')&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_date_time_filter&lt;br /&gt;
    &amp;quot;created_at &amp;gt;= '#{time_to_string(params[:start_time])}' AND &amp;quot; +&lt;br /&gt;
        &amp;quot;created_at &amp;lt;= '#{time_to_string(params[:end_time])}'&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_version_type_filter (version_type)&lt;br /&gt;
    &amp;quot;item_type = '#{version_type}' AND &amp;quot; if version_type &amp;amp;&amp;amp; !(version_type.eql? 'Any')&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The paginate method has been moved to the helper class Pagination_Helper. This new method can be now reused by the different components like UsersController etc. The method receives two parameters, first the list to paginate and second the number of items to be displayed in a page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module PaginationHelper&lt;br /&gt;
&lt;br /&gt;
  def paginate (items, number_of_items_per_page)&lt;br /&gt;
    items.page(params[:page]).per_page(number_of_items_per_page)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Code improvements===&lt;br /&gt;
* Introduced a constant VERSIONS_PER_PAGE and assigned the value 25 to it. The pagination algorithm for VersionsController displays at most 25 versions in a page. The existing implementation uses the value 25 straight in the code and there are few problems associated with such an approach.&lt;br /&gt;
** It is not easy to understand what 25 is unless the programmer takes a close look at the code.&lt;br /&gt;
** In case if the value 25 is used at more than one places and in future a new requirement comes to show at most 30 versions in a page, all the values will have to be modified. It is not very DRY.&lt;br /&gt;
* The VersionsController was overriding AccessHelper - action_allowed? method to return true in all the cases. This was violating the whole purpose of the method action_allowed?. The purpose of this method is to determine whether the user who is triggering a CRUD operation is allowed to do so. So when the current user invokes a CRUD operation, the action_allowed? method is invoked first and if the method returns true the CRUD operation is triggered or else the user is intimated with a message and gracefully exited. Hence, when the action_allowed? method is overridden to return true always, it results in providing unauthorized access to certain users.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def action_allowed?&lt;br /&gt;
    true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:With the new implementation the AccessHelper - action_allowed? method has been modified in such a way that unauthorized access is prevented. As per the new algorithm, 'new', 'create', 'edit', 'update' cannot be invoked by any user. These operations can be accessed only by ‘papertrail’ gem. Only an ‘Administrator’ or ‘Super-Administrator’ can call 'destroy_all' method. All the other methods are accessible to ‘Administrator’,  ‘Super-Administrator’, ‘Instructor’, ‘Teaching Assistant’ and ‘Student’.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    case params[:action]&lt;br /&gt;
    when 'new', 'create', 'edit', 'update'&lt;br /&gt;
    #Modifications can only be done by papertrail&lt;br /&gt;
      return false&lt;br /&gt;
    when 'destroy_all'&lt;br /&gt;
      ['Super-Administrator',&lt;br /&gt;
       'Administrator'].include? current_role_name&lt;br /&gt;
    else&lt;br /&gt;
      #Allow all others&lt;br /&gt;
      ['Super-Administrator',&lt;br /&gt;
       'Administrator',&lt;br /&gt;
       'Instructor',&lt;br /&gt;
       'Teaching Assistant',&lt;br /&gt;
       'Student'].include? current_role_name&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Automated Testing using Rspec===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/WintersLt/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[http://bit.ly/myexpertiza  Demo link] &lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;br /&gt;
#[https://relishapp.com/rspec Rspec Documentation]&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1553_AAJ&amp;diff=97430</id>
		<title>CSC/ECE 517 Fall 2015/oss E1553 AAJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1553_AAJ&amp;diff=97430"/>
		<updated>2015-10-31T02:40:45Z</updated>

		<summary type="html">&lt;p&gt;Asayal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1553. Refactoring the Versions Controller==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Introduction to Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a large project developed as a combined effort of students and faculty using the [http://rubyonrails.org/ Ruby on Rails] framework. The main advantage of using Expertiza, in an educational environment, is for the instructor to introduce peer reviewing among the students. Expertiza allows the instructor to create and customize assignments, create a list of topics the students can sign up for, have students work on teams and then review each other's assignments at the end. Expertiza supports submission of almost any document type, including the URLs and wiki pages. Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the [http://www.ncsu.edu/ NCSU] [http://litre.ncsu.edu/ Learning in a Technology-Rich Environment] (LITRE) program, the NCSU [http://ofd.ncsu.edu/teaching-learning/ Faculty Center for Teaching and Learning], the NCSU [http://stem.ncsu.edu/ STEM] Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===About Versions Controller===&lt;br /&gt;
Pagination of versions helps the user to view a subset of versions at a time. Considering the huge number of versions in the system, it is very useful to have a pagination mechanism and a filtering mechanism which can be applied on the whole set of versions. The idea is to display the versions in an ordered, comprehensible and logical manner. In Expertiza the gem ‘will_paginate’ is used to achieve pagination.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Current Implementation===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Functionality====&lt;br /&gt;
* Any user irrespective of his/ her privileges can view all the versions.&lt;br /&gt;
::The versions which a particular user can view should be restricted based on the privileges of the user. For instance, only a user with Administrator privileges should be able to view all the versions in the system. However, that is not the case now. Every user can view all the versions irrespective of whether the user is a student or an administrator.&lt;br /&gt;
* Any user can delete any version&lt;br /&gt;
::The versions which a particular user can delete should be restricted based on the privileges of the user. For instance, a student should not be allowed to delete any version. According to the current implementation any user can delete any version in the system.&lt;br /&gt;
* Filtering of versions were restricted to the current user&lt;br /&gt;
::The filtering options on versions were restricted to the current user. Sometimes a user might want to view versions associated with other users. For instance, an instructor might want to view the list of versions created by a particular student. This is not possible with the current implementation.&lt;br /&gt;
&lt;br /&gt;
====Drawbacks and Solutions====&lt;br /&gt;
* '''Problem 1''': The method paginate_list is doing more than one thing.&lt;br /&gt;
::The method paginate_list was building a complex search criteria based on the input params, getting the list of versions from the Database matching this search criteria and then calling the Page API. All these tasks in a single method made it difficult to understand.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# For filtering the versions list with proper search and pagination.&lt;br /&gt;
  def paginate_list(id, user_id, item_type, event, datetime)&lt;br /&gt;
    # Set up the search criteria&lt;br /&gt;
    criteria = ''&lt;br /&gt;
    criteria = criteria + &amp;quot;id = #{id} AND &amp;quot; if id &amp;amp;&amp;amp; id.to_i &amp;gt; 0&lt;br /&gt;
    if current_user_role? == 'Super-Administrator'&lt;br /&gt;
      criteria = criteria + &amp;quot;whodunnit = #{user_id} AND &amp;quot; if user_id &amp;amp;&amp;amp; user_id.to_i &amp;gt; 0&lt;br /&gt;
    end&lt;br /&gt;
    criteria = criteria + &amp;quot;whodunnit = #{current_user.try(:id)} AND &amp;quot; if current_user.try(:id) &amp;amp;&amp;amp; current_user.try(:id).to_i &amp;gt; 0&lt;br /&gt;
    criteria = criteria + &amp;quot;item_type = '#{item_type}' AND &amp;quot; if item_type &amp;amp;&amp;amp; !(item_type.eql? 'Any')&lt;br /&gt;
    criteria = criteria + &amp;quot;event = '#{event}' AND &amp;quot; if event &amp;amp;&amp;amp; !(event.eql? 'Any')&lt;br /&gt;
    criteria = criteria + &amp;quot;created_at &amp;gt;= '#{time_to_string(params[:start_time])}' AND &amp;quot;&lt;br /&gt;
    criteria = criteria + &amp;quot;created_at &amp;lt;= '#{time_to_string(params[:end_time])}' AND &amp;quot;&lt;br /&gt;
&lt;br /&gt;
    if current_role == 'Instructor' || current_role == 'Administrator'&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # Remove the last ' AND '&lt;br /&gt;
    criteria = criteria[0..-5]&lt;br /&gt;
&lt;br /&gt;
    versions = Version.page(params[:page]).order('id').per_page(25).where(criteria)&lt;br /&gt;
    versions&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* '''Solution''': The implementation has been changed in such a way that the versions which a user is allowed to see depends on the privileges of the user. The approach we have taken is as follows:&lt;br /&gt;
**An administrator can see all the versions&lt;br /&gt;
**An instructor can see all the versions created by him and other users who are in his course or are participants in the assignments he creates.&lt;br /&gt;
**A TA can see all the versions created by him and other users who are in the course for which he/ she assists.&lt;br /&gt;
**A Student can see all the versions created by him/ her.&lt;br /&gt;
* '''Problem 2''': The search criteria created in the method paginate_list was difficult to comprehend.&lt;br /&gt;
::The code which builds the search criteria in the method paginate_list uses many string literals and conditions and is hardly intuitive. The programmer will have to spend some time to understand what the code is really doing.&lt;br /&gt;
* '''Solution''': The implementation has been changed. A student is not allowed to delete any versions now. Other types of users, for instance administrators, instructors and TAs are allowed to delete only the versions they are authorized to view.&lt;br /&gt;
* '''Problem 3''': The paginate method can be moved to a helper class.&lt;br /&gt;
::VersionsController is not the only component which require to paginate items. There are other components too. For instance, the UsersController has to paginate the list of users. Hence the Paginate method can be moved to a helper class which can be accessed by other components as well.&lt;br /&gt;
* '''Solution''': The filtering options has also been enhanced. The current user can now choose as part of the version search filter any user from a list of users if the current user is authorized to see the versions created by that user.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===New Implementation===&lt;br /&gt;
*The method paginate_list has been split into 2 methods now. &lt;br /&gt;
** BuildSearchCriteria – as the name suggests the sole purpose of this method is to build a search criteria based on the input search filters when the current user initiates a search in versions.&lt;br /&gt;
** paginate_list – this method will call the paginate API.&lt;br /&gt;
:First the search criteria is built, then the criteria is applied to versions in the database to get all versions which matches the criteria and then the retrieved versions are paginated.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # pagination.&lt;br /&gt;
  def paginate_list(versions)&lt;br /&gt;
    paginate(versions, VERSIONS_PER_PAGE);&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def BuildSearchCriteria(id, user_id, item_type, event)&lt;br /&gt;
    # Set up the search criteria&lt;br /&gt;
    search_criteria = ''&lt;br /&gt;
    search_criteria = search_criteria + add_id_filter_if_valid(id).to_s&lt;br /&gt;
    if current_user_role? == 'Super-Administrator'&lt;br /&gt;
      search_criteria = search_criteria + add_user_filter_for_super_admin(user_id).to_s&lt;br /&gt;
    end&lt;br /&gt;
    search_criteria = search_criteria + add_user_filter&lt;br /&gt;
    search_criteria = search_criteria + add_version_type_filter(item_type).to_s&lt;br /&gt;
    search_criteria = search_criteria + add_event_filter(event).to_s&lt;br /&gt;
    search_criteria = search_criteria + add_date_time_filter&lt;br /&gt;
    search_criteria&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The string literals and conditions in the method paginate_list were replaced with methods with intuitive names so that the programmer can understand the code more easily. We also removed an empty if clause and a redundant statement.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def add_id_filter_if_valid (id)&lt;br /&gt;
    &amp;quot;id = #{id} AND &amp;quot; if id &amp;amp;&amp;amp; id.to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_user_filter_for_super_admin (user_id)&lt;br /&gt;
    &amp;quot;whodunnit = #{user_id} AND &amp;quot; if user_id &amp;amp;&amp;amp; user_id.to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_user_filter&lt;br /&gt;
    &amp;quot;whodunnit = #{current_user.try(:id)} AND &amp;quot; if current_user.try(:id) &amp;amp;&amp;amp; current_user.try(:id).to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_event_filter (event)&lt;br /&gt;
    &amp;quot;event = '#{event}' AND &amp;quot; if event &amp;amp;&amp;amp; !(event.eql? 'Any')&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_date_time_filter&lt;br /&gt;
    &amp;quot;created_at &amp;gt;= '#{time_to_string(params[:start_time])}' AND &amp;quot; +&lt;br /&gt;
        &amp;quot;created_at &amp;lt;= '#{time_to_string(params[:end_time])}'&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_version_type_filter (version_type)&lt;br /&gt;
    &amp;quot;item_type = '#{version_type}' AND &amp;quot; if version_type &amp;amp;&amp;amp; !(version_type.eql? 'Any')&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The paginate method has been moved to the helper class Pagination_Helper. This new method can be now reused by the different components like UsersController etc. The method receives two parameters, first the list to paginate and second the number of items to be displayed in a page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module PaginationHelper&lt;br /&gt;
&lt;br /&gt;
  def paginate (items, number_of_items_per_page)&lt;br /&gt;
    items.page(params[:page]).per_page(number_of_items_per_page)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Code improvements===&lt;br /&gt;
* Introduced a constant VERSIONS_PER_PAGE and assigned the value 25 to it. The pagination algorithm for VersionsController displays at most 25 versions in a page. The existing implementation uses the value 25 straight in the code and there are few problems associated with such an approach.&lt;br /&gt;
** It is not easy to understand what 25 is unless the programmer takes a close look at the code.&lt;br /&gt;
** In case if the value 25 is used at more than one places and in future a new requirement comes to show at most 30 versions in a page, all the values will have to be modified. It is not very DRY.&lt;br /&gt;
* The VersionsController was overriding AccessHelper - action_allowed? method to return true in all the cases. This was violating the whole purpose of the method action_allowed?. The purpose of this method is to determine whether the user who is triggering a CRUD operation is allowed to do so. So when the current user invokes a CRUD operation, the action_allowed? method is invoked first and if the method returns true the CRUD operation is triggered or else the user is intimated with a message and gracefully exited. Hence, when the action_allowed? method is overridden to return true always, it results in providing unauthorized access to certain users.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def action_allowed?&lt;br /&gt;
    true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:With the new implementation the AccessHelper - action_allowed? method has been modified in such a way that unauthorized access is prevented. As per the new algorithm, 'new', 'create', 'edit', 'update' cannot be invoked by any user. These operations can be accessed only by ‘papertrail’ gem. Only an ‘Administrator’ or ‘Super-Administrator’ can call 'destroy_all' method. All the other methods are accessible to ‘Administrator’,  ‘Super-Administrator’, ‘Instructor’, ‘Teaching Assistant’ and ‘Student’.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    case params[:action]&lt;br /&gt;
    when 'new', 'create', 'edit', 'update'&lt;br /&gt;
    #Modifications can only be done by papertrail&lt;br /&gt;
      return false&lt;br /&gt;
    when 'destroy_all'&lt;br /&gt;
      ['Super-Administrator',&lt;br /&gt;
       'Administrator'].include? current_role_name&lt;br /&gt;
    else&lt;br /&gt;
      #Allow all others&lt;br /&gt;
      ['Super-Administrator',&lt;br /&gt;
       'Administrator',&lt;br /&gt;
       'Instructor',&lt;br /&gt;
       'Teaching Assistant',&lt;br /&gt;
       'Student'].include? current_role_name&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Automated Testing using Rspec===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/WintersLt/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[http://bit.ly/myexpertiza  Demo link] &lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;br /&gt;
#[https://relishapp.com/rspec Rspec Documentation]&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1553_AAJ&amp;diff=97429</id>
		<title>CSC/ECE 517 Fall 2015/oss E1553 AAJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1553_AAJ&amp;diff=97429"/>
		<updated>2015-10-31T02:39:35Z</updated>

		<summary type="html">&lt;p&gt;Asayal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1553. Refactoring the Versions Controller==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Introduction to Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a large project developed as a combined effort of students and faculty using the [http://rubyonrails.org/ Ruby on Rails] framework. The main advantage of using Expertiza, in an educational environment, is for the instructor to introduce peer reviewing among the students. Expertiza allows the instructor to create and customize assignments, create a list of topics the students can sign up for, have students work on teams and then review each other's assignments at the end. Expertiza supports submission of almost any document type, including the URLs and wiki pages. Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the [http://www.ncsu.edu/ NCSU] [http://litre.ncsu.edu/ Learning in a Technology-Rich Environment] (LITRE) program, the NCSU [http://ofd.ncsu.edu/teaching-learning/ Faculty Center for Teaching and Learning], the NCSU [http://stem.ncsu.edu/ STEM] Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
===About Versions Controller===&lt;br /&gt;
Pagination of versions helps the user to view a subset of versions at a time. Considering the huge number of versions in the system, it is very useful to have a pagination mechanism and a filtering mechanism which can be applied on the whole set of versions. The idea is to display the versions in an ordered, comprehensible and logical manner. In Expertiza the gem ‘will_paginate’ is used to achieve pagination.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Current Implementation===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Functionality====&lt;br /&gt;
* Any user irrespective of his/ her privileges can view all the versions.&lt;br /&gt;
::The versions which a particular user can view should be restricted based on the privileges of the user. For instance, only a user with Administrator privileges should be able to view all the versions in the system. However, that is not the case now. Every user can view all the versions irrespective of whether the user is a student or an administrator.&lt;br /&gt;
* Any user can delete any version&lt;br /&gt;
::The versions which a particular user can delete should be restricted based on the privileges of the user. For instance, a student should not be allowed to delete any version. According to the current implementation any user can delete any version in the system.&lt;br /&gt;
* Filtering of versions were restricted to the current user&lt;br /&gt;
::The filtering options on versions were restricted to the current user. Sometimes a user might want to view versions associated with other users. For instance, an instructor might want to view the list of versions created by a particular student. This is not possible with the current implementation.&lt;br /&gt;
&lt;br /&gt;
====Drawbacks and Solutions====&lt;br /&gt;
* '''Problem 1''': The method paginate_list is doing more than one thing.&lt;br /&gt;
::The method paginate_list was building a complex search criteria based on the input params, getting the list of versions from the Database matching this search criteria and then calling the Page API. All these tasks in a single method made it difficult to understand.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# For filtering the versions list with proper search and pagination.&lt;br /&gt;
  def paginate_list(id, user_id, item_type, event, datetime)&lt;br /&gt;
    # Set up the search criteria&lt;br /&gt;
    criteria = ''&lt;br /&gt;
    criteria = criteria + &amp;quot;id = #{id} AND &amp;quot; if id &amp;amp;&amp;amp; id.to_i &amp;gt; 0&lt;br /&gt;
    if current_user_role? == 'Super-Administrator'&lt;br /&gt;
      criteria = criteria + &amp;quot;whodunnit = #{user_id} AND &amp;quot; if user_id &amp;amp;&amp;amp; user_id.to_i &amp;gt; 0&lt;br /&gt;
    end&lt;br /&gt;
    criteria = criteria + &amp;quot;whodunnit = #{current_user.try(:id)} AND &amp;quot; if current_user.try(:id) &amp;amp;&amp;amp; current_user.try(:id).to_i &amp;gt; 0&lt;br /&gt;
    criteria = criteria + &amp;quot;item_type = '#{item_type}' AND &amp;quot; if item_type &amp;amp;&amp;amp; !(item_type.eql? 'Any')&lt;br /&gt;
    criteria = criteria + &amp;quot;event = '#{event}' AND &amp;quot; if event &amp;amp;&amp;amp; !(event.eql? 'Any')&lt;br /&gt;
    criteria = criteria + &amp;quot;created_at &amp;gt;= '#{time_to_string(params[:start_time])}' AND &amp;quot;&lt;br /&gt;
    criteria = criteria + &amp;quot;created_at &amp;lt;= '#{time_to_string(params[:end_time])}' AND &amp;quot;&lt;br /&gt;
&lt;br /&gt;
    if current_role == 'Instructor' || current_role == 'Administrator'&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # Remove the last ' AND '&lt;br /&gt;
    criteria = criteria[0..-5]&lt;br /&gt;
&lt;br /&gt;
    versions = Version.page(params[:page]).order('id').per_page(25).where(criteria)&lt;br /&gt;
    versions&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* '''Solution''': The implementation has been changed in such a way that the versions which a user is allowed to see depends on the privileges of the user. The approach we have taken is as follows:&lt;br /&gt;
**An administrator can see all the versions&lt;br /&gt;
**An instructor can see all the versions created by him and other users who are in his course or are participants in the assignments he creates.&lt;br /&gt;
**A TA can see all the versions created by him and other users who are in the course for which he/ she assists.&lt;br /&gt;
**A Student can see all the versions created by him/ her.&lt;br /&gt;
* '''Problem 2''': The search criteria created in the method paginate_list was difficult to comprehend.&lt;br /&gt;
::The code which builds the search criteria in the method paginate_list uses many string literals and conditions and is hardly intuitive. The programmer will have to spend some time to understand what the code is really doing.&lt;br /&gt;
* '''Solution''': The implementation has been changed. A student is not allowed to delete any versions now. Other types of users, for instance administrators, instructors and TAs are allowed to delete only the versions they are authorized to view.&lt;br /&gt;
* '''Problem 3''': The paginate method can be moved to a helper class.&lt;br /&gt;
::VersionsController is not the only component which require to paginate items. There are other components too. For instance, the UsersController has to paginate the list of users. Hence the Paginate method can be moved to a helper class which can be accessed by other components as well.&lt;br /&gt;
* '''Solution''': The filtering options has also been enhanced. The current user can now choose as part of the version search filter any user from a list of users if the current user is authorized to see the versions created by that user.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===New Implementation===&lt;br /&gt;
*The method paginate_list has been split into 2 methods now. &lt;br /&gt;
** BuildSearchCriteria – as the name suggests the sole purpose of this method is to build a search criteria based on the input search filters when the current user initiates a search in versions.&lt;br /&gt;
** paginate_list – this method will call the paginate API.&lt;br /&gt;
:First the search criteria is built, then the criteria is applied to versions in the database to get all versions which matches the criteria and then the retrieved versions are paginated.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # pagination.&lt;br /&gt;
  def paginate_list(versions)&lt;br /&gt;
    paginate(versions, VERSIONS_PER_PAGE);&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def BuildSearchCriteria(id, user_id, item_type, event)&lt;br /&gt;
    # Set up the search criteria&lt;br /&gt;
    search_criteria = ''&lt;br /&gt;
    search_criteria = search_criteria + add_id_filter_if_valid(id).to_s&lt;br /&gt;
    if current_user_role? == 'Super-Administrator'&lt;br /&gt;
      search_criteria = search_criteria + add_user_filter_for_super_admin(user_id).to_s&lt;br /&gt;
    end&lt;br /&gt;
    search_criteria = search_criteria + add_user_filter&lt;br /&gt;
    search_criteria = search_criteria + add_version_type_filter(item_type).to_s&lt;br /&gt;
    search_criteria = search_criteria + add_event_filter(event).to_s&lt;br /&gt;
    search_criteria = search_criteria + add_date_time_filter&lt;br /&gt;
    search_criteria&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The string literals and conditions in the method paginate_list were replaced with methods with intuitive names so that the programmer can understand the code more easily. We also removed an empty if clause and a redundant statement.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def add_id_filter_if_valid (id)&lt;br /&gt;
    &amp;quot;id = #{id} AND &amp;quot; if id &amp;amp;&amp;amp; id.to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_user_filter_for_super_admin (user_id)&lt;br /&gt;
    &amp;quot;whodunnit = #{user_id} AND &amp;quot; if user_id &amp;amp;&amp;amp; user_id.to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_user_filter&lt;br /&gt;
    &amp;quot;whodunnit = #{current_user.try(:id)} AND &amp;quot; if current_user.try(:id) &amp;amp;&amp;amp; current_user.try(:id).to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_event_filter (event)&lt;br /&gt;
    &amp;quot;event = '#{event}' AND &amp;quot; if event &amp;amp;&amp;amp; !(event.eql? 'Any')&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_date_time_filter&lt;br /&gt;
    &amp;quot;created_at &amp;gt;= '#{time_to_string(params[:start_time])}' AND &amp;quot; +&lt;br /&gt;
        &amp;quot;created_at &amp;lt;= '#{time_to_string(params[:end_time])}'&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_version_type_filter (version_type)&lt;br /&gt;
    &amp;quot;item_type = '#{version_type}' AND &amp;quot; if version_type &amp;amp;&amp;amp; !(version_type.eql? 'Any')&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The paginate method has been moved to the helper class Pagination_Helper. This new method can be now reused by the different components like UsersController etc. The method receives two parameters, first the list to paginate and second the number of items to be displayed in a page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module PaginationHelper&lt;br /&gt;
&lt;br /&gt;
  def paginate (items, number_of_items_per_page)&lt;br /&gt;
    items.page(params[:page]).per_page(number_of_items_per_page)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Code improvements===&lt;br /&gt;
* Introduced a constant VERSIONS_PER_PAGE and assigned the value 25 to it. The pagination algorithm for VersionsController displays at most 25 versions in a page. The existing implementation uses the value 25 straight in the code and there are few problems associated with such an approach.&lt;br /&gt;
** It is not easy to understand what 25 is unless the programmer takes a close look at the code.&lt;br /&gt;
** In case if the value 25 is used at more than one places and in future a new requirement comes to show at most 30 versions in a page, all the values will have to be modified. It is not very DRY.&lt;br /&gt;
* The VersionsController was overriding AccessHelper - action_allowed? method to return true in all the cases. This was violating the whole purpose of the method action_allowed?. The purpose of this method is to determine whether the user who is triggering a CRUD operation is allowed to do so. So when the current user invokes a CRUD operation, the action_allowed? method is invoked first and if the method returns true the CRUD operation is triggered or else the user is intimated with a message and gracefully exited. Hence, when the action_allowed? method is overridden to return true always, it results in providing unauthorized access to certain users.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def action_allowed?&lt;br /&gt;
    true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:With the new implementation the AccessHelper - action_allowed? method has been modified in such a way that unauthorized access is prevented. As per the new algorithm, 'new', 'create', 'edit', 'update' cannot be invoked by any user. These operations can be accessed only by ‘papertrail’ gem. Only an ‘Administrator’ or ‘Super-Administrator’ can call 'destroy_all' method. All the other methods are accessible to ‘Administrator’,  ‘Super-Administrator’, ‘Instructor’, ‘Teaching Assistant’ and ‘Student’.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    case params[:action]&lt;br /&gt;
    when 'new', 'create', 'edit', 'update'&lt;br /&gt;
    #Modifications can only be done by papertrail&lt;br /&gt;
      return false&lt;br /&gt;
    when 'destroy_all'&lt;br /&gt;
      ['Super-Administrator',&lt;br /&gt;
       'Administrator'].include? current_role_name&lt;br /&gt;
    else&lt;br /&gt;
      #Allow all others&lt;br /&gt;
      ['Super-Administrator',&lt;br /&gt;
       'Administrator',&lt;br /&gt;
       'Instructor',&lt;br /&gt;
       'Teaching Assistant',&lt;br /&gt;
       'Student'].include? current_role_name&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/WintersLt/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[http://bit.ly/myexpertiza  Demo link] &lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;br /&gt;
#[https://relishapp.com/rspec Rspec Documentation]&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1553_AAJ&amp;diff=97428</id>
		<title>CSC/ECE 517 Fall 2015/oss E1553 AAJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1553_AAJ&amp;diff=97428"/>
		<updated>2015-10-31T02:38:07Z</updated>

		<summary type="html">&lt;p&gt;Asayal: /* Introduction to Expertiza */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1553. Refactoring the Versions Controller==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Introduction to Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a large project developed as a combined effort of students and faculty using the [http://rubyonrails.org/ Ruby on Rails] framework. The main advantage of using Expertiza, in an educational environment, is for the instructor to introduce peer reviewing among the students. Expertiza allows the instructor to create and customize assignments, create a list of topics the students can sign up for, have students work on teams and then review each other's assignments at the end. Expertiza supports submission of almost any document type, including the URLs and wiki pages. Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the [http://www.ncsu.edu/ NCSU] [http://litre.ncsu.edu/ Learning in a Technology-Rich Environment] (LITRE) program, the NCSU [http://ofd.ncsu.edu/teaching-learning/ Faculty Center for Teaching and Learning], the NCSU [http://stem.ncsu.edu/ STEM] Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
===Current Implementation===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Functionality====&lt;br /&gt;
* Any user irrespective of his/ her privileges can view all the versions.&lt;br /&gt;
::The versions which a particular user can view should be restricted based on the privileges of the user. For instance, only a user with Administrator privileges should be able to view all the versions in the system. However, that is not the case now. Every user can view all the versions irrespective of whether the user is a student or an administrator.&lt;br /&gt;
* Any user can delete any version&lt;br /&gt;
::The versions which a particular user can delete should be restricted based on the privileges of the user. For instance, a student should not be allowed to delete any version. According to the current implementation any user can delete any version in the system.&lt;br /&gt;
* Filtering of versions were restricted to the current user&lt;br /&gt;
::The filtering options on versions were restricted to the current user. Sometimes a user might want to view versions associated with other users. For instance, an instructor might want to view the list of versions created by a particular student. This is not possible with the current implementation.&lt;br /&gt;
&lt;br /&gt;
====Drawbacks and Solutions====&lt;br /&gt;
* '''Problem 1''': The method paginate_list is doing more than one thing.&lt;br /&gt;
::The method paginate_list was building a complex search criteria based on the input params, getting the list of versions from the Database matching this search criteria and then calling the Page API. All these tasks in a single method made it difficult to understand.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# For filtering the versions list with proper search and pagination.&lt;br /&gt;
  def paginate_list(id, user_id, item_type, event, datetime)&lt;br /&gt;
    # Set up the search criteria&lt;br /&gt;
    criteria = ''&lt;br /&gt;
    criteria = criteria + &amp;quot;id = #{id} AND &amp;quot; if id &amp;amp;&amp;amp; id.to_i &amp;gt; 0&lt;br /&gt;
    if current_user_role? == 'Super-Administrator'&lt;br /&gt;
      criteria = criteria + &amp;quot;whodunnit = #{user_id} AND &amp;quot; if user_id &amp;amp;&amp;amp; user_id.to_i &amp;gt; 0&lt;br /&gt;
    end&lt;br /&gt;
    criteria = criteria + &amp;quot;whodunnit = #{current_user.try(:id)} AND &amp;quot; if current_user.try(:id) &amp;amp;&amp;amp; current_user.try(:id).to_i &amp;gt; 0&lt;br /&gt;
    criteria = criteria + &amp;quot;item_type = '#{item_type}' AND &amp;quot; if item_type &amp;amp;&amp;amp; !(item_type.eql? 'Any')&lt;br /&gt;
    criteria = criteria + &amp;quot;event = '#{event}' AND &amp;quot; if event &amp;amp;&amp;amp; !(event.eql? 'Any')&lt;br /&gt;
    criteria = criteria + &amp;quot;created_at &amp;gt;= '#{time_to_string(params[:start_time])}' AND &amp;quot;&lt;br /&gt;
    criteria = criteria + &amp;quot;created_at &amp;lt;= '#{time_to_string(params[:end_time])}' AND &amp;quot;&lt;br /&gt;
&lt;br /&gt;
    if current_role == 'Instructor' || current_role == 'Administrator'&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # Remove the last ' AND '&lt;br /&gt;
    criteria = criteria[0..-5]&lt;br /&gt;
&lt;br /&gt;
    versions = Version.page(params[:page]).order('id').per_page(25).where(criteria)&lt;br /&gt;
    versions&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* '''Solution''': The implementation has been changed in such a way that the versions which a user is allowed to see depends on the privileges of the user. The approach we have taken is as follows:&lt;br /&gt;
**An administrator can see all the versions&lt;br /&gt;
**An instructor can see all the versions created by him and other users who are in his course or are participants in the assignments he creates.&lt;br /&gt;
**A TA can see all the versions created by him and other users who are in the course for which he/ she assists.&lt;br /&gt;
**A Student can see all the versions created by him/ her.&lt;br /&gt;
* '''Problem 2''': The search criteria created in the method paginate_list was difficult to comprehend.&lt;br /&gt;
::The code which builds the search criteria in the method paginate_list uses many string literals and conditions and is hardly intuitive. The programmer will have to spend some time to understand what the code is really doing.&lt;br /&gt;
* '''Solution''': The implementation has been changed. A student is not allowed to delete any versions now. Other types of users, for instance administrators, instructors and TAs are allowed to delete only the versions they are authorized to view.&lt;br /&gt;
* '''Problem 3''': The paginate method can be moved to a helper class.&lt;br /&gt;
::VersionsController is not the only component which require to paginate items. There are other components too. For instance, the UsersController has to paginate the list of users. Hence the Paginate method can be moved to a helper class which can be accessed by other components as well.&lt;br /&gt;
* '''Solution''': The filtering options has also been enhanced. The current user can now choose as part of the version search filter any user from a list of users if the current user is authorized to see the versions created by that user.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===New Implementation===&lt;br /&gt;
*The method paginate_list has been split into 2 methods now. &lt;br /&gt;
** BuildSearchCriteria – as the name suggests the sole purpose of this method is to build a search criteria based on the input search filters when the current user initiates a search in versions.&lt;br /&gt;
** paginate_list – this method will call the paginate API.&lt;br /&gt;
:First the search criteria is built, then the criteria is applied to versions in the database to get all versions which matches the criteria and then the retrieved versions are paginated.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # pagination.&lt;br /&gt;
  def paginate_list(versions)&lt;br /&gt;
    paginate(versions, VERSIONS_PER_PAGE);&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def BuildSearchCriteria(id, user_id, item_type, event)&lt;br /&gt;
    # Set up the search criteria&lt;br /&gt;
    search_criteria = ''&lt;br /&gt;
    search_criteria = search_criteria + add_id_filter_if_valid(id).to_s&lt;br /&gt;
    if current_user_role? == 'Super-Administrator'&lt;br /&gt;
      search_criteria = search_criteria + add_user_filter_for_super_admin(user_id).to_s&lt;br /&gt;
    end&lt;br /&gt;
    search_criteria = search_criteria + add_user_filter&lt;br /&gt;
    search_criteria = search_criteria + add_version_type_filter(item_type).to_s&lt;br /&gt;
    search_criteria = search_criteria + add_event_filter(event).to_s&lt;br /&gt;
    search_criteria = search_criteria + add_date_time_filter&lt;br /&gt;
    search_criteria&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The string literals and conditions in the method paginate_list were replaced with methods with intuitive names so that the programmer can understand the code more easily. We also removed an empty if clause and a redundant statement.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def add_id_filter_if_valid (id)&lt;br /&gt;
    &amp;quot;id = #{id} AND &amp;quot; if id &amp;amp;&amp;amp; id.to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_user_filter_for_super_admin (user_id)&lt;br /&gt;
    &amp;quot;whodunnit = #{user_id} AND &amp;quot; if user_id &amp;amp;&amp;amp; user_id.to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_user_filter&lt;br /&gt;
    &amp;quot;whodunnit = #{current_user.try(:id)} AND &amp;quot; if current_user.try(:id) &amp;amp;&amp;amp; current_user.try(:id).to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_event_filter (event)&lt;br /&gt;
    &amp;quot;event = '#{event}' AND &amp;quot; if event &amp;amp;&amp;amp; !(event.eql? 'Any')&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_date_time_filter&lt;br /&gt;
    &amp;quot;created_at &amp;gt;= '#{time_to_string(params[:start_time])}' AND &amp;quot; +&lt;br /&gt;
        &amp;quot;created_at &amp;lt;= '#{time_to_string(params[:end_time])}'&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_version_type_filter (version_type)&lt;br /&gt;
    &amp;quot;item_type = '#{version_type}' AND &amp;quot; if version_type &amp;amp;&amp;amp; !(version_type.eql? 'Any')&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The paginate method has been moved to the helper class Pagination_Helper. This new method can be now reused by the different components like UsersController etc. The method receives two parameters, first the list to paginate and second the number of items to be displayed in a page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module PaginationHelper&lt;br /&gt;
&lt;br /&gt;
  def paginate (items, number_of_items_per_page)&lt;br /&gt;
    items.page(params[:page]).per_page(number_of_items_per_page)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Code improvements===&lt;br /&gt;
* Introduced a constant VERSIONS_PER_PAGE and assigned the value 25 to it. The pagination algorithm for VersionsController displays at most 25 versions in a page. The existing implementation uses the value 25 straight in the code and there are few problems associated with such an approach.&lt;br /&gt;
** It is not easy to understand what 25 is unless the programmer takes a close look at the code.&lt;br /&gt;
** In case if the value 25 is used at more than one places and in future a new requirement comes to show at most 30 versions in a page, all the values will have to be modified. It is not very DRY.&lt;br /&gt;
* The VersionsController was overriding AccessHelper - action_allowed? method to return true in all the cases. This was violating the whole purpose of the method action_allowed?. The purpose of this method is to determine whether the user who is triggering a CRUD operation is allowed to do so. So when the current user invokes a CRUD operation, the action_allowed? method is invoked first and if the method returns true the CRUD operation is triggered or else the user is intimated with a message and gracefully exited. Hence, when the action_allowed? method is overridden to return true always, it results in providing unauthorized access to certain users.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def action_allowed?&lt;br /&gt;
    true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:With the new implementation the AccessHelper - action_allowed? method has been modified in such a way that unauthorized access is prevented. As per the new algorithm, 'new', 'create', 'edit', 'update' cannot be invoked by any user. These operations can be accessed only by ‘papertrail’ gem. Only an ‘Administrator’ or ‘Super-Administrator’ can call 'destroy_all' method. All the other methods are accessible to ‘Administrator’,  ‘Super-Administrator’, ‘Instructor’, ‘Teaching Assistant’ and ‘Student’.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    case params[:action]&lt;br /&gt;
    when 'new', 'create', 'edit', 'update'&lt;br /&gt;
    #Modifications can only be done by papertrail&lt;br /&gt;
      return false&lt;br /&gt;
    when 'destroy_all'&lt;br /&gt;
      ['Super-Administrator',&lt;br /&gt;
       'Administrator'].include? current_role_name&lt;br /&gt;
    else&lt;br /&gt;
      #Allow all others&lt;br /&gt;
      ['Super-Administrator',&lt;br /&gt;
       'Administrator',&lt;br /&gt;
       'Instructor',&lt;br /&gt;
       'Teaching Assistant',&lt;br /&gt;
       'Student'].include? current_role_name&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/WintersLt/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[http://bit.ly/myexpertiza  Demo link] &lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;br /&gt;
#[https://relishapp.com/rspec Rspec Documentation]&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1553_AAJ&amp;diff=97427</id>
		<title>CSC/ECE 517 Fall 2015/oss E1553 AAJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1553_AAJ&amp;diff=97427"/>
		<updated>2015-10-31T02:17:47Z</updated>

		<summary type="html">&lt;p&gt;Asayal: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1553. Refactoring the Versions Controller==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Introduction to Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a large project developed as a combined effort of students and faculty using the [http://rubyonrails.org/ Ruby on Rails] framework. The main advantage of using Expertiza, in an educational environment, is for the instructor to introduce peer reviewing among the students. Expertiza allows the instructor to create and customize assignments, create a list of topics the students can sign up for, have students work on teams and then review each other's assignments at the end. Expertiza supports submission of almost any document type, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the [http://www.ncsu.edu/ NCSU] [http://litre.ncsu.edu/ Learning in a Technology-Rich Environment] (LITRE) program, the NCSU [http://ofd.ncsu.edu/teaching-learning/ Faculty Center for Teaching and Learning], the NCSU [http://stem.ncsu.edu/ STEM] Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
Pagination of versions helps the user to view a subset of versions at a time. Considering the huge number of versions in the system, it is very useful to have a pagination mechanism and a filtering mechanism which can be applied on the whole set of versions. The idea is to display the versions in an ordered, comprehensible and logical manner. In Expertiza the gem ‘will_paginate’ is used to achieve pagination.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Current Implementation===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Functionality====&lt;br /&gt;
* Any user irrespective of his/ her privileges can view all the versions.&lt;br /&gt;
::The versions which a particular user can view should be restricted based on the privileges of the user. For instance, only a user with Administrator privileges should be able to view all the versions in the system. However, that is not the case now. Every user can view all the versions irrespective of whether the user is a student or an administrator.&lt;br /&gt;
* Any user can delete any version&lt;br /&gt;
::The versions which a particular user can delete should be restricted based on the privileges of the user. For instance, a student should not be allowed to delete any version. According to the current implementation any user can delete any version in the system.&lt;br /&gt;
* Filtering of versions were restricted to the current user&lt;br /&gt;
::The filtering options on versions were restricted to the current user. Sometimes a user might want to view versions associated with other users. For instance, an instructor might want to view the list of versions created by a particular student. This is not possible with the current implementation.&lt;br /&gt;
&lt;br /&gt;
====Drawbacks and Solutions====&lt;br /&gt;
* '''Problem 1''': The method paginate_list is doing more than one thing.&lt;br /&gt;
::The method paginate_list was building a complex search criteria based on the input params, getting the list of versions from the Database matching this search criteria and then calling the Page API. All these tasks in a single method made it difficult to understand.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# For filtering the versions list with proper search and pagination.&lt;br /&gt;
  def paginate_list(id, user_id, item_type, event, datetime)&lt;br /&gt;
    # Set up the search criteria&lt;br /&gt;
    criteria = ''&lt;br /&gt;
    criteria = criteria + &amp;quot;id = #{id} AND &amp;quot; if id &amp;amp;&amp;amp; id.to_i &amp;gt; 0&lt;br /&gt;
    if current_user_role? == 'Super-Administrator'&lt;br /&gt;
      criteria = criteria + &amp;quot;whodunnit = #{user_id} AND &amp;quot; if user_id &amp;amp;&amp;amp; user_id.to_i &amp;gt; 0&lt;br /&gt;
    end&lt;br /&gt;
    criteria = criteria + &amp;quot;whodunnit = #{current_user.try(:id)} AND &amp;quot; if current_user.try(:id) &amp;amp;&amp;amp; current_user.try(:id).to_i &amp;gt; 0&lt;br /&gt;
    criteria = criteria + &amp;quot;item_type = '#{item_type}' AND &amp;quot; if item_type &amp;amp;&amp;amp; !(item_type.eql? 'Any')&lt;br /&gt;
    criteria = criteria + &amp;quot;event = '#{event}' AND &amp;quot; if event &amp;amp;&amp;amp; !(event.eql? 'Any')&lt;br /&gt;
    criteria = criteria + &amp;quot;created_at &amp;gt;= '#{time_to_string(params[:start_time])}' AND &amp;quot;&lt;br /&gt;
    criteria = criteria + &amp;quot;created_at &amp;lt;= '#{time_to_string(params[:end_time])}' AND &amp;quot;&lt;br /&gt;
&lt;br /&gt;
    if current_role == 'Instructor' || current_role == 'Administrator'&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # Remove the last ' AND '&lt;br /&gt;
    criteria = criteria[0..-5]&lt;br /&gt;
&lt;br /&gt;
    versions = Version.page(params[:page]).order('id').per_page(25).where(criteria)&lt;br /&gt;
    versions&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* '''Solution''': The implementation has been changed in such a way that the versions which a user is allowed to see depends on the privileges of the user. The approach we have taken is as follows:&lt;br /&gt;
**An administrator can see all the versions&lt;br /&gt;
**An instructor can see all the versions created by him and other users who are in his course or are participants in the assignments he creates.&lt;br /&gt;
**A TA can see all the versions created by him and other users who are in the course for which he/ she assists.&lt;br /&gt;
**A Student can see all the versions created by him/ her.&lt;br /&gt;
* '''Problem 2''': The search criteria created in the method paginate_list was difficult to comprehend.&lt;br /&gt;
::The code which builds the search criteria in the method paginate_list uses many string literals and conditions and is hardly intuitive. The programmer will have to spend some time to understand what the code is really doing.&lt;br /&gt;
* '''Solution''': The implementation has been changed. A student is not allowed to delete any versions now. Other types of users, for instance administrators, instructors and TAs are allowed to delete only the versions they are authorized to view.&lt;br /&gt;
* '''Problem 3''': The paginate method can be moved to a helper class.&lt;br /&gt;
::VersionsController is not the only component which require to paginate items. There are other components too. For instance, the UsersController has to paginate the list of users. Hence the Paginate method can be moved to a helper class which can be accessed by other components as well.&lt;br /&gt;
* '''Solution''': The filtering options has also been enhanced. The current user can now choose as part of the version search filter any user from a list of users if the current user is authorized to see the versions created by that user.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===New Implementation===&lt;br /&gt;
*The method paginate_list has been split into 2 methods now. &lt;br /&gt;
** BuildSearchCriteria – as the name suggests the sole purpose of this method is to build a search criteria based on the input search filters when the current user initiates a search in versions.&lt;br /&gt;
** paginate_list – this method will call the paginate API.&lt;br /&gt;
:First the search criteria is built, then the criteria is applied to versions in the database to get all versions which matches the criteria and then the retrieved versions are paginated.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # pagination.&lt;br /&gt;
  def paginate_list(versions)&lt;br /&gt;
    paginate(versions, VERSIONS_PER_PAGE);&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def BuildSearchCriteria(id, user_id, item_type, event)&lt;br /&gt;
    # Set up the search criteria&lt;br /&gt;
    search_criteria = ''&lt;br /&gt;
    search_criteria = search_criteria + add_id_filter_if_valid(id).to_s&lt;br /&gt;
    if current_user_role? == 'Super-Administrator'&lt;br /&gt;
      search_criteria = search_criteria + add_user_filter_for_super_admin(user_id).to_s&lt;br /&gt;
    end&lt;br /&gt;
    search_criteria = search_criteria + add_user_filter&lt;br /&gt;
    search_criteria = search_criteria + add_version_type_filter(item_type).to_s&lt;br /&gt;
    search_criteria = search_criteria + add_event_filter(event).to_s&lt;br /&gt;
    search_criteria = search_criteria + add_date_time_filter&lt;br /&gt;
    search_criteria&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The string literals and conditions in the method paginate_list were replaced with methods with intuitive names so that the programmer can understand the code more easily. We also removed an empty if clause and a redundant statement.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def add_id_filter_if_valid (id)&lt;br /&gt;
    &amp;quot;id = #{id} AND &amp;quot; if id &amp;amp;&amp;amp; id.to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_user_filter_for_super_admin (user_id)&lt;br /&gt;
    &amp;quot;whodunnit = #{user_id} AND &amp;quot; if user_id &amp;amp;&amp;amp; user_id.to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_user_filter&lt;br /&gt;
    &amp;quot;whodunnit = #{current_user.try(:id)} AND &amp;quot; if current_user.try(:id) &amp;amp;&amp;amp; current_user.try(:id).to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_event_filter (event)&lt;br /&gt;
    &amp;quot;event = '#{event}' AND &amp;quot; if event &amp;amp;&amp;amp; !(event.eql? 'Any')&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_date_time_filter&lt;br /&gt;
    &amp;quot;created_at &amp;gt;= '#{time_to_string(params[:start_time])}' AND &amp;quot; +&lt;br /&gt;
        &amp;quot;created_at &amp;lt;= '#{time_to_string(params[:end_time])}'&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_version_type_filter (version_type)&lt;br /&gt;
    &amp;quot;item_type = '#{version_type}' AND &amp;quot; if version_type &amp;amp;&amp;amp; !(version_type.eql? 'Any')&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The paginate method has been moved to the helper class Pagination_Helper. This new method can be now reused by the different components like UsersController etc. The method receives two parameters, first the list to paginate and second the number of items to be displayed in a page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module PaginationHelper&lt;br /&gt;
&lt;br /&gt;
  def paginate (items, number_of_items_per_page)&lt;br /&gt;
    items.page(params[:page]).per_page(number_of_items_per_page)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Code improvements===&lt;br /&gt;
* Introduced a constant VERSIONS_PER_PAGE and assigned the value 25 to it. The pagination algorithm for VersionsController displays at most 25 versions in a page. The existing implementation uses the value 25 straight in the code and there are few problems associated with such an approach.&lt;br /&gt;
** It is not easy to understand what 25 is unless the programmer takes a close look at the code.&lt;br /&gt;
** In case if the value 25 is used at more than one places and in future a new requirement comes to show at most 30 versions in a page, all the values will have to be modified. It is not very DRY.&lt;br /&gt;
* The VersionsController was overriding AccessHelper - action_allowed? method to return true in all the cases. This was violating the whole purpose of the method action_allowed?. The purpose of this method is to determine whether the user who is triggering a CRUD operation is allowed to do so. So when the current user invokes a CRUD operation, the action_allowed? method is invoked first and if the method returns true the CRUD operation is triggered or else the user is intimated with a message and gracefully exited. Hence, when the action_allowed? method is overridden to return true always, it results in providing unauthorized access to certain users.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def action_allowed?&lt;br /&gt;
    true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:With the new implementation the AccessHelper - action_allowed? method has been modified in such a way that unauthorized access is prevented. As per the new algorithm, 'new', 'create', 'edit', 'update' cannot be invoked by any user. These operations can be accessed only by ‘papertrail’ gem. Only an ‘Administrator’ or ‘Super-Administrator’ can call 'destroy_all' method. All the other methods are accessible to ‘Administrator’,  ‘Super-Administrator’, ‘Instructor’, ‘Teaching Assistant’ and ‘Student’.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    case params[:action]&lt;br /&gt;
    when 'new', 'create', 'edit', 'update'&lt;br /&gt;
    #Modifications can only be done by papertrail&lt;br /&gt;
      return false&lt;br /&gt;
    when 'destroy_all'&lt;br /&gt;
      ['Super-Administrator',&lt;br /&gt;
       'Administrator'].include? current_role_name&lt;br /&gt;
    else&lt;br /&gt;
      #Allow all others&lt;br /&gt;
      ['Super-Administrator',&lt;br /&gt;
       'Administrator',&lt;br /&gt;
       'Instructor',&lt;br /&gt;
       'Teaching Assistant',&lt;br /&gt;
       'Student'].include? current_role_name&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/WintersLt/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[http://bit.ly/myexpertiza  Demo link] &lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;br /&gt;
#[https://relishapp.com/rspec Rspec Documentation]&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1553_AAJ&amp;diff=97425</id>
		<title>CSC/ECE 517 Fall 2015/oss E1553 AAJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1553_AAJ&amp;diff=97425"/>
		<updated>2015-10-31T01:18:50Z</updated>

		<summary type="html">&lt;p&gt;Asayal: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1553. Refactoring the Versions Controller==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Introduction to Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a large project developed as a combined effort of students and faculty using the [http://rubyonrails.org/ Ruby on Rails] framework. The main advantage of using Expertiza, in an educational environment, is for the instructor to introduce peer reviewing among the students. Expertiza allows the instructor to create and customize assignments, create a list of topics the students can sign up for, have students work on teams and then review each other's assignments at the end. Expertiza supports submission of almost any document type, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the [http://www.ncsu.edu/ NCSU] [http://litre.ncsu.edu/ Learning in a Technology-Rich Environment] (LITRE) program, the NCSU [http://ofd.ncsu.edu/teaching-learning/ Faculty Center for Teaching and Learning], the NCSU [http://stem.ncsu.edu/ STEM] Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
Pagination of versions helps the user to view a subset of versions at a time. Considering the huge number of versions in the system, it is very useful to have a pagination mechanism and a filtering mechanism which can be applied on the whole set of versions. The idea is to display the versions in an ordered, comprehensible and logical manner. In Expertiza the gem ‘will_paginate’ is used to achieve pagination.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Current Implementation===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Functionality====&lt;br /&gt;
* Any user irrespective of his/ her privileges can view all the versions.&lt;br /&gt;
::The versions which a particular user can view should be restricted based on the privileges of the user. For instance, only a user with Administrator privileges should be able to view all the versions in the system. However, that is not the case now. Every user can view all the versions irrespective of whether the user is a student or an administrator.&lt;br /&gt;
* Any user can delete any version&lt;br /&gt;
::The versions which a particular user can delete should be restricted based on the privileges of the user. For instance, a student should not be allowed to delete any version. According to the current implementation any user can delete any version in the system.&lt;br /&gt;
* Filtering of versions were restricted to the current user&lt;br /&gt;
::The filtering options on versions were restricted to the current user. Sometimes a user might want to view versions associated with other users. For instance, an instructor might want to view the list of versions created by a particular student. This is not possible with the current implementation.&lt;br /&gt;
&lt;br /&gt;
====Drawbacks and Solutions====&lt;br /&gt;
* '''Problem 1''': The method paginate_list is doing more than one thing.&lt;br /&gt;
::The method paginate_list was building a complex search criteria based on the input params, getting the list of versions from the Database matching this search criteria and then calling the Page API. All these tasks in a single method made it difficult to understand.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# For filtering the versions list with proper search and pagination.&lt;br /&gt;
  def paginate_list(id, user_id, item_type, event, datetime)&lt;br /&gt;
    # Set up the search criteria&lt;br /&gt;
    criteria = ''&lt;br /&gt;
    criteria = criteria + &amp;quot;id = #{id} AND &amp;quot; if id &amp;amp;&amp;amp; id.to_i &amp;gt; 0&lt;br /&gt;
    if current_user_role? == 'Super-Administrator'&lt;br /&gt;
      criteria = criteria + &amp;quot;whodunnit = #{user_id} AND &amp;quot; if user_id &amp;amp;&amp;amp; user_id.to_i &amp;gt; 0&lt;br /&gt;
    end&lt;br /&gt;
    criteria = criteria + &amp;quot;whodunnit = #{current_user.try(:id)} AND &amp;quot; if current_user.try(:id) &amp;amp;&amp;amp; current_user.try(:id).to_i &amp;gt; 0&lt;br /&gt;
    criteria = criteria + &amp;quot;item_type = '#{item_type}' AND &amp;quot; if item_type &amp;amp;&amp;amp; !(item_type.eql? 'Any')&lt;br /&gt;
    criteria = criteria + &amp;quot;event = '#{event}' AND &amp;quot; if event &amp;amp;&amp;amp; !(event.eql? 'Any')&lt;br /&gt;
    criteria = criteria + &amp;quot;created_at &amp;gt;= '#{time_to_string(params[:start_time])}' AND &amp;quot;&lt;br /&gt;
    criteria = criteria + &amp;quot;created_at &amp;lt;= '#{time_to_string(params[:end_time])}' AND &amp;quot;&lt;br /&gt;
&lt;br /&gt;
    if current_role == 'Instructor' || current_role == 'Administrator'&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # Remove the last ' AND '&lt;br /&gt;
    criteria = criteria[0..-5]&lt;br /&gt;
&lt;br /&gt;
    versions = Version.page(params[:page]).order('id').per_page(25).where(criteria)&lt;br /&gt;
    versions&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* '''Solution''': The implementation has been changed in such a way that the versions which a user is allowed to see depends on the privileges of the user. The approach we have taken is as follows:&lt;br /&gt;
**An administrator can see all the versions&lt;br /&gt;
**An instructor can see all the versions created by him and other users who are in his course or are participants in the assignments he creates.&lt;br /&gt;
**A TA can see all the versions created by him and other users who are in the course for which he/ she assists.&lt;br /&gt;
**A Student can see all the versions created by him/ her.&lt;br /&gt;
* '''Problem 2''': The search criteria created in the method paginate_list was difficult to comprehend.&lt;br /&gt;
::The code which builds the search criteria in the method paginate_list uses many string literals and conditions and is hardly intuitive. The programmer will have to spend some time to understand what the code is really doing.&lt;br /&gt;
* '''Solution''': The implementation has been changed. A student is not allowed to delete any versions now. Other types of users, for instance administrators, instructors and TAs are allowed to delete only the versions they are authorized to view.&lt;br /&gt;
* '''Problem 3''': The paginate method can be moved to a helper class.&lt;br /&gt;
::VersionsController is not the only component which require to paginate items. There are other components too. For instance, the UsersController has to paginate the list of users. Hence the Paginate method can be moved to a helper class which can be accessed by other components as well.&lt;br /&gt;
* '''Solution''': The filtering options has also been enhanced. The current user can now choose as part of the version search filter any user from a list of users if the current user is authorized to see the versions created by that user.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===New Implementation===&lt;br /&gt;
*The method paginate_list has been split into 2 methods now. &lt;br /&gt;
** BuildSearchCriteria – as the name suggests the sole purpose of this method is to build a search criteria based on the input search filters when the current user initiates a search in versions.&lt;br /&gt;
** paginate_list – this method will call the paginate API.&lt;br /&gt;
:First the search criteria is built, then the criteria is applied to versions in the database to get all versions which matches the criteria and then the retrieved versions are paginated.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # pagination.&lt;br /&gt;
  def paginate_list(versions)&lt;br /&gt;
    paginate(versions, VERSIONS_PER_PAGE);&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def BuildSearchCriteria(id, user_id, item_type, event)&lt;br /&gt;
    # Set up the search criteria&lt;br /&gt;
    search_criteria = ''&lt;br /&gt;
    search_criteria = search_criteria + add_id_filter_if_valid(id).to_s&lt;br /&gt;
    if current_user_role? == 'Super-Administrator'&lt;br /&gt;
      search_criteria = search_criteria + add_user_filter_for_super_admin(user_id).to_s&lt;br /&gt;
    end&lt;br /&gt;
    search_criteria = search_criteria + add_user_filter&lt;br /&gt;
    search_criteria = search_criteria + add_version_type_filter(item_type).to_s&lt;br /&gt;
    search_criteria = search_criteria + add_event_filter(event).to_s&lt;br /&gt;
    search_criteria = search_criteria + add_date_time_filter&lt;br /&gt;
    search_criteria&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The string literals and conditions in the method paginate_list were replaced with methods with intuitive names so that the programmer can understand the code more easily. We also removed an empty if clause and a redundant statement.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def add_id_filter_if_valid (id)&lt;br /&gt;
    &amp;quot;id = #{id} AND &amp;quot; if id &amp;amp;&amp;amp; id.to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_user_filter_for_super_admin (user_id)&lt;br /&gt;
    &amp;quot;whodunnit = #{user_id} AND &amp;quot; if user_id &amp;amp;&amp;amp; user_id.to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_user_filter&lt;br /&gt;
    &amp;quot;whodunnit = #{current_user.try(:id)} AND &amp;quot; if current_user.try(:id) &amp;amp;&amp;amp; current_user.try(:id).to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_event_filter (event)&lt;br /&gt;
    &amp;quot;event = '#{event}' AND &amp;quot; if event &amp;amp;&amp;amp; !(event.eql? 'Any')&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_date_time_filter&lt;br /&gt;
    &amp;quot;created_at &amp;gt;= '#{time_to_string(params[:start_time])}' AND &amp;quot; +&lt;br /&gt;
        &amp;quot;created_at &amp;lt;= '#{time_to_string(params[:end_time])}'&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_version_type_filter (version_type)&lt;br /&gt;
    &amp;quot;item_type = '#{version_type}' AND &amp;quot; if version_type &amp;amp;&amp;amp; !(version_type.eql? 'Any')&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The paginate method has been moved to the helper class Pagination_Helper. This new method can be now reused by the different components like UsersController etc. The method receives two parameters, first the list to paginate and second the number of items to be displayed in a page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module PaginationHelper&lt;br /&gt;
&lt;br /&gt;
  def paginate (items, number_of_items_per_page)&lt;br /&gt;
    items.page(params[:page]).per_page(number_of_items_per_page)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Code improvements===&lt;br /&gt;
* Introduced a constant VERSIONS_PER_PAGE and assigned the value 25 to it. The pagination algorithm for VersionsController displays at most 25 versions in a page. The existing implementation uses the value 25 straight in the code and there are few problems associated with such an approach.&lt;br /&gt;
** It is not easy to understand what 25 is unless the programmer takes a close look at the code.&lt;br /&gt;
** In case if the value 25 is used at more than one places and in future a new requirement comes to show at most 30 versions in a page, all the values will have to be modified. It is not very DRY.&lt;br /&gt;
* The VersionsController was overriding AccessHelper - action_allowed? method to return true in all the cases. This was violating the whole purpose of the method action_allowed?. The purpose of this method is to determine whether the user who is triggering a CRUD operation is allowed to do so. So when the current user invokes a CRUD operation, the action_allowed? method is invoked first and if the method returns true the CRUD operation is triggered or else the user is intimated with a message and gracefully exited. Hence, when the action_allowed? method is overridden to return true always, it results in providing unauthorized access to certain users.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def action_allowed?&lt;br /&gt;
    true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:With the new implementation the AccessHelper - action_allowed? method has been modified in such a way that unauthorized access is prevented. As per the new algorithm, 'new', 'create', 'edit', 'update' cannot be invoked by any user. These operations can be accessed only by ‘papertrail’ gem. Only an ‘Administrator’ or ‘Super-Administrator’ can call 'destroy_all' method. All the other methods are accessible to ‘Administrator’,  ‘Super-Administrator’, ‘Instructor’, ‘Teaching Assistant’ and ‘Student’.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    case params[:action]&lt;br /&gt;
    when 'new', 'create', 'edit', 'update'&lt;br /&gt;
    #Modifications can only be done by papertrail&lt;br /&gt;
      return false&lt;br /&gt;
    when 'destroy_all'&lt;br /&gt;
      ['Super-Administrator',&lt;br /&gt;
       'Administrator'].include? current_role_name&lt;br /&gt;
    else&lt;br /&gt;
      #Allow all others&lt;br /&gt;
      ['Super-Administrator',&lt;br /&gt;
       'Administrator',&lt;br /&gt;
       'Instructor',&lt;br /&gt;
       'Teaching Assistant',&lt;br /&gt;
       'Student'].include? current_role_name&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/WintersLt/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[http://bit.ly/myexpertiza  Demo link] &lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1553_AAJ&amp;diff=97424</id>
		<title>CSC/ECE 517 Fall 2015/oss E1553 AAJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1553_AAJ&amp;diff=97424"/>
		<updated>2015-10-31T01:16:10Z</updated>

		<summary type="html">&lt;p&gt;Asayal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1553. Refactoring the Versions Controller==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Introduction to Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a large project developed as a combined effort of students and faculty using the [http://rubyonrails.org/ Ruby on Rails] framework. The main advantage of using Expertiza, in an educational environment, is for the instructor to introduce peer reviewing among the students. Expertiza allows the instructor to create and customize assignments, create a list of topics the students can sign up for, have students work on teams and then review each other's assignments at the end. Expertiza supports submission of almost any document type, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the [http://www.ncsu.edu/ NCSU] [http://litre.ncsu.edu/ Learning in a Technology-Rich Environment] (LITRE) program, the NCSU [http://ofd.ncsu.edu/teaching-learning/ Faculty Center for Teaching and Learning], the NCSU [http://stem.ncsu.edu/ STEM] Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
Pagination of versions helps the user to view a subset of versions at a time. Considering the huge number of versions in the system, it is very useful to have a pagination mechanism and a filtering mechanism which can be applied on the whole set of versions. The idea is to display the versions in an ordered, comprehensible and logical manner. In Expertiza the gem ‘will_paginate’ is used to achieve pagination.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Current Implementation===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Functionality====&lt;br /&gt;
* Any user irrespective of his/ her privileges can view all the versions.&lt;br /&gt;
::The versions which a particular user can view should be restricted based on the privileges of the user. For instance, only a user with Administrator privileges should be able to view all the versions in the system. However, that is not the case now. Every user can view all the versions irrespective of whether the user is a student or an administrator.&lt;br /&gt;
* Any user can delete any version&lt;br /&gt;
::The versions which a particular user can delete should be restricted based on the privileges of the user. For instance, a student should not be allowed to delete any version. According to the current implementation any user can delete any version in the system.&lt;br /&gt;
* Filtering of versions were restricted to the current user&lt;br /&gt;
::The filtering options on versions were restricted to the current user. Sometimes a user might want to view versions associated with other users. For instance, an instructor might want to view the list of versions created by a particular student. This is not possible with the current implementation.&lt;br /&gt;
&lt;br /&gt;
====Drawbacks and Solutions====&lt;br /&gt;
* '''Problem 1''': The method paginate_list is doing more than one thing.&lt;br /&gt;
::The method paginate_list was building a complex search criteria based on the input params, getting the list of versions from the Database matching this search criteria and then calling the Page API. All these tasks in a single method made it difficult to understand.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# For filtering the versions list with proper search and pagination.&lt;br /&gt;
  def paginate_list(id, user_id, item_type, event, datetime)&lt;br /&gt;
    # Set up the search criteria&lt;br /&gt;
    criteria = ''&lt;br /&gt;
    criteria = criteria + &amp;quot;id = #{id} AND &amp;quot; if id &amp;amp;&amp;amp; id.to_i &amp;gt; 0&lt;br /&gt;
    if current_user_role? == 'Super-Administrator'&lt;br /&gt;
      criteria = criteria + &amp;quot;whodunnit = #{user_id} AND &amp;quot; if user_id &amp;amp;&amp;amp; user_id.to_i &amp;gt; 0&lt;br /&gt;
    end&lt;br /&gt;
    criteria = criteria + &amp;quot;whodunnit = #{current_user.try(:id)} AND &amp;quot; if current_user.try(:id) &amp;amp;&amp;amp; current_user.try(:id).to_i &amp;gt; 0&lt;br /&gt;
    criteria = criteria + &amp;quot;item_type = '#{item_type}' AND &amp;quot; if item_type &amp;amp;&amp;amp; !(item_type.eql? 'Any')&lt;br /&gt;
    criteria = criteria + &amp;quot;event = '#{event}' AND &amp;quot; if event &amp;amp;&amp;amp; !(event.eql? 'Any')&lt;br /&gt;
    criteria = criteria + &amp;quot;created_at &amp;gt;= '#{time_to_string(params[:start_time])}' AND &amp;quot;&lt;br /&gt;
    criteria = criteria + &amp;quot;created_at &amp;lt;= '#{time_to_string(params[:end_time])}' AND &amp;quot;&lt;br /&gt;
&lt;br /&gt;
    if current_role == 'Instructor' || current_role == 'Administrator'&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # Remove the last ' AND '&lt;br /&gt;
    criteria = criteria[0..-5]&lt;br /&gt;
&lt;br /&gt;
    versions = Version.page(params[:page]).order('id').per_page(25).where(criteria)&lt;br /&gt;
    versions&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* '''Solution''': The implementation has been changed in such a way that the versions which a user is allowed to see depends on the privileges of the user. The approach we have taken is as follows:&lt;br /&gt;
**An administrator can see all the versions&lt;br /&gt;
**An instructor can see all the versions created by him and other users who are in his course or are participants in the assignments he creates.&lt;br /&gt;
**A TA can see all the versions created by him and other users who are in the course for which he/ she assists.&lt;br /&gt;
**A Student can see all the versions created by him/ her.&lt;br /&gt;
* '''Problem 2''': The search criteria created in the method paginate_list was difficult to comprehend.&lt;br /&gt;
::The code which builds the search criteria in the method paginate_list uses many string literals and conditions and is hardly intuitive. The programmer will have to spend some time to understand what the code is really doing.&lt;br /&gt;
* '''Solution''': The implementation has been changed. A student is not allowed to delete any versions now. Other types of users, for instance administrators, instructors and TAs are allowed to delete only the versions they are authorized to view.&lt;br /&gt;
* '''Problem 3''': The paginate method can be moved to a helper class.&lt;br /&gt;
::VersionsController is not the only component which require to paginate items. There are other components too. For instance, the UsersController has to paginate the list of users. Hence the Paginate method can be moved to a helper class which can be accessed by other components as well.&lt;br /&gt;
* '''Solution''': The filtering options has also been enhanced. The current user can now choose as part of the version search filter any user from a list of users if the current user is authorized to see the versions created by that user.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===New Implementation===&lt;br /&gt;
*The method paginate_list has been split into 2 methods now. &lt;br /&gt;
** BuildSearchCriteria – as the name suggests the sole purpose of this method is to build a search criteria based on the input search filters when the current user initiates a search in versions.&lt;br /&gt;
** paginate_list – this method will call the paginate API.&lt;br /&gt;
:First the search criteria is built, then the criteria is applied to versions in the database to get all versions which matches the criteria and then the retrieved versions are paginated.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # pagination.&lt;br /&gt;
  def paginate_list(versions)&lt;br /&gt;
    paginate(versions, VERSIONS_PER_PAGE);&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def BuildSearchCriteria(id, user_id, item_type, event)&lt;br /&gt;
    # Set up the search criteria&lt;br /&gt;
    search_criteria = ''&lt;br /&gt;
    search_criteria = search_criteria + add_id_filter_if_valid(id).to_s&lt;br /&gt;
    if current_user_role? == 'Super-Administrator'&lt;br /&gt;
      search_criteria = search_criteria + add_user_filter_for_super_admin(user_id).to_s&lt;br /&gt;
    end&lt;br /&gt;
    search_criteria = search_criteria + add_user_filter&lt;br /&gt;
    search_criteria = search_criteria + add_version_type_filter(item_type).to_s&lt;br /&gt;
    search_criteria = search_criteria + add_event_filter(event).to_s&lt;br /&gt;
    search_criteria = search_criteria + add_date_time_filter&lt;br /&gt;
    search_criteria&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The string literals and conditions in the method paginate_list were replaced with methods with intuitive names so that the programmer can understand the code more easily. We also removed an empty if clause and a redundant statement.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def add_id_filter_if_valid (id)&lt;br /&gt;
    &amp;quot;id = #{id} AND &amp;quot; if id &amp;amp;&amp;amp; id.to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_user_filter_for_super_admin (user_id)&lt;br /&gt;
    &amp;quot;whodunnit = #{user_id} AND &amp;quot; if user_id &amp;amp;&amp;amp; user_id.to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_user_filter&lt;br /&gt;
    &amp;quot;whodunnit = #{current_user.try(:id)} AND &amp;quot; if current_user.try(:id) &amp;amp;&amp;amp; current_user.try(:id).to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_event_filter (event)&lt;br /&gt;
    &amp;quot;event = '#{event}' AND &amp;quot; if event &amp;amp;&amp;amp; !(event.eql? 'Any')&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_date_time_filter&lt;br /&gt;
    &amp;quot;created_at &amp;gt;= '#{time_to_string(params[:start_time])}' AND &amp;quot; +&lt;br /&gt;
        &amp;quot;created_at &amp;lt;= '#{time_to_string(params[:end_time])}'&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_version_type_filter (version_type)&lt;br /&gt;
    &amp;quot;item_type = '#{version_type}' AND &amp;quot; if version_type &amp;amp;&amp;amp; !(version_type.eql? 'Any')&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The paginate method has been moved to the helper class Pagination_Helper. This new method can be now reused by the different components like UsersController etc. The method receives two parameters, first the list to paginate and second the number of items to be displayed in a page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module PaginationHelper&lt;br /&gt;
&lt;br /&gt;
  def paginate (items, number_of_items_per_page)&lt;br /&gt;
    items.page(params[:page]).per_page(number_of_items_per_page)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Code improvements===&lt;br /&gt;
* Introduced a constant VERSIONS_PER_PAGE and assigned the value 25 to it. The pagination algorithm for VersionsController displays at most 25 versions in a page. The existing implementation uses the value 25 straight in the code and there are few problems associated with such an approach.&lt;br /&gt;
** It is not easy to understand what 25 is unless the programmer takes a close look at the code.&lt;br /&gt;
** In case if the value 25 is used at more than one places and in future a new requirement comes to show at most 30 versions in a page, all the values will have to be modified. It is not very DRY.&lt;br /&gt;
* The VersionsController was overriding AccessHelper - action_allowed? method to return true in all the cases. This was violating the whole purpose of the method action_allowed?. The purpose of this method is to determine whether the user who is triggering a CRUD operation is allowed to do so. So when the current user invokes a CRUD operation, the action_allowed? method is invoked first and if the method returns true the CRUD operation is triggered or else the user is intimated with a message and gracefully exited. Hence, when the action_allowed? method is overridden to return true always, it results in providing unauthorized access to certain users.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def action_allowed?&lt;br /&gt;
    true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:With the new implementation the AccessHelper - action_allowed? method has been modified in such a way that unauthorized access is prevented. As per the new algorithm, 'new', 'create', 'edit', 'update' cannot be invoked by any user. These operations can be accessed only by ‘papertrail’ gem. Only an ‘Administrator’ or ‘Super-Administrator’ can call 'destroy_all' method. All the other methods are accessible to ‘Administrator’,  ‘Super-Administrator’, ‘Instructor’, ‘Teaching Assistant’ and ‘Student’.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    case params[:action]&lt;br /&gt;
    when 'new', 'create', 'edit', 'update'&lt;br /&gt;
    #Modifications can only be done by papertrail&lt;br /&gt;
      return false&lt;br /&gt;
    when 'destroy_all'&lt;br /&gt;
      ['Super-Administrator',&lt;br /&gt;
       'Administrator'].include? current_role_name&lt;br /&gt;
    else&lt;br /&gt;
      #Allow all others&lt;br /&gt;
      ['Super-Administrator',&lt;br /&gt;
       'Administrator',&lt;br /&gt;
       'Instructor',&lt;br /&gt;
       'Teaching Assistant',&lt;br /&gt;
       'Student'].include? current_role_name&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/WintersLt/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[http://bit.ly/myexpertiza  Demo link] - This might not be available after May of 2015&lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1553_AAJ&amp;diff=97422</id>
		<title>CSC/ECE 517 Fall 2015/oss E1553 AAJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1553_AAJ&amp;diff=97422"/>
		<updated>2015-10-31T01:11:48Z</updated>

		<summary type="html">&lt;p&gt;Asayal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1553. Refactoring the Versions Controller==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Introduction to Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a large project developed as a combined effort of students and faculty using the [http://rubyonrails.org/ Ruby on Rails] framework. The main advantage of using Expertiza, in an educational environment, is for the instructor to introduce peer reviewing among the students. Expertiza allows the instructor to create and customize assignments, create a list of topics the students can sign up for, have students work on teams and then review each other's assignments at the end. Expertiza supports submission of almost any document type, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the [http://www.ncsu.edu/ NCSU] [http://litre.ncsu.edu/ Learning in a Technology-Rich Environment] (LITRE) program, the NCSU [http://ofd.ncsu.edu/teaching-learning/ Faculty Center for Teaching and Learning], the NCSU [http://stem.ncsu.edu/ STEM] Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
Pagination of versions helps the user to view a subset of versions at a time. Considering the huge number of versions in the system, it is very useful to have a pagination mechanism and a filtering mechanism which can be applied on the whole set of versions. The idea is to display the versions in an ordered, comprehensible and logical manner. In Expertiza the gem ‘will_paginate’ is used to achieve pagination.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Current Implementation===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Functionality====&lt;br /&gt;
* Any user irrespective of his/ her privileges can view all the versions.&lt;br /&gt;
::The versions which a particular user can view should be restricted based on the privileges of the user. For instance, only a user with Administrator privileges should be able to view all the versions in the system. However, that is not the case now. Every user can view all the versions irrespective of whether the user is a student or an administrator.&lt;br /&gt;
* Any user can delete any version&lt;br /&gt;
::The versions which a particular user can delete should be restricted based on the privileges of the user. For instance, a student should not be allowed to delete any version. According to the current implementation any user can delete any version in the system.&lt;br /&gt;
* Filtering of versions were restricted to the current user&lt;br /&gt;
::The filtering options on versions were restricted to the current user. Sometimes a user might want to view versions associated with other users. For instance, an instructor might want to view the list of versions created by a particular student. This is not possible with the current implementation.&lt;br /&gt;
&lt;br /&gt;
====Drawbacks and Solutions====&lt;br /&gt;
* '''Problem 1''': The method paginate_list is doing more than one thing.&lt;br /&gt;
::The method paginate_list was building a complex search criteria based on the input params, getting the list of versions from the Database matching this search criteria and then calling the Page API. All these tasks in a single method made it difficult to understand.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# For filtering the versions list with proper search and pagination.&lt;br /&gt;
  def paginate_list(id, user_id, item_type, event, datetime)&lt;br /&gt;
    # Set up the search criteria&lt;br /&gt;
    criteria = ''&lt;br /&gt;
    criteria = criteria + &amp;quot;id = #{id} AND &amp;quot; if id &amp;amp;&amp;amp; id.to_i &amp;gt; 0&lt;br /&gt;
    if current_user_role? == 'Super-Administrator'&lt;br /&gt;
      criteria = criteria + &amp;quot;whodunnit = #{user_id} AND &amp;quot; if user_id &amp;amp;&amp;amp; user_id.to_i &amp;gt; 0&lt;br /&gt;
    end&lt;br /&gt;
    criteria = criteria + &amp;quot;whodunnit = #{current_user.try(:id)} AND &amp;quot; if current_user.try(:id) &amp;amp;&amp;amp; current_user.try(:id).to_i &amp;gt; 0&lt;br /&gt;
    criteria = criteria + &amp;quot;item_type = '#{item_type}' AND &amp;quot; if item_type &amp;amp;&amp;amp; !(item_type.eql? 'Any')&lt;br /&gt;
    criteria = criteria + &amp;quot;event = '#{event}' AND &amp;quot; if event &amp;amp;&amp;amp; !(event.eql? 'Any')&lt;br /&gt;
    criteria = criteria + &amp;quot;created_at &amp;gt;= '#{time_to_string(params[:start_time])}' AND &amp;quot;&lt;br /&gt;
    criteria = criteria + &amp;quot;created_at &amp;lt;= '#{time_to_string(params[:end_time])}' AND &amp;quot;&lt;br /&gt;
&lt;br /&gt;
    if current_role == 'Instructor' || current_role == 'Administrator'&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # Remove the last ' AND '&lt;br /&gt;
    criteria = criteria[0..-5]&lt;br /&gt;
&lt;br /&gt;
    versions = Version.page(params[:page]).order('id').per_page(25).where(criteria)&lt;br /&gt;
    versions&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* '''Solution''': The implementation has been changed in such a way that the versions which a user is allowed to see depends on the privileges of the user. The approach we have taken is as follows:&lt;br /&gt;
**An administrator can see all the versions&lt;br /&gt;
**An instructor can see all the versions created by him and other users who are in his course or are participants in the assignments he creates.&lt;br /&gt;
**A TA can see all the versions created by him and other users who are in the course for which he/ she assists.&lt;br /&gt;
**A Student can see all the versions created by him/ her.&lt;br /&gt;
* '''Problem 2''': The search criteria created in the method paginate_list was difficult to comprehend.&lt;br /&gt;
::The code which builds the search criteria in the method paginate_list uses many string literals and conditions and is hardly intuitive. The programmer will have to spend some time to understand what the code is really doing.&lt;br /&gt;
* '''Solution''': The implementation has been changed. A student is not allowed to delete any versions now. Other types of users, for instance administrators, instructors and TAs are allowed to delete only the versions they are authorized to view.&lt;br /&gt;
* '''Problem 3''': The paginate method can be moved to a helper class.&lt;br /&gt;
::VersionsController is not the only component which require to paginate items. There are other components too. For instance, the UsersController has to paginate the list of users. Hence the Paginate method can be moved to a helper class which can be accessed by other components as well.&lt;br /&gt;
* '''Solution''': The filtering options has also been enhanced. The current user can now choose as part of the version search filter any user from a list of users if the current user is authorized to see the versions created by that user.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===New Implementation===&lt;br /&gt;
*The method paginate_list has been split into 2 methods now. &lt;br /&gt;
** BuildSearchCriteria – as the name suggests the sole purpose of this method is to build a search criteria based on the input search filters when the current user initiates a search in versions.&lt;br /&gt;
** paginate_list – this method will call the paginate API.&lt;br /&gt;
:First the search criteria is built, then the criteria is applied to versions in the database to get all versions which matches the criteria and then the retrieved versions are paginated.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # pagination.&lt;br /&gt;
  def paginate_list(versions)&lt;br /&gt;
    paginate(versions, VERSIONS_PER_PAGE);&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def BuildSearchCriteria(id, user_id, item_type, event)&lt;br /&gt;
    # Set up the search criteria&lt;br /&gt;
    search_criteria = ''&lt;br /&gt;
    search_criteria = search_criteria + add_id_filter_if_valid(id).to_s&lt;br /&gt;
    if current_user_role? == 'Super-Administrator'&lt;br /&gt;
      search_criteria = search_criteria + add_user_filter_for_super_admin(user_id).to_s&lt;br /&gt;
    end&lt;br /&gt;
    search_criteria = search_criteria + add_user_filter&lt;br /&gt;
    search_criteria = search_criteria + add_version_type_filter(item_type).to_s&lt;br /&gt;
    search_criteria = search_criteria + add_event_filter(event).to_s&lt;br /&gt;
    search_criteria = search_criteria + add_date_time_filter&lt;br /&gt;
    search_criteria&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The string literals and conditions in the method paginate_list were replaced with methods with intuitive names so that the programmer can understand the code more easily. We also removed an empty if clause and a redundant statement.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def add_id_filter_if_valid (id)&lt;br /&gt;
    &amp;quot;id = #{id} AND &amp;quot; if id &amp;amp;&amp;amp; id.to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_user_filter_for_super_admin (user_id)&lt;br /&gt;
    &amp;quot;whodunnit = #{user_id} AND &amp;quot; if user_id &amp;amp;&amp;amp; user_id.to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_user_filter&lt;br /&gt;
    &amp;quot;whodunnit = #{current_user.try(:id)} AND &amp;quot; if current_user.try(:id) &amp;amp;&amp;amp; current_user.try(:id).to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_event_filter (event)&lt;br /&gt;
    &amp;quot;event = '#{event}' AND &amp;quot; if event &amp;amp;&amp;amp; !(event.eql? 'Any')&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_date_time_filter&lt;br /&gt;
    &amp;quot;created_at &amp;gt;= '#{time_to_string(params[:start_time])}' AND &amp;quot; +&lt;br /&gt;
        &amp;quot;created_at &amp;lt;= '#{time_to_string(params[:end_time])}'&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_version_type_filter (version_type)&lt;br /&gt;
    &amp;quot;item_type = '#{version_type}' AND &amp;quot; if version_type &amp;amp;&amp;amp; !(version_type.eql? 'Any')&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The paginate method has been moved to the helper class Pagination_Helper. This new method can be now reused by the different components like UsersController etc. The method receives two parameters, first the list to paginate and second the number of items to be displayed in a page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module PaginationHelper&lt;br /&gt;
&lt;br /&gt;
  def paginate (items, number_of_items_per_page)&lt;br /&gt;
    items.page(params[:page]).per_page(number_of_items_per_page)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Code improvements===&lt;br /&gt;
* Introduced a constant VERSIONS_PER_PAGE and assigned the value 25 to it. The pagination algorithm for VersionsController displays at most 25 versions in a page. The existing implementation uses the value 25 straight in the code and there are few problems associated with such an approach.&lt;br /&gt;
** It is not easy to understand what 25 is unless the programmer takes a close look at the code.&lt;br /&gt;
** In case if the value 25 is used at more than one places and in future a new requirement comes to show at most 30 versions in a page, all the values will have to be modified. It is not very DRY.&lt;br /&gt;
* The VersionsController was overriding AccessHelper - action_allowed? method to return true in all the cases. This was violating the whole purpose of the method action_allowed?. The purpose of this method is to determine whether the user who is triggering a CRUD operation is allowed to do so. So when the current user invokes a CRUD operation, the action_allowed? method is invoked first and if the method returns true the CRUD operation is triggered or else the user is intimated with a message and gracefully exited. Hence, when the action_allowed? method is overridden to return true always, it results in providing unauthorized access to certain users.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def action_allowed?&lt;br /&gt;
    true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:With the new implementation the AccessHelper - action_allowed? method has been modified in such a way that unauthorized access is prevented. As per the new algorithm, 'new', 'create', 'edit', 'update' cannot be invoked by any user. These operations can be accessed only by ‘papertrail’ gem. Only an ‘Administrator’ or ‘Super-Administrator’ can call 'destroy_all' method. All the other methods are accessible to ‘Administrator’,  ‘Super-Administrator’, ‘Instructor’, ‘Teaching Assistant’ and ‘Student’.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    case params[:action]&lt;br /&gt;
    when 'new', 'create', 'edit', 'update'&lt;br /&gt;
    #Modifications can only be done by papertrail&lt;br /&gt;
      return false&lt;br /&gt;
    when 'destroy_all'&lt;br /&gt;
      ['Super-Administrator',&lt;br /&gt;
       'Administrator'].include? current_role_name&lt;br /&gt;
    else&lt;br /&gt;
      #Allow all others&lt;br /&gt;
      ['Super-Administrator',&lt;br /&gt;
       'Administrator',&lt;br /&gt;
       'Instructor',&lt;br /&gt;
       'Teaching Assistant',&lt;br /&gt;
       'Student'].include? current_role_name&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Asayal</name></author>
	</entry>
</feed>