Index: /sandbox/2.4.1-3/prototype/config/contactGroup.ini
===================================================================
--- /sandbox/2.4.1-3/prototype/config/contactGroup.ini	(revision 6429)
+++ /sandbox/2.4.1-3/prototype/config/contactGroup.ini	(revision 6437)
@@ -8,3 +8,4 @@
 id  = id_group
 user = owner
-name = title 
+name = title
+email = short_name 
Index: /sandbox/2.4.1-3/prototype/modules/catalog/interceptors/DBMapping.php
===================================================================
--- /sandbox/2.4.1-3/prototype/modules/catalog/interceptors/DBMapping.php	(revision 6396)
+++ /sandbox/2.4.1-3/prototype/modules/catalog/interceptors/DBMapping.php	(revision 6437)
@@ -1,3 +1,3 @@
-<?php
+ <?php
 
 //Definindo Constantes
@@ -13,34 +13,70 @@
     public function findConnections(&$uri, &$params, &$criteria, $original) {
 
-	if(count($params)>0 && isset($params[0]['id'])){
-		for($i=0; $i < count($params); $i++){
-			//Retorna o telefone e o e-mail padrao de um determinado contato
-			$sql = ' SELECT phpgw_cc_contact_conns.id_typeof_contact_connection as type, phpgw_cc_connections.connection_value as value '
-				.'FROM phpgw_cc_contact_conns '
-				.'JOIN phpgw_cc_connections '
-				.'ON (phpgw_cc_connections.id_connection = phpgw_cc_contact_conns.id_connection) '
-				.'WHERE phpgw_cc_contact_conns.id_contact = ' . $params[$i]['id'] . ' AND '
-				.'phpgw_cc_connections.connection_is_default = TRUE ';
+		if(count($params)>0 && isset($params[0]['id'])){
+			for($i=0; $i < count($params); $i++){
+				//Retorna o telefone e o e-mail padrao de um determinado contato
+				$sql = ' SELECT phpgw_cc_contact_conns.id_typeof_contact_connection as type, phpgw_cc_connections.connection_value as value '
+					.'FROM phpgw_cc_contact_conns '
+					.'JOIN phpgw_cc_connections '
+					.'ON (phpgw_cc_connections.id_connection = phpgw_cc_contact_conns.id_connection) '
+					.'WHERE phpgw_cc_contact_conns.id_contact = ' . $params[$i]['id'] . ' AND '
+					.'phpgw_cc_connections.connection_is_default = TRUE ';
 
-			$array = Controller::service('PostgreSQL')->execResultSql($sql);
-			if(count($array)>0){
-				foreach($array as $connection){
-					switch($connection['type']){
-						case TYPE_EMAIL 	: $params[$i][INDEX_EMAIL] 	= $connection['value']; break;
-						case TYPE_TELEPHONE 	: $params[$i][INDEX_TELEPHONE] 	= $connection['value']; break;
-					
-						default			: $params[$i][INDEX_EMAIL] = $params[$i][INDEX_TELEPHONE] = '';
+				$array = Controller::service('PostgreSQL')->execResultSql($sql);
+				if(count($array)>0){
+					foreach($array as $connection){
+						switch($connection['type']){
+							case TYPE_EMAIL 	: $params[$i][INDEX_EMAIL] 	= $connection['value']; break;
+							case TYPE_TELEPHONE 	: $params[$i][INDEX_TELEPHONE] 	= $connection['value']; break;
+							default			: $params[$i][INDEX_EMAIL] = $params[$i][INDEX_TELEPHONE] = '';
+						}
+
 					}
-
+				}
+				else{
+					$params[$i][INDEX_EMAIL] = $params[$i][INDEX_TELEPHONE] = '';
 				}
 			}
-			else{
-				$params[$i][INDEX_EMAIL] = $params[$i][INDEX_TELEPHONE] = '';
+		}
+    }
+
+	public function findGroupConnections(&$uri, &$params, &$criteria, $original) {
+
+		if(count($params)>0 && isset($params[0]['id'])){
+		$z = 0;
+		$count = count($params);
+		for($i=0; $i < $count; $i++){
+				//Retorna o telefone e o e-mail padrao de um determinado contato
+				$sql = 'SELECT contato.names_ordered as name, contato.id_contact as id, conexao.connection_value as value '
+					.'FROM phpgw_cc_groups grupo '
+					.'JOIN phpgw_cc_contact_grps grupo_contato '
+					.'ON (grupo.id_group = grupo_contato.id_group) '
+					.'JOIN phpgw_cc_connections conexao '
+					.'ON (grupo_contato.id_connection = conexao.id_connection) '
+					.'JOIN phpgw_cc_contact_conns conexaoCon '
+					.'ON (conexao.id_connection = conexaoCon.id_connection) '
+					.'JOIN phpgw_cc_contact contato '
+					.'ON (contato.id_contact = conexaoCon.id_contact) '
+					.'WHERE grupo.id_group = ' . $params[$i]['id'] . ' AND '
+					.'conexao.connection_is_default = TRUE';
+
+				$array = Controller::service('PostgreSQL')->execResultSql($sql);
+
+				if(count($array)>0){
+					$params[$i]['contacts'][$z] = array();
+					foreach($array as $connection){
+						$params[$i]['contacts'][$z]['id'] = $connection['id'];		
+						$params[$i]['contacts'][$z]['name'] = $connection['name'];							
+						$params[$i]['contacts'][$z][INDEX_EMAIL] = $connection['value'];							
+						$z++;
+					}
+				}
+				else{
+					$params[$i][INDEX_EMAIL] = '';
+				}
 			}
 		}
-	}
-	return false;
     }
-
+	
 }
 
Index: /sandbox/2.4.1-3/prototype/rest/hypermedia/collection.php
===================================================================
--- /sandbox/2.4.1-3/prototype/rest/hypermedia/collection.php	(revision 6429)
+++ /sandbox/2.4.1-3/prototype/rest/hypermedia/collection.php	(revision 6437)
@@ -7,15 +7,27 @@
 include_once('query.php');
 include_once('error.php');
+/*
+Valores padrão
 
+Números são enviados como números, sem aspas;
+Atributos não obrigatórios sem valor serão nulos;
+Strings vazias serão nulos;
+Todos os indices / chaves estarão sempre presentes na mensagem;
+Arrays vazios serão nulos;
+Objetos vazios serão nulos;
+Números sem valor serão nulos;
+valores booleanos são escritos como booleanos (sem aspas);
+*/
 class Collection {
 
-    public $itens = array();
+    public $itens;
     public $href;
     public $error;
     public $pagination;
-    public $queries = array();
+    public $queries;
     public $template;
     public $type;
-    public $data = array();
+    public $data;
+	public $links;
 
     function __construct($config, $className) {
@@ -29,4 +41,8 @@
     }
 
+	function addLink($link) {
+	$this->links[] = $link;
+    }
+	
     function addItem($item) {
 	$this->itens[] = $item;
Index: /sandbox/2.4.1-3/prototype/rest/catalog/ContactResource.php
===================================================================
--- /sandbox/2.4.1-3/prototype/rest/catalog/ContactResource.php	(revision 6429)
+++ /sandbox/2.4.1-3/prototype/rest/catalog/ContactResource.php	(revision 6437)
@@ -48,120 +48,103 @@
 		return $response;
 	    }
-
-            foreach($contact as $value){
+			
+		$t = new Template();
 		$d = new Data();
-                $i = new Item($request->resources, 'ContactResource', $value['id']);
 
 		$d->setName('name');
-                $d->setValue($value['name']);
-                $d->setPrompt('Nome do Contato');
-                $d->setDataType('string');
-                $d->setMaxLength('100');
-                $d->setMinLength(null);
-                $d->setRequired(true);
+		$d->setValue(null);
+		$d->setPrompt('Nome do Contato');
+		$d->setDataType('string');
+		$d->setMaxLength(100);
+		$d->setMinLength(null);
+		$d->setRequired(true);
 
-                $i->addData($d);
+		$t->addData($d);
 
 		$d = new Data();
-                $d->setName('email');
-                $d->setValue($value['email']);
-                $d->setPrompt('Email do Contato');
-                $d->setDataType('string');
-                $d->setMaxLength('100');
-                $d->setMinLength(null);
-                $d->setRequired(true);
+		$d->setName('email');
+		$d->setValue(null);
+		$d->setPrompt('Email do Contato');
+		$d->setDataType('string');
+		$d->setMaxLength(100);
+		$d->setMinLength(null);
+		$d->setRequired(true);
 
-                $i->addData($d);
+		$t->addData($d);
 
 		$d = new Data();
-                $d->setName('telephone');
-                $d->setValue($value['telephone']);
-                $d->setPrompt('Telefone do Contato');
-                $d->setDataType('string');
-                $d->setMaxLength('100');
-                $d->setMinLength(null);
-                $d->setRequired(true);
+		$d->setName('telefone');
+		$d->setValue(null);
+		$d->setPrompt('Telefone do Contato');
+		$d->setDataType('string');
+		$d->setMaxLength(100);
+		$d->setMinLength(null);
+		$d->setRequired(true);
 
-                $i->addData($d);
+		$t->addData($d);
 
-                $l = new Link();
+		$c->setTemplate($t);
+		
+		$d = new Data();
+		$d->setName('name');
+		$d->setValue($contact[0]['name']);
+		$d->setPrompt('Nome do Contato');
+		$d->setDataType('string');
+		$d->setMaxLength('100');
+		$d->setMinLength(null);
+		$d->setRequired(true);
 
-                $l->setHref('');
-                $l->setRel('delete');
-                $l->setAlt('Remover');
-                $l->setPrompt('Remover');
-                $l->setRender('link');
+		$c->addData($d);
+		
+		$d = new Data();
+		$d->setName('email');
+		$d->setValue($value['email']);
+		$d->setPrompt('Email do Contato');
+		$d->setDataType('string');
+		$d->setMaxLength('100');
+		$d->setMinLength(null);
+		$d->setRequired(true);
 
-                $i->addLink($l);
+		$c->addData($d);
+		
+		$d = new Data();
+		$d->setName('telephone');
+		$d->setValue($value['telephone']);
+		$d->setPrompt('Telefone do Contato');
+		$d->setDataType('string');
+		$d->setMaxLength('100');
+		$d->setMinLength(null);
+		$d->setRequired(true);
 
-                $l = new Link();
-                $l->setHref('');
-                $l->setRel('put');
-                $l->setAlt('Atualizar');
-                $l->setPrompt('Atualizar');
-                $l->setRender('link');
+		$c->addData($d);
+		
+		$l = new Link();
+		$l->setHref('');
+		$l->setRel('delete');
+		$l->setAlt('Remover');
+		$l->setPrompt('Remover');
+		$l->setRender('link');
+		
+		$c->addLink($l);
+		
+		$l = new Link();
+		$l->setHref('');
+		$l->setRel('put');
+		$l->setAlt('Atualizar');
+		$l->setPrompt('Atualizar');
+		$l->setRender('link');
+		
+		$c->addLink($l);
+		
+		$l = new Link();
+		$l->setHref('/contact/'.$value['id']);
+		$l->setRel('get');
+		$l->setAlt('Buscar');
+		$l->setPrompt('Buscar');
+		$l->setRender('link');
 
-                $i->addLink($l);
-
-                $l = new Link();
-                $l->setHref('/contact/'.$value['id']);
-                $l->setRel('get');
-                $l->setAlt('Buscar');
-                $l->setPrompt('Buscar');
-                $l->setRender('link');
-
-                $i->addLink($l);
-                $c->addItem($i);
-	    }
-
-            $t = new Template();
-            $d = new Data();
-
-            $d->setName('name');
-            $d->setValue(null);
-            $d->setPrompt('Nome do Contato');
-            $d->setDataType('string');
-            $d->setMaxLength(100);
-            $d->setMinLength(null);
-            $d->setRequired(true);
-
-            $t->addData($d);
-
-            $d = new Data();
-            $d->setName('email');
-            $d->setValue(null);
-            $d->setPrompt('Email do Contato');
-            $d->setDataType('string');
-            $d->setMaxLength(100);
-            $d->setMinLength(null);
-            $d->setRequired(true);
-
-            $t->addData($d);
-
-            $d = new Data();
-            $d->setName('telefone');
-            $d->setValue(null);
-            $d->setPrompt('Telefone do Contato');
-            $d->setDataType('string');
-            $d->setMaxLength(100);
-            $d->setMinLength(null);
-            $d->setRequired(true);
-
-            $t->addData($d);
-
-            $c->setTemplate($t);
-
-            $d = new Data();
-            $d->setName('Contato');
-            $d->setValue(null);
-            $d->setPrompt('Contato');
-            $d->setDataType(null);
-            $d->setMaxLength(null);
-            $d->setMinLength(null);
-            $d->setRequired(null);
-
-            $c->addData($d);
-
-            $h->setCollection($c);
+		$c->addLink($l);
+			
+		$h->setCollection($c);
 
 	}catch (Exception $ex){
Index: /sandbox/2.4.1-3/prototype/rest/catalog/GroupResource.php
===================================================================
--- /sandbox/2.4.1-3/prototype/rest/catalog/GroupResource.php	(revision 6437)
+++ /sandbox/2.4.1-3/prototype/rest/catalog/GroupResource.php	(revision 6437)
@@ -0,0 +1,252 @@
+<?php
+
+if( !defined( 'ROOTPATH' ) )
+    define( 'ROOTPATH', dirname(__FILE__).'/..' );
+
+require_once(ROOTPATH.'/rest/hypermedia/hypermedia.php');
+
+use prototype\api\Config as Config;
+
+class GroupResource extends Resource {
+
+    /**
+     * Retorna uma lista de usuários
+     *
+     * @license    http://www.gnu.org/copyleft/gpl.html GPL
+     * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
+     * @sponsor    Caixa Econômica Federal
+     * @author     José Vicente Tezza Jr. 
+     * @return     Retorna uma lista de usuários do LDAP
+     * @access     public
+     * */
+    function get($request, $id) {
+
+	$response = new Response($request);
+	$response->addHeader('Content-type', 'aplication/json');
+	$response->code = Response::OK;
+
+	$h = new Hypermedia();
+	$c = new Collection($request->resources, 'GroupResource');
+
+	try {
+	    $this->secured();
+
+            $group = Controller::find( array( 'concept' => 'contactGroup' ), false, array( 'filter' => array( 'AND', array('=', 'user',  Config::me("uidNumber") ), array('=', 'id', $id) )  ) );
+
+	    //Se nao foi encontrado contatos na consulta
+	    if($group===false){
+		$error = new Error();
+		$error->setCode(Response::NOTFOUND);
+		$error->setTitle('Group not found');
+		$error->setDescription('Group not found.');
+
+		$c->setError($error);
+		$h->setCollection($c);
+
+		$response->code = Response::NOTFOUND;
+		$response->body = $h->getHypermedia($request->accept[10][0]);
+		return $response;
+	    }
+		
+ob_start();
+print_r( "=== LOG BEGIN group===" . "\n" );
+print_r(  $group);
+print_r( "=== LOG BEGIN group2===" . "\n" );
+print_r(  $group[0]['contacts']);
+print_r( "\n=== LOG END ===" . "\n" );
+$output = ob_get_clean();
+file_put_contents( '/tmp/log-gustavo2.txt', file_get_contents( '/tmp/log-gustavo2.txt' ) . $output );
+
+		foreach($group[0]['contacts'] as $value){
+			$d = new Data();
+			$i = new Item($request->resources, 'ContactResource', $value['id']);
+
+			$d->setName('name');
+			$d->setValue($value['name']);
+			$d->setPrompt('Nome do Grupo');
+			$d->setDataType('string');
+			$d->setMaxLength('100');
+			$d->setMinLength(null);
+			$d->setRequired(true);
+
+			$i->addData($d);
+
+			$d = new Data();
+			$d->setName('id');
+			$d->setValue($value['id']);
+			$d->setPrompt('Id do Contato');
+			$d->setDataType('string');
+			$d->setMaxLength('100');
+			$d->setMinLength(null);
+			$d->setRequired(true);
+
+			$i->addData($d);
+
+			$d = new Data();
+			$d->setName('email');
+			$d->setValue($value['email']);
+			$d->setPrompt('Email do Contato');
+			$d->setDataType('string');
+			$d->setMaxLength('100');
+			$d->setMinLength(null);
+			$d->setRequired(true);
+
+			$i->addData($d);
+
+			$l = new Link();
+
+			$l->setHref('');
+			$l->setRel('delete');
+			$l->setAlt('Remover');
+			$l->setPrompt('Remover');
+			$l->setRender('link');
+
+			$i->addLink($l);
+
+			$l = new Link();
+			$l->setHref('');
+			$l->setRel('put');
+			$l->setAlt('Atualizar');
+			$l->setPrompt('Atualizar');
+			$l->setRender('link');
+
+			$i->addLink($l);
+
+			$l = new Link();
+			$l->setHref('/contact/'.$value['id']);
+			$l->setRel('get');
+			$l->setAlt('Buscar');
+			$l->setPrompt('Buscar');
+			$l->setRender('link');
+
+			$i->addLink($l);
+			$c->addItem($i);
+	    }
+
+		$t = new Template();
+		$d = new Data();
+
+		$d->setName('name');
+		$d->setValue(null);
+		$d->setPrompt('Nome do Contato');
+		$d->setDataType('string');
+		$d->setMaxLength(100);
+		$d->setMinLength(null);
+		$d->setRequired(true);
+
+		$t->addData($d);
+
+		$d = new Data();
+		$d->setName('email');
+		$d->setValue(null);
+		$d->setPrompt('Email do Contato');
+		$d->setDataType('string');
+		$d->setMaxLength(100);
+		$d->setMinLength(null);
+		$d->setRequired(true);
+
+		$t->addData($d);
+
+		$d = new Data();
+		$d->setName('telefone');
+		$d->setValue(null);
+		$d->setPrompt('Telefone do Contato');
+		$d->setDataType('string');
+		$d->setMaxLength(100);
+		$d->setMinLength(null);
+		$d->setRequired(true);
+
+		$t->addData($d);
+
+		$c->setTemplate($t);
+
+		$d = new Data();
+		$d->setName('id');
+		$d->setValue($group[0]['id']);
+		$d->setPrompt('Id do Grupo');
+		$d->setDataType('string');
+		$d->setMaxLength(100);
+		$d->setMinLength(null);
+		$d->setRequired(true);
+
+		$c->addData($d);
+
+		$d = new Data();
+		$d->setName('name');
+		$d->setValue($group[0]['name']);
+		$d->setPrompt('Nome do Grupo');
+		$d->setDataType('string');
+		$d->setMaxLength(100);
+		$d->setMinLength(null);
+		$d->setRequired(true);
+
+		$c->addData($d);
+		
+		$d = new Data();
+		$d->setName('email');
+		$d->setValue($group[0]['email']);
+		$d->setPrompt('Email do Grupo');
+		$d->setDataType('string');
+		$d->setMaxLength(100);
+		$d->setMinLength(null);
+		$d->setRequired(true);
+
+		$c->addData($d);	
+		
+		$l = new Link();
+		$l->setHref('/group/'.$group[0]['id']);
+		$l->setRel('get');
+		$l->setAlt('Buscar');
+		$l->setPrompt('Buscar');
+		$l->setRender('link');
+
+		$c->addLink($l);
+			
+		$l = new Link();
+		$l->setHref(null);
+		$l->setRel('put');
+		$l->setAlt('Edit');
+		$l->setRender('link');
+		$l->setPrompt('Editar');
+
+		$c->addLink($l);
+		
+		$l = new Link();
+		$l->setHref(null);
+		$l->setRel('post');
+		$l->setAlt('Create');
+		$l->setRender('link');
+		$l->setPrompt('Criar');
+
+		$c->addLink($l);
+		
+		$l = new Link();
+		$l->setHref(null);
+		$l->setRel('delete');
+		$l->setAlt('Delete');
+		$l->setRender('link');
+		$l->setPrompt('Remover');
+
+		$c->addLink($l);
+		
+		$h->setCollection($c);
+
+	}catch (Exception $ex){
+		$error = new Error();
+		$error->setCode(Response::INTERNALSERVERERROR);
+		$error->setTitle('Internal Server Error');
+		$error->setDescription($ex);
+
+		$c->setError($error);
+		$h->setCollection($c);
+
+		$response->code = Response::INTERNALSERVERERROR;
+		$response->body = $h->getHypermedia($request->accept[10][0]);
+		return $response;
+	}
+
+	$response->body = $h->getHypermedia($request->accept[10][0]);
+	return $response;
+  }
+}
+?>
Index: /sandbox/2.4.1-3/prototype/rest/catalog/ContactsResource.php
===================================================================
--- /sandbox/2.4.1-3/prototype/rest/catalog/ContactsResource.php	(revision 6429)
+++ /sandbox/2.4.1-3/prototype/rest/catalog/ContactsResource.php	(revision 6437)
@@ -152,15 +152,4 @@
             $c->setTemplate($t);
 
-            $d = new Data();
-            $d->setName('Contato');
-            $d->setValue(null);
-            $d->setPrompt('Contato');
-            $d->setDataType(null);
-            $d->setMaxLength(null);
-            $d->setMinLength(null);
-            $d->setRequired(null);
-
-            $c->addData($d);
-
             $h->setCollection($c);
 
Index: /sandbox/2.4.1-3/prototype/rest/user/UsersResource.php
===================================================================
--- /sandbox/2.4.1-3/prototype/rest/user/UsersResource.php	(revision 6429)
+++ /sandbox/2.4.1-3/prototype/rest/user/UsersResource.php	(revision 6437)
@@ -185,17 +185,4 @@
 		$t->addData($d);
 
-		$c->setTemplate($t);
-
-		$d = new Data();
-		$d->setName('Usuario LDAP');
-		$d->setValue(null);
-		$d->setPrompt('Usuario do LDAP');
-		$d->setDataType(null);
-		$d->setMaxLength(null);
-		$d->setMinLength(null);
-		$d->setRequired(null);
-
-		$c->addData($d);
-
 	    $queries = new Querie();    
 		$queries->setHref($c->href);
