use of org.bimserver.shared.exceptions.UserException in project BIMserver by opensourceBIM.
the class ServiceImpl method getSuggestedDeserializerForExtension.
@Override
public SDeserializerPluginConfiguration getSuggestedDeserializerForExtension(String extension, Long poid) throws ServerException, UserException {
// Token authenticated users should also be able to call this method
try {
requireAuthenticationAndRunningServer();
DatabaseSession session = getBimServer().getDatabase().createSession();
List<DeserializerPluginConfiguration> list = new ArrayList<>();
try {
Project project = session.get(poid, OldQuery.getDefault());
UserSettings userSettings = getUserSettings(session);
for (DeserializerPluginConfiguration deserializer : userSettings.getDeserializers()) {
Plugin plugin = getBimServer().getPluginManager().getPlugin(deserializer.getPluginDescriptor().getIdentifier(), true);
if (plugin instanceof DeserializerPlugin) {
DeserializerPlugin deserializerPlugin = (DeserializerPlugin) plugin;
if (deserializerPlugin.getSupportedSchemas().contains(Schema.valueOf(project.getSchema().toUpperCase()))) {
if (deserializerPlugin.canHandleExtension(extension)) {
list.add(deserializer);
}
}
} else if (plugin instanceof StreamingDeserializerPlugin) {
StreamingDeserializerPlugin streamingDeserializerPlugin = (StreamingDeserializerPlugin) plugin;
if (streamingDeserializerPlugin.getSupportedSchemas().contains(Schema.valueOf(project.getSchema().toUpperCase()))) {
if (streamingDeserializerPlugin.canHandleExtension(extension)) {
list.add(deserializer);
}
}
}
}
} finally {
session.close();
}
if (list.size() == 1) {
return getBimServer().getSConverter().convertToSObject(list.get(0));
} else if (list.size() > 1) {
for (DeserializerPluginConfiguration deserializerPluginConfiguration : list) {
Plugin plugin = getBimServer().getPluginManager().getPlugin(deserializerPluginConfiguration.getPluginDescriptor().getIdentifier(), true);
// Prefer the streaming version
if (plugin instanceof StreamingDeserializerPlugin) {
return getBimServer().getSConverter().convertToSObject(deserializerPluginConfiguration);
}
}
// Just return the first one
return getBimServer().getSConverter().convertToSObject(list.get(0));
}
} catch (Exception e) {
return handleException(e);
}
return null;
}
use of org.bimserver.shared.exceptions.UserException in project BIMserver by opensourceBIM.
the class ServiceImpl method getAllLocalProfiles.
@Override
public List<SProfileDescriptor> getAllLocalProfiles(String serviceIdentifier) throws ServerException, UserException {
requireRealUserAuthentication();
DatabaseSession session = getBimServer().getDatabase().createSession();
List<SProfileDescriptor> descriptors = new ArrayList<SProfileDescriptor>();
try {
SUser currentUser = getCurrentUser();
Condition condition = new AttributeCondition(StorePackage.eINSTANCE.getUser_Token(), new StringLiteral(currentUser.getToken()));
User user = session.querySingle(condition, User.class, OldQuery.getDefault());
if (user != null) {
for (InternalServicePluginConfiguration internalServicePluginConfiguration : user.getUserSettings().getServices()) {
if (serviceIdentifier.equals("" + internalServicePluginConfiguration.getOid())) {
SProfileDescriptor sProfileDescriptor = new SProfileDescriptor();
descriptors.add(sProfileDescriptor);
sProfileDescriptor.setIdentifier("" + internalServicePluginConfiguration.getOid());
sProfileDescriptor.setName(internalServicePluginConfiguration.getName());
sProfileDescriptor.setDescription(internalServicePluginConfiguration.getDescription());
sProfileDescriptor.setPublicProfile(false);
}
}
}
} catch (Exception e) {
handleException(e);
} finally {
session.close();
}
return descriptors;
}
use of org.bimserver.shared.exceptions.UserException in project BIMserver by opensourceBIM.
the class ServiceImpl method getQueryEngineByName.
@Override
public SQueryEnginePluginConfiguration getQueryEngineByName(String name) throws ServerException, UserException {
requireRealUserAuthentication();
DatabaseSession session = getBimServer().getDatabase().createSession();
try {
return getBimServer().getSConverter().convertToSObject(session.executeAndCommitAction(new GetQueryEngineByNameDatabaseAction(session, getInternalAccessMethod(), name)));
} catch (Exception e) {
return handleException(e);
} finally {
session.close();
}
}
use of org.bimserver.shared.exceptions.UserException in project BIMserver by opensourceBIM.
the class ServiceImpl method checkinInitiatedInternal.
public Long checkinInitiatedInternal(Long topicId, final Long poid, final String comment, Long deserializerOid, Long fileSize, String fileName, DataHandler dataHandler, Boolean merge, Boolean sync, long newServiceId) throws ServerException, UserException {
requireAuthenticationAndRunningServer();
final DatabaseSession session = getBimServer().getDatabase().createSession();
String username = "Unknown";
String userUsername = "Unknown";
try {
if (getBimServer().getCheckinsInProgress().containsKey(poid)) {
Thread.sleep(1000);
throw new UserException("Checkin in progress on this project, please try again later");
}
User user = (User) session.get(StorePackage.eINSTANCE.getUser(), getAuthorization().getUoid(), OldQuery.getDefault());
Project project = session.get(poid, OldQuery.getDefault());
if (project == null) {
throw new UserException("No project found with poid " + poid);
}
username = user.getName();
userUsername = user.getUsername();
Path homeDirIncoming = getBimServer().getHomeDir().resolve("incoming");
Path userDirIncoming = homeDirIncoming.resolve(userUsername);
if (!Files.exists(userDirIncoming)) {
Files.createDirectories(userDirIncoming);
}
if (fileName.contains("/")) {
fileName = fileName.substring(fileName.lastIndexOf("/") + 1);
}
if (fileName.contains("\\")) {
fileName = fileName.substring(fileName.lastIndexOf("\\") + 1);
}
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
String cacheFileName = dateFormat.format(new Date()) + "-" + fileName;
Path file = userDirIncoming.resolve(cacheFileName);
return checkinInternal(topicId, poid, comment, deserializerOid, fileSize, fileName, dataHandler.getInputStream(), merge, sync, session, username, userUsername, project, file, newServiceId);
} catch (UserException e) {
throw e;
} catch (Throwable e) {
LOGGER.error("", e);
throw new ServerException(e);
} finally {
session.close();
}
}
use of org.bimserver.shared.exceptions.UserException in project BIMserver by opensourceBIM.
the class ServiceImpl method getAllCheckoutsOfProjectAndSubProjects.
@Override
public List<SCheckout> getAllCheckoutsOfProjectAndSubProjects(Long poid) throws ServerException, UserException {
requireRealUserAuthentication();
DatabaseSession session = getBimServer().getDatabase().createSession();
try {
BimDatabaseAction<List<Checkout>> action = new GetAllCheckoutsOfProjectDatabaseAction(session, getInternalAccessMethod(), poid, true);
List<Checkout> list = session.executeAndCommitAction(action);
Collections.sort(list, new CheckoutComparator());
return getBimServer().getSConverter().convertToSListCheckout(list);
} catch (Exception e) {
return handleException(e);
} finally {
session.close();
}
}
Aggregations