use of org.bimserver.models.store.Project in project BIMserver by opensourceBIM.
the class GetRevisionDatabaseAction method execute.
@Override
public Revision execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
Revision revision = getRevisionByRoid(roid);
if (revision == null) {
throw new UserException("Revision does not exist");
}
Project project = revision.getProject();
User user = getUserByUoid(authorization.getUoid());
if (authorization.hasRightsOnProjectOrSuperProjectsOrSubProjects(user, project)) {
return revision;
}
throw new UserException("User has no rights on this revision's project (" + project.getName() + ")");
}
use of org.bimserver.models.store.Project in project BIMserver by opensourceBIM.
the class GetCheckoutWarningsDatabaseAction method execute.
@Override
public Set<String> execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
Project project = getProjectByPoid(poid);
User user = getUserByUoid(authorization.getUoid());
Set<String> warnings = new HashSet<String>();
checkOtherUsersCheckouts(project, user, warnings);
return warnings;
}
use of org.bimserver.models.store.Project in project BIMserver by opensourceBIM.
the class NewRevisionNotification method getRelatedProjects.
private Set<Project> getRelatedProjects(Project project) {
Set<Project> projects = new HashSet<Project>();
Project rootProject = getRootProject(project);
getAllSubProjects(projects, rootProject);
return projects;
}
use of org.bimserver.models.store.Project in project BIMserver by opensourceBIM.
the class NewRevisionNotification method triggerNewRevision.
public void triggerNewRevision(DatabaseSession session, NotificationsManager notificationsManager, final BimServer bimServer, String siteAddress, Project project, final long roid, Trigger trigger, final Service service) throws UserException, ServerException {
if (service.getTrigger() == trigger) {
Channel channel = null;
try {
IfcModelInterface model = null;
for (ModelCheckerInstance modelCheckerInstance : service.getModelCheckers()) {
if (modelCheckerInstance.isValid()) {
ModelCheckerPlugin modelCheckerPlugin = bimServer.getPluginManager().getModelCheckerPlugin(modelCheckerInstance.getModelCheckerPluginClassName(), true);
if (modelCheckerPlugin != null) {
ModelChecker modelChecker = modelCheckerPlugin.createModelChecker(null);
ModelCheckerResult result;
try {
if (model == null) {
PackageMetaData packageMetaData = bimServer.getMetaDataManager().getPackageMetaData(project.getSchema());
model = new BasicIfcModel(packageMetaData, null);
Revision revision;
try {
revision = session.get(roid, OldQuery.getDefault());
session.getMap(model, new OldQuery(packageMetaData, project.getId(), revision.getId(), revision.getOid(), Deep.NO));
} catch (BimserverDatabaseException e) {
LOGGER.error("", e);
}
}
result = modelChecker.check(model, modelCheckerInstance.getCompiled());
if (!result.isValid()) {
LOGGER.info("Not triggering");
return;
}
} catch (ModelCheckException e) {
LOGGER.info("Not triggering");
return;
}
}
}
}
channel = notificationsManager.getChannel(service);
final RemoteServiceInterface remoteServiceInterface = channel.get(RemoteServiceInterface.class);
long writeProjectPoid = service.getWriteRevision() == null ? -1 : service.getWriteRevision().getOid();
long writeExtendedDataRoid = roid;
if (writeExtendedDataRoid == -1) {
LOGGER.error("Write extended data roid is already -1 here");
}
@SuppressWarnings("unused") long readRevisionRoid = service.isReadRevision() ? roid : -1;
long readExtendedDataRoid = service.getReadExtendedData() != null ? roid : -1;
List<Long> roidsList = new ArrayList<>();
Set<Project> relatedProjects = getRelatedProjects(project);
for (Project p : relatedProjects) {
for (Revision revision : p.getRevisions()) {
roidsList.add(revision.getOid());
}
}
long[] roids = new long[roidsList.size()];
for (int i = 0; i < roids.length; i++) {
roids[i] = roidsList.get(i);
}
final ExplicitRightsAuthorization authorization = new ExplicitRightsAuthorization(bimServer, service.getUser().getOid(), service.getOid(), service.isReadRevision() ? roids : new long[0], writeProjectPoid, readExtendedDataRoid, writeExtendedDataRoid);
ServiceInterface newService = bimServer.getServiceFactory().get(authorization, AccessMethod.INTERNAL).get(ServiceInterface.class);
// TODO redundant?
((org.bimserver.webservices.impl.ServiceImpl) newService).setAuthorization(authorization);
AsyncRemoteServiceInterface asyncRemoteServiceInterface = new AsyncRemoteServiceInterface(remoteServiceInterface, bimServer.getExecutorService());
asyncRemoteServiceInterface.newRevision(poid, roid, service.getOid(), service.getServiceIdentifier(), service.getProfileIdentifier(), service.getToken(), authorization.asHexToken(bimServer.getEncryptionKey()), bimServer.getServerSettingsCache().getServerSettings().getSiteAddress(), new NewRevisionCallback() {
@Override
public void success() {
}
@Override
public void error(Throwable e) {
LOGGER.error("", e);
}
});
} catch (ChannelConnectionException e) {
LOGGER.error("", e);
} catch (PublicInterfaceNotFoundException e) {
LOGGER.error("", e);
} finally {
if (channel != null) {
// TODO This is interesting, when sending async, is this not going to break?
channel.disconnect();
}
}
}
}
use of org.bimserver.models.store.Project in project BIMserver by opensourceBIM.
the class TestDatabase method removeWithAllOfType.
@SuppressWarnings("unused")
private void removeWithAllOfType() {
DatabaseSession session = database.createSession(OperationType.READ_WRITE);
try {
List<User> users = session.getAllOfType(StorePackage.eINSTANCE.getUser(), User.class, OldQuery.getDefault());
List<Project> projects = session.getAllOfType(StorePackage.eINSTANCE.getProject(), Project.class, OldQuery.getDefault());
Project p = null;
for (Project project : projects) {
if (project.getName().equals("testproject")) {
p = project;
break;
}
}
for (User user : users) {
if (user.getName().equals("testuser")) {
if (!user.getHasRightsOn().remove(p)) {
System.err.println("No project removed");
}
session.store(user);
}
}
session.store(p);
session.commit();
} catch (BimserverDatabaseException e) {
e.printStackTrace();
} catch (ServiceException e) {
e.printStackTrace();
} finally {
session.close();
}
}
Aggregations