/*
* Copyright 2002-2007 the original author or authors.
*
* 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.internna.iwebmvc.spring.services.dwr.impl;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.directwebremoting.annotations.RemoteMethod;
import org.directwebremoting.annotations.RemoteProxy;
import org.internna.iwebmvc.core.crypto.Cipher;
import org.internna.iwebmvc.core.dao.SecurityDAO;
import org.internna.iwebmvc.model.UpdateDataDTO;
import org.internna.iwebmvc.model.security.UserImpl;
import org.internna.iwebmvc.spring.services.dwr.SecurityRemoteEntityManager;
import org.internna.iwebmvc.utils.Assert;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeanWrapperImpl;
import org.springframework.beans.factory.annotation.Autowired;
/**
* Default implementation based on a SecurityDAO.
* @author Jose Noheda
* @since 1.0
*/
@RemoteProxy(name = "SecurityEntityManager")
public class SecurityRemoteEntityManagerImpl implements SecurityRemoteEntityManager {
protected static Log log = LogFactory.getLog(SecurityRemoteEntityManagerImpl.class);
@Autowired protected SecurityDAO dao;
@RemoteMethod
@SuppressWarnings("unchecked")
public List<UserImpl> fetch(String username, String name, String role, int offset, int number) throws Exception {
return dao.findUsers(username, name, role, offset, number);
}
@RemoteMethod
public boolean toggle(String username) throws Exception {
Assert.hasText(username);
UserImpl user = dao.findUser(username);
user.toggle();
dao.createUser(user);
return user.isEnabled();
}
@RemoteMethod
public boolean update(Class clazz, UpdateDataDTO[] data) throws Exception {
for (UpdateDataDTO dto : data) {
UserImpl user = dao.findUser(dto.getPrimaryKey());
BeanWrapper w = new BeanWrapperImpl(user);
w.setPropertyValue(dto.getPath(), dto.getValue());
dao.createUser(user);
}
return true;
}
}