/* Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.camunda.bpm.engine.rest.dto.identity;

import java.net.URI;
import java.util.ArrayList;
import java.util.List;

import javax.ws.rs.core.UriBuilder;

import org.camunda.bpm.engine.identity.User;
import org.camunda.bpm.engine.rest.ProcessInstanceRestService;
import org.camunda.bpm.engine.rest.UserRestService;
import org.camunda.bpm.engine.rest.dto.AtomLink;
import org.camunda.bpm.engine.rest.dto.LinkableDto;

/**
 * @author Daniel Meyer
 *
 */
public class UserProfileDto extends LinkableDto {

  protected String id;
  protected String firstName;
  protected String lastName;
  protected String email;
    
  // transformers ////////////////////////////////////////
  
  public static UserProfileDto fromUser(User user) {
    UserProfileDto result = new UserProfileDto();
    result.id = user.getId();
    result.firstName = user.getFirstName();
    result.lastName = user.getLastName();
    result.email = user.getEmail();
    return result;
  }
  
  public static List<UserProfileDto> fromUserList(List<User> sourceList) {
    List<UserProfileDto> resultList = new ArrayList<UserProfileDto>(); 
    for (User user : sourceList) {
      resultList.add(fromUser(user));
    }
    return resultList;
  }
  
  public void update(User dbUser) {  
    dbUser.setId(getId());
    dbUser.setFirstName(getFirstName());
    dbUser.setLastName(getLastName());
    dbUser.setEmail(getEmail());
  }

  // getter / setters ////////////////////////////////////
  
  public String getId() {
    return id;
  }

  public void setId(String id) {
    this.id = id;
  }

  public String getFirstName() {
    return firstName;
  }

  public void setFirstName(String firstName) {
    this.firstName = firstName;
  }

  public String getLastName() {
    return lastName;
  }

  public void setLastName(String lastName) {
    this.lastName = lastName;
  }

  public String getEmail() {
    return email;
  }

  public void setEmail(String email) {
    this.email = email;
  }

  public AtomLink generateLink(UriBuilder rootUriBuilder, String action, String method, String relation) {
    
    UriBuilder builder = rootUriBuilder.path(UserRestService.class).path("{id}");
    if (action != null) {
      builder.path(action);
    }
    
    URI linkUri = builder.build(id);
    AtomLink link = new AtomLink(relation, linkUri.toString(), method);
    return link;
  }
  
}

@@ -610,29 +610,8 @@
 y;%0A%0A
-import java.net.URI;%0A
 impo
@@ -669,245 +669,44 @@
 ort 
-javax.ws.rs.core.UriBuilder;%0A%0Aimport org.camunda.bpm.engine.identity.User;%0Aimport org.camunda.bpm.engine.rest.ProcessInstanceRestService;%0Aimport org.camunda.bpm.engine.rest.UserRestService;%0Aimport org.camunda.bpm.engine.rest.dto.AtomLink
+org.camunda.bpm.engine.identity.User
 ;%0Aim
@@ -2305,400 +2305,7 @@
 %0A  %7D
-%0A%0A  public AtomLink generateLink(UriBuilder rootUriBuilder, String action, String method, String relation) %7B%0A    %0A    UriBuilder builder = rootUriBuilder.path(UserRestService.class).path(%22%7Bid%7D%22);%0A    if (action != null) %7B%0A      builder.path(action);%0A    %7D%0A    %0A    URI linkUri = builder.build(id);%0A    AtomLink link = new AtomLink(relation, linkUri.toString(), method);%0A    return link;%0A  %7D%0A  
 %0A%7D%0A

remove unused method from UserProfileDto