Remove trunk directory

This commit is contained in:
Paulo Gustavo Veiga
2009-11-06 23:30:29 -02:00
parent 2494133fed
commit 75470a91fd
715 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*
* $Id: file 64488 2006-03-10 17:32:09Z paulo $
*/
package com.wisemapping.service;
import javax.servlet.ServletContextListener;
import javax.servlet.ServletContextEvent;
public class HibernateAppListener implements ServletContextListener {
/* Application Startup Event */
public void contextInitialized(ServletContextEvent ce) {
try {
Class.forName("tomcatJndi.HibernateUtil").newInstance();
} catch (Exception e) {}
}
/* Application Shutdown Event */
public void contextDestroyed(ServletContextEvent ce)
{ }
}

View File

@@ -0,0 +1,43 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*
* $Id: file 64488 2006-03-10 17:32:09Z paulo $
*/
package com.wisemapping.service;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}

View File

@@ -0,0 +1,29 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*
* $Id: file 64488 2006-03-10 17:32:09Z paulo $
*/
package com.wisemapping.service;
public class InvalidActivationCodeException
extends Exception
{
public InvalidActivationCodeException(String msg)
{
super(msg);
}
}

View File

@@ -0,0 +1,29 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*
* $Id: file 64488 2006-03-10 17:32:09Z paulo $
*/
package com.wisemapping.service;
public class InvalidColaboratorException
extends Exception
{
public InvalidColaboratorException(String msg)
{
super(msg);
}
}

View File

@@ -0,0 +1,28 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*
* $Id: file 64488 2006-03-10 17:32:09Z paulo $
*/
package com.wisemapping.service;
public class InvalidUserEmailException extends Exception
{
public InvalidUserEmailException(String msg)
{
super(msg);
}
}

View File

@@ -0,0 +1,72 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*
* $Id: file 64488 2006-03-10 17:32:09Z paulo $
*/
package com.wisemapping.service;
import com.wisemapping.model.*;
import com.wisemapping.exceptions.WiseMappingException;
import java.util.List;
import java.io.IOException;
public interface MindmapService {
public static final String TAG_SEPARATOR = " ";
public MindmapUser getMindmapUserBy(int mindmapId, User user);
public MindMap getMindmapById(int mindmapId);
public MindMap getMindmapByTitle(String title, User user);
public List<MindmapUser> getMindmapUserByUser(User user);
public void updateMindmap(MindMap mindMap, boolean saveHistory) throws WiseMappingException;
public void addMindmap(MindMap map, User user) throws WiseMappingException;
public void addColaborators(MindMap mindmap, String[] colaboratorEmails, UserRole role, ColaborationEmail email)
throws InvalidColaboratorException;
public void addTags(MindMap mindmap, String tags);
public void removeColaboratorFromMindmap(MindMap mindmap, long colaboratorId);
public void removeMindmap(MindMap mindmap, User user) throws WiseMappingException;
public List<MindMap> search(MindMapCriteria criteria);
public List<MindMap> getPublicMaps(int cant);
public List<MindMapHistory> getMindMapHistory(int mindmapId);
public boolean isAllowedToView(User user, MindMap map, UserRole allowedRole);
public boolean isAllowedToView(User user, int mapId, UserRole allowedRole);
public boolean isAllowedToColaborate(User user, int mapId, UserRole grantedRole);
public boolean isAllowedToColaborate(User user, MindMap map, UserRole grantedRole);
public void addWelcomeMindmap(User user) throws WiseMappingException;
public void addView(int mapId);
public void revertMapToHistory(MindMap map, int historyId) throws IOException, WiseMappingException;
}

View File

@@ -0,0 +1,303 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*
* $Id: file 64488 2006-03-10 17:32:09Z paulo $
*/
package com.wisemapping.service;
import com.wisemapping.dao.MindmapManager;
import com.wisemapping.exceptions.WiseMappingException;
import com.wisemapping.mail.Mailer;
import com.wisemapping.model.*;
import java.io.IOException;
import java.util.*;
public class MindmapServiceImpl
implements MindmapService {
private MindmapManager mindmapManager;
private UserService userService;
private Mailer mailer;
public boolean isAllowedToColaborate(User user, int mapId, UserRole grantedRole) {
final MindMap map = mindmapManager.getMindmapById(mapId);
return isAllowedToColaborate(user, map, grantedRole);
}
public boolean isAllowedToView(User user, int mapId, UserRole grantedRole) {
final MindMap map = mindmapManager.getMindmapById(mapId);
return isAllowedToView(user, map, grantedRole);
}
public boolean isAllowedToView(User user, MindMap map, UserRole grantedRole) {
boolean isAllowed = false;
if (map != null) {
if (map.isPublic()) {
isAllowed = true;
} else if (user != null) {
isAllowed = isAllowedToColaborate(user, map, grantedRole);
}
}
return isAllowed;
}
public boolean isAllowedToColaborate(User user, MindMap map, UserRole grantedRole) {
boolean isAllowed = false;
if (map != null) {
if (map.getOwner().getId() == user.getId()) {
isAllowed = true;
} else {
final Set<MindmapUser> users = map.getMindmapUsers();
UserRole rol = null;
for (MindmapUser mindmapUser : users) {
if (mindmapUser.getColaborator().getId() == user.getId()) {
rol = mindmapUser.getRole();
break;
}
}
// only if the user has a role for the current map
isAllowed = rol != null &&
(grantedRole.equals(rol) || rol.ordinal() < grantedRole.ordinal());
}
}
return isAllowed;
}
public MindmapUser getMindmapUserBy(int mindmapId, User user) {
return mindmapManager.getMindmapUserBy(mindmapId, user);
}
public MindMap getMindmapByTitle(String title, User user) {
return mindmapManager.getMindmapByTitle(title, user);
}
public MindMap getMindmapById(int mindmapId) {
return mindmapManager.getMindmapById(mindmapId);
}
public List<MindmapUser> getMindmapUserByUser(User user) {
return mindmapManager.getMindmapUserByColaborator(user.getId());
}
public void updateMindmap(MindMap mindMap, boolean saveHistory) throws WiseMappingException {
if (mindMap.getTitle() == null || mindMap.getTitle().length() == 0) {
throw new WiseMappingException("The tile can not be empty");
}
mindmapManager.updateMindmap(mindMap, saveHistory);
}
public List<MindMap> getPublicMaps(int cant) {
return mindmapManager.search(null, cant);
}
public List<MindMap> search(MindMapCriteria criteria) {
return mindmapManager.search(criteria);
}
public void removeColaboratorFromMindmap(MindMap mindmap, long colaboratorId) {
// remove colaborator association
Set<MindmapUser> mindmapusers = mindmap.getMindmapUsers();
MindmapUser mindmapuserToDelete = null;
for (MindmapUser mindmapuser : mindmapusers) {
if (mindmapuser.getColaborator().getId() == colaboratorId) {
mindmapuserToDelete = mindmapuser;
//@TODO evaluar si el colaborador no tiene mas asociaciones si hay que eliminarlo, por ahora NO
// final List<MindmapUser> otherAsociations = mindmapManager.getMindmapUserByColaborator(colaboratorId);
// if (otherAsociations != null)
// {
//
// final User user = userService.getUserBy(colaboratorId);
// // Is not a User
// if (user == null)
// {
// final Colaborator col = mindmapManager.getColaboratorBy(colaboratorId);
// mindmapManager.removeColaborator(col);
// }
// }
break;
}
}
if (mindmapuserToDelete != null) {
// When you delete an object from hibernate you have to delete it from *all* collections it exists in...
mindmapusers.remove(mindmapuserToDelete);
mindmapManager.removeMindmapUser(mindmapuserToDelete);
}
}
public void removeMindmap(MindMap mindmap, User user) throws WiseMappingException {
if (mindmap.getOwner().equals(user)) {
mindmapManager.removeMindmap(mindmap);
} else {
this.removeColaboratorFromMindmap(mindmap, user.getId());
}
}
public void addMindmap(MindMap map, User user) throws WiseMappingException {
final String title = map.getTitle();
if (title == null || title.length() == 0) {
throw new IllegalArgumentException("The tile can not be empty");
}
if (user==null) {
throw new IllegalArgumentException("User can not be null");
}
final Calendar creationTime = Calendar.getInstance();
final String username = user.getUsername();
map.setCreator(username);
map.setLastModifierUser(username);
map.setCreationTime(creationTime);
map.setLastModificationTime(creationTime);
map.setOwner(user);
final MindmapUser mindmapUser = new MindmapUser(UserRole.OWNER.ordinal(), user, map);
map.getMindmapUsers().add(mindmapUser);
mindmapManager.addMindmap(user, map);
}
public void addColaborators(MindMap mindmap, String[] colaboratorEmails, UserRole role, ColaborationEmail email)
throws InvalidColaboratorException {
if (colaboratorEmails != null && colaboratorEmails.length > 0) {
final Colaborator owner = mindmap.getOwner();
final Set<MindmapUser> mindmapUsers = mindmap.getMindmapUsers();
for (String colaboratorEmail : colaboratorEmails) {
if (owner.getEmail().equals(colaboratorEmail)) {
throw new InvalidColaboratorException("The user " + owner.getEmail() + " is the owner");
}
MindmapUser mindmapUser = getMindmapUserBy(colaboratorEmail, mindmapUsers);
if (mindmapUser == null) {
addColaborator(colaboratorEmail, role, mindmap, email);
} else if (mindmapUser.getRole() != role) {
// If the relationship already exists and the role changed then only update the role
mindmapUser.setRoleId(role.ordinal());
mindmapManager.updateMindmap(mindmap, false);
}
}
}
}
public void addTags(MindMap mindmap, String tags) {
mindmap.setTags(tags);
mindmapManager.updateMindmap(mindmap, false);
if (tags != null && tags.length() > 0) {
final String tag[] = tags.split(TAG_SEPARATOR);
final User user = mindmap.getOwner();
// Add new Tags to User
boolean updateUser = false;
for (String userTag : tag) {
if (!user.getTags().contains(userTag)) {
user.getTags().add(userTag);
updateUser = true;
}
}
if (updateUser) {
//update user
userService.updateUser(user);
}
}
}
public void addWelcomeMindmap(User user) throws WiseMappingException {
final MindMap savedWelcome = getMindmapById(Constants.WELCOME_MAP_ID);
// Is there a welcomed map configured ?
if(savedWelcome!=null)
{
final MindMap welcomeMap = new MindMap();
welcomeMap.setTitle(savedWelcome.getTitle() + " " + user.getFirstname());
welcomeMap.setDescription(savedWelcome.getDescription());
welcomeMap.setXml(savedWelcome.getXml());
final MindMapNative mindmapNative = new MindMapNative();
mindmapNative.setSvgXml(savedWelcome.getNativeBrowser().getSvgXml());
mindmapNative.setVmlXml(savedWelcome.getNativeBrowser().getVmlXml());
welcomeMap.setNativeBrowser(mindmapNative);
addMindmap(welcomeMap, user);
}
}
public void addView(int mapId) {
mindmapManager.addView(mapId);
}
public List<MindMapHistory> getMindMapHistory(int mindmapId) {
return mindmapManager.getHistoryFrom(mindmapId);
}
public void revertMapToHistory(MindMap map, int historyId)
throws IOException, WiseMappingException {
final MindMapHistory history = mindmapManager.getHistory(historyId);
map.setNativeXml(history.getNativeXml());
updateMindmap(map, false);
}
private MindmapUser getMindmapUserBy(String email, Set<MindmapUser> mindmapUsers) {
MindmapUser mindmapUser = null;
for (MindmapUser user : mindmapUsers) {
if (user.getColaborator().getEmail().equals(email)) {
mindmapUser = user;
break;
}
}
return mindmapUser;
}
private void addColaborator(String colaboratorEmail, UserRole role, MindMap mindmap, ColaborationEmail email) {
Colaborator colaborator = mindmapManager.getColaboratorBy(colaboratorEmail);
if (colaborator == null) {
colaborator = new Colaborator();
colaborator.setEmail(colaboratorEmail);
colaborator.setCreationDate(Calendar.getInstance());
mindmapManager.addColaborator(colaborator);
}
final MindmapUser newMindmapUser = new MindmapUser(role.ordinal(), colaborator, mindmap);
mindmap.getMindmapUsers().add(newMindmapUser);
mindmapManager.saveMindmap(mindmap);
final Map<String, Object> model = new HashMap<String, Object>();
model.put("role", role);
model.put("map", mindmap);
model.put("message", email.getMessage());
mailer.sendEmail(mailer.getSiteEmail(), colaboratorEmail, email.getSubject(), model, "newColaborator.vm");
}
public void setMindmapManager(MindmapManager mindmapManager) {
this.mindmapManager = mindmapManager;
}
public void setUserService(UserService userService) {
this.userService = userService;
}
public void setMailer(Mailer mailer) {
this.mailer = mailer;
}
}

View File

@@ -0,0 +1,44 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*
* $Id: file 64488 2006-03-10 17:32:09Z paulo $
*/
package com.wisemapping.service;
import com.wisemapping.model.User;
import com.wisemapping.exceptions.WiseMappingException;
public interface UserService {
public void activateAcount(long code) throws InvalidActivationCodeException;
public void createUser(User user) throws WiseMappingException;
public void changePassword(User user);
public User getUserBy(String email);
public User getUserBy(long id);
public User getUserByUsername(String username);
public void updateUser(User user);
public void sendEmailPassword(String email) throws InvalidUserEmailException;
public User reloadUser(final User user);
}

View File

@@ -0,0 +1,154 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*
* $Id: file 64488 2006-03-10 17:32:09Z paulo $
*/
package com.wisemapping.service;
import com.wisemapping.dao.UserManager;
import com.wisemapping.exceptions.WiseMappingException;
import com.wisemapping.mail.Mailer;
import com.wisemapping.model.User;
import com.wisemapping.model.Colaborator;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class UserServiceImpl
implements UserService {
private UserManager userManager;
private MindmapService mindmapService;
private Mailer mailer;
public void activateAcount(long code)
throws InvalidActivationCodeException
{
final User user = userManager.getUserByActivationCode(code);
if (user == null || user.isActive()) {
throw new InvalidActivationCodeException("Invalid Activation Code");
} else {
final Calendar now = Calendar.getInstance();
user.setActivationDate(now);
userManager.updateUser(user);
final Map<String, User> model = new HashMap<String, User>();
model.put("user", user);
mailer.sendEmail(mailer.getRegistrationEmail(), user.getEmail(), "WiseMapping : Active account", model, "activationAccountMail.vm");
}
}
public User reloadUser(final User user) {
return this.getUserBy(user.getId());
}
public void sendEmailPassword(String email)
throws InvalidUserEmailException {
final User user = userManager.getUserBy(email);
if (user != null) {
final Map<String, Object> model = new HashMap<String, Object>();
final String password = randomstring(8, 10);
user.setPassword(password);
changePassword(user);
model.put("user", user);
model.put("password", password);
mailer.sendEmail(mailer.getRegistrationEmail(), user.getEmail(), "WiseMapping : Recovery Password", model, "recoveryMail.vm");
} else {
throw new InvalidUserEmailException("The email '" + email + "' does not exists.");
}
}
private String randomstring(int lo, int hi) {
int n = rand(lo, hi);
byte b[] = new byte[n];
for (int i = 0; i < n; i++)
b[i] = (byte) rand('@', 'Z');
return new String(b);
}
private int rand(int lo, int hi) {
java.util.Random rn = new java.util.Random();
int n = hi - lo + 1;
int i = rn.nextInt() % n;
if (i < 0)
i = -i;
return lo + i;
}
public void createUser(User user) throws WiseMappingException {
final UUID uuid = UUID.randomUUID();
user.setCreationDate(Calendar.getInstance());
user.setActivationDate(null);
user.setActivationCode(uuid.getLeastSignificantBits());
Colaborator col = userManager.getColaboratorBy(user.getEmail());
if (col != null)
{
userManager.createUser(user,col);
}
else
{
userManager.createUser(user);
}
//create welcome map
mindmapService.addWelcomeMindmap(user);
final Map<String, Object> model = new HashMap<String, Object>();
model.put("user", user);
// TODO: ver como no hacer hardcode el url
final String activationUrl = "http://wisemapping.com/c/activation.htm?code=" + user.getActivationCode();
model.put("emailcheck", activationUrl);
mailer.sendEmail(mailer.getRegistrationEmail(), user.getEmail(), "Welcome to Wisemapping!", model,
"confirmationMail.vm");
mailer.sendEmail(mailer.getRegistrationEmail(), mailer.getRegistrationEmail(), "Wisemapping : New User", model,
"activeUserAccountMail.vm");
}
public void changePassword(User user) {
userManager.updateUser(user);
}
public User getUserBy(String email) {
return userManager.getUserBy(email);
}
public User getUserByUsername(String username) {
return userManager.getUserByUsername(username);
}
public User getUserBy(long id) {
return userManager.getUserBy(id);
}
public void updateUser(User user) {
userManager.updateUser(user);
}
public void setUserManager(UserManager userManager) {
this.userManager = userManager;
}
public void setMailer(Mailer mailer) {
this.mailer = mailer;
}
public void setMindmapService(MindmapService mindmapService) {
this.mindmapService = mindmapService;
}
}