/*******************************************************************************
 * Copyright (c) 2012-2016 Codenvy, S.A.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Codenvy, S.A. - initial API and implementation
 *******************************************************************************/
package org.eclipse.che.api.user.server;

import org.eclipse.che.api.core.ConflictException;
import org.eclipse.che.api.core.NotFoundException;
import org.eclipse.che.api.core.ServerException;
import org.eclipse.che.api.core.jdbc.jpa.guice.JpaInitializer;
import org.eclipse.che.api.user.server.model.impl.UserImpl;

import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Singleton;

import static java.util.Collections.emptyList;

/**
 * Creates 'che' default user.
 *
 * @author Anton Korneta
 */
@Singleton
public class CheUserCreator {

    @Inject
    private UserManager userManager;

    @Inject
    @SuppressWarnings("unused")
    // this work around needed for Guice to help initialize components in right sequence,
    // because instance of JpaInitializer should be created before components that dependent on dao (such as UserManager)
    private JpaInitializer jpaInitializer;

    @PostConstruct
    public void createCheUser() throws ServerException {
        try {
            userManager.getById("che");
        } catch (NotFoundException ex) {
            try {
                final UserImpl cheUser = new UserImpl("che",
                                                      "che@eclipse.org",
                                                      "che",
                                                      "secret",
                                                      emptyList());
                userManager.create(cheUser, false);
            } catch (ConflictException ignore) {
            }
        }
    }
}

@@ -700,32 +700,128 @@
 erverException;%0A
+import org.eclipse.che.api.core.jdbc.jpa.eclipselink.EntityListenerInjectionManagerInitializer;%0A
 import org.eclip
@@ -1395,19 +1395,46 @@
 ance of 
-Jpa
+EntityListenerInjectionManager
 Initiali
@@ -1465,41 +1465,39 @@
 fore
- components that dependent on dao
+%0A    // jpa callback components
  (su
@@ -1506,21 +1506,28 @@
  as User
-Manag
+EntityListen
 er)%0A    
@@ -1534,19 +1534,46 @@
 private 
-Jpa
+EntityListenerInjectionManager
 Initiali
@@ -1580,12 +1580,9 @@
 zer 
-jpaI
+i
 niti

Fix initialization of user related components (#2644)