use of org.bimserver.models.store.Project in project BIMserver by opensourceBIM.
the class GetDataObjectsByTypeDatabaseAction method execute.
@Override
public List<DataObject> execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
EClass eClass = getDatabaseSession().getEClassForName(packageName, className);
Revision virtualRevision = getRevisionByRoid(roid);
if (virtualRevision == null) {
throw new UserException("No revision with roid " + roid + " found");
}
Map<Integer, Long> pidRoidMap = new HashMap<>();
IfcModelSet ifcModelSet = new IfcModelSet();
pidRoidMap.put(virtualRevision.getProject().getId(), virtualRevision.getOid());
PackageMetaData lastPackageMetaData = null;
Project project = virtualRevision.getProject();
for (ConcreteRevision concreteRevision : virtualRevision.getConcreteRevisions()) {
PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(concreteRevision.getProject().getSchema());
int highestStopId = findHighestStopRid(project, concreteRevision);
OldQuery query = new OldQuery(packageMetaData, concreteRevision.getProject().getId(), concreteRevision.getId(), -1, Deep.NO, highestStopId);
lastPackageMetaData = packageMetaData;
IfcModelInterface subModel = getDatabaseSession().getAllOfType(packageMetaData.getEPackage().getName(), className, query);
subModel.getModelMetaData().setDate(concreteRevision.getDate());
ifcModelSet.add(subModel);
}
IfcModelInterface ifcModel = getDatabaseSession().createServerModel(lastPackageMetaData, pidRoidMap);
if (ifcModelSet.size() > 1) {
try {
ifcModel = getBimServer().getMergerFactory().createMerger(getDatabaseSession(), getAuthorization().getUoid()).merge(project, ifcModelSet, new ModelHelper(getBimServer().getMetaDataManager(), ifcModel));
} catch (MergeException e) {
throw new UserException(e);
}
} else {
ifcModel = ifcModelSet.iterator().next();
}
List<DataObject> dataObjects = new ArrayList<DataObject>();
for (Long oid : new HashSet<>(ifcModel.keySet())) {
EObject eObject = ifcModel.get(oid);
if (eClass.isInstance(eObject)) {
DataObject dataObject = StoreFactory.eINSTANCE.createDataObject();
if (eObject instanceof IfcRoot) {
IfcRoot ifcRoot = (IfcRoot) eObject;
String guid = ifcRoot.getGlobalId() != null ? ifcRoot.getGlobalId() : "";
String name = ifcRoot.getName() != null ? ifcRoot.getName() : "";
dataObject = StoreFactory.eINSTANCE.createDataObject();
dataObject.setType(eObject.eClass().getName());
((IdEObjectImpl) dataObject).setOid(oid);
dataObject.setGuid(guid);
dataObject.setName(name);
} else {
dataObject = StoreFactory.eINSTANCE.createDataObject();
dataObject.setType(eObject.eClass().getName());
((IdEObjectImpl) dataObject).setOid(oid);
dataObject.setGuid("");
dataObject.setName("");
}
if (!flat) {
GetDataObjectByOidDatabaseAction.fillDataObject(ifcModel.getObjects(), eObject, dataObject);
}
dataObjects.add(dataObject);
}
}
return dataObjects;
}
use of org.bimserver.models.store.Project in project BIMserver by opensourceBIM.
the class GetGeoTagDatabaseAction method execute.
@Override
public GeoTag execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
User actingUser = getUserByUoid(authorization.getUoid());
GeoTag geoTag = (GeoTag) getDatabaseSession().get(StorePackage.eINSTANCE.getGeoTag(), goid, OldQuery.getDefault());
boolean hasRights = false;
for (Project project : geoTag.getProjects()) {
if (authorization.hasRightsOnProject(actingUser, project)) {
hasRights = true;
continue;
}
}
if (hasRights) {
return geoTag;
} else {
throw new UserException("User has no rights on any projects associated with this geotag");
}
}
use of org.bimserver.models.store.Project in project BIMserver by opensourceBIM.
the class GetAllProjectsSmallDatabaseAction method addProjects.
private void addProjects(List<SProjectSmall> list, Project project, User user) {
if (project.getState() == ObjectState.DELETED && !(authorization instanceof AdminAuthorization)) {
return;
}
list.add(createSmallProject(authorization, bimServer, project, user));
List<Project> subProjects = new ArrayList<Project>(project.getSubProjects());
Collections.sort(subProjects, new Comparator<Project>() {
@Override
public int compare(Project o1, Project o2) {
return o1.getName().compareTo(o2.getName());
}
});
for (Project subProject : subProjects) {
addProjects(list, subProject, user);
}
}
use of org.bimserver.models.store.Project in project BIMserver by opensourceBIM.
the class GetAllReadableProjectsDatabaseAction method execute.
@Override
public Set<Project> execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
User user = getUserByUoid(authorization.getUoid());
IfcModelInterface projectsModel = getDatabaseSession().getAllOfType(StorePackage.eINSTANCE.getProject(), OldQuery.getDefault());
Set<Project> result = new HashSet<Project>();
for (IdEObject idEObject : projectsModel.getValues()) {
if (idEObject instanceof Project) {
Project project = (Project) idEObject;
if (!Database.STORE_PROJECT_NAME.equals(project.getName()) && (user.getUserType() == UserType.ADMIN || (project.getState() == ObjectState.ACTIVE) && authorization.hasRightsOnProjectOrSuperProjectsOrSubProjects(user, project))) {
result.add(project);
}
}
}
return result;
}
use of org.bimserver.models.store.Project in project BIMserver by opensourceBIM.
the class GetProjectsByNameDatabaseAction method execute.
@Override
public List<Project> execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
List<Project> projects = getProjectsByName(name);
List<Project> result = new ArrayList<Project>();
User user = getUserByUoid(authorization.getUoid());
for (Project project : projects) {
if ((project.getState() == ObjectState.ACTIVE && authorization.hasRightsOnProjectOrSuperProjectsOrSubProjects(user, project))) {
result.add(project);
}
}
return result;
}
Aggregations