/*
* 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.parsers;
import org.internna.iwebmvc.dao.DAO;
import org.internna.iwebmvc.model.Document;
import org.internna.iwebmvc.model.UUID;
import org.internna.iwebmvc.model.User;
import org.internna.iwebmvc.model.security.GuestUser;
import org.internna.iwebmvc.model.security.UserImpl;
import org.internna.iwebmvc.security.UserManager;
/**
* Parses @{@link Document} entities.
*
* @author Jose Noheda
* @since 2.0
*/
public class DocumentParser extends AbstractEntityParser<Document> {
private UserManager userManager;
public DocumentParser(DAO dao, UserManager userManager) {
super(Document.class, dao);
this.userManager = userManager;
}
@Override public Document parse(Document up) {
if (up != null) {
UUID id = up.getId();
if (id != null) {
Document doc = getDao().find(Document.class, id);
doc.setTemporal(false);
doc.setIdentifier(up.getIdentifier());
if ((doc.getAuthor() == null) && (userManager != null)) {
User user = userManager.getActiveUser();
if ((user != null) && (!GuestUser.GUEST_USER.equals(user.getName())))
doc.setAuthor((UserImpl) user);
}
return doc;
} else return null;
}
return up;
}
}