
org.xlcloud.console.controllers.utils.ProjectsLazyLoader Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2012 AMG.lab, a Bull Group Company
*
* 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.xlcloud.console.controllers.utils;
import java.io.Serializable;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Named;
import org.xlcloud.console.controllers.request.RequestParameters;
import org.xlcloud.console.extensions.scope.ViewScoped;
import org.xlcloud.service.Project;
import org.xlcloud.service.api.ProjectsApi;
/**
* Lazy loader for accounts.
*
* @author Konrad Król, AMG.net
*/
@Named
@ViewScoped
public class ProjectsLazyLoader implements Serializable {
private static final long serialVersionUID = -5822897808977079642L;
private Map projects = Collections.synchronizedMap(new HashMap());
@Inject
private ProjectsApi projectsApi;
@Inject
RequestParameters requestParameters;
/**
* Retrieves account data from the accounts api.
*
* @param projectId
* requested account id
*/
public void loadProject(Long projectId) {
if (projectId != null && !projects.containsKey(projectId)) {
projects.put(projectId, projectsApi.get(projectId));
}
requestParameters.addCallbackParameter("stopPoller", true);
}
/**
* Returns the requeted account. The account has to be loaded first using
* {@link #loadAccount(Long)}, otherwise: {@code null} is returned.
*
* @param accountId
* requested account id.
* @return account
*/
public Project getProject(Long projectId) {
return projects.get(projectId);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy