Skip to content

Issue #1353, fixed NullCall in GetProjectByUuidDatabaseAction.java #1368

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions BimServer/src/org/bimserver/database/DatabaseSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -1644,6 +1644,30 @@ public <T extends IdEObject> Map<Long, T> query(IfcModelInterface model, Conditi
return map;
}

public <T extends IdEObject> Map<UUID, T> queryUuid(Condition condition, Class<T> clazz, QueryInterface query) throws BimserverDatabaseException {
IfcModelInterface model = createModel(query);
return queryUuid(model, condition, clazz, query);
}
public <T extends IdEObject> Map<UUID, T> queryUuid(IfcModelInterface model, Condition condition, Class<T> clazz, QueryInterface query) throws BimserverDatabaseException {
Map<UUID, T> map = new HashMap<UUID, T>();
Set<EClass> eClasses = new HashSet<EClass>();
condition.getEClassRequirements(eClasses);
for (EClass eClass : eClasses) {
TodoList todoList = new TodoList();
getMap(eClass, model, query, todoList);
processTodoList(model, todoList, query);
List<IdEObject> list = new ArrayList<IdEObject>(model.getValues());
for (IdEObject object : list) {
if (clazz.isInstance(object)) {
if (condition.matches(object)) {
map.put(object.getUuid(), clazz.cast(object));
}
}
}
}
return map;
}

public <T extends IdEObject> T querySingle(Condition condition, Class<T> clazz, QueryInterface query) throws BimserverDatabaseException {
checkOpen();
Collection<T> values = query(condition, clazz, query).values();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,42 +19,59 @@

import org.bimserver.BimserverDatabaseException;
import org.bimserver.database.BimserverLockConflictException;
import org.bimserver.database.Database;
import org.bimserver.database.DatabaseSession;
import org.bimserver.database.OldQuery;
import org.bimserver.database.query.conditions.AttributeCondition;
import org.bimserver.database.query.conditions.Condition;
import org.bimserver.database.query.conditions.IsOfTypeCondition;
import org.bimserver.database.query.conditions.Not;
import org.bimserver.database.query.literals.StringLiteral;
import org.bimserver.models.log.AccessMethod;
import org.bimserver.models.store.Project;
import org.bimserver.models.store.*;
import org.bimserver.shared.exceptions.UserException;
import org.bimserver.webservices.authorization.Authorization;
public class GetProjectByUuidDatabaseAction extends BimDatabaseAction<Project> {


import java.util.Map;
import java.util.UUID;

public class GetProjectByUuidDatabaseAction extends BimDatabaseAction<Project> {

private final String uuid;
private Authorization authorization;
public GetProjectByUuidDatabaseAction(DatabaseSession databaseSession, AccessMethod accessMethod, String uuid, Authorization authorization) {
super(databaseSession, accessMethod);
private Authorization authorization;

public GetProjectByUuidDatabaseAction(DatabaseSession databaseSession, AccessMethod accessMethod, String uuid, Authorization authorization) {
super(databaseSession, accessMethod);
this.uuid = uuid;
this.authorization = authorization;
}

@Override
public Project execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
// List<IdEObject> projects = (List<IdEObject>) getDatabaseSession().query(StorePackage.eINSTANCE.getProject_Uuid(), uuid);
// if (projects.size() == 0) {
// throw new UserException("Project with uuid " + uuid + " does not exist");
// }
// Project project = (Project) projects.get(0);
// User user = getUserByUoid(authorization.getUoid());
// if (user == null) {
// throw new UserException("Authenticated user required");
// }
// if (project.getState() == ObjectState.DELETED && user.getUserType() != UserType.ADMIN) {
// throw new UserException("Project has been deleted");
// }
// if (authorization.hasRightsOnProjectOrSuperProjectsOrSubProjects(user, project)) {
// return project;
// } else {
// throw new UserException("User '" + user.getUsername() + "' has no rights on this project");
// }
// TODO reimplement
return null;
}
this.authorization = authorization;
}

@Override
public Project execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {

UUID comparisonUUID;
try {
comparisonUUID = UUID.fromString(uuid);
}
catch (IllegalArgumentException e) {
throw new UserException("Invalid uuid format");
}
User user = getUserByUoid(authorization.getUoid());
Not notStoreProject = new Not(new AttributeCondition(StorePackage.eINSTANCE.getProject_Name(), new StringLiteral(Database.STORE_PROJECT_NAME)));
Condition condition = new IsOfTypeCondition(StorePackage.eINSTANCE.getProject()).and(notStoreProject);
Map<UUID, Project> results = getDatabaseSession().queryUuid(condition, Project.class, OldQuery.getDefault());
if (results.containsKey(comparisonUUID)) {
if (!authorization.hasRightsOnProject(user, results.get(comparisonUUID))) {
throw new UserException("You do not have rights on this project");
}
if (!results.get(comparisonUUID).getState().equals(ObjectState.ACTIVE) &&
user.getUserType() != UserType.ADMIN && user.getUserType() != UserType.SYSTEM){
throw new UserException("This project is not active");
}
return results.get(comparisonUUID);
}
else {
throw new UserException("Project with uuid " + uuid + " does not exist");
}
}
}