use of org.bimserver.shared.exceptions.UserException in project BIMserver by opensourceBIM.
the class PluginManager method update.
public PluginBundle update(PluginBundleVersionIdentifier pluginBundleVersionIdentifier, SPluginBundle sPluginBundle, SPluginBundleVersion pluginBundleVersion, Path jarFile, Path pomFile, List<SPluginInformation> plugins) throws Exception {
PluginBundle existingPluginBundle = pluginBundleIdentifierToPluginBundle.get(pluginBundleVersionIdentifier.getPluginBundleIdentifier());
if (existingPluginBundle == null) {
throw new UserException("No previous version of plugin bundle " + pluginBundleVersionIdentifier.getPluginBundleIdentifier() + " found");
}
try {
existingPluginBundle.close();
if (pluginBundleIdentifierToPluginBundle.remove(pluginBundleVersionIdentifier.getPluginBundleIdentifier()) == null) {
LOGGER.warn("Previous version of " + pluginBundleVersionIdentifier.getPluginBundleIdentifier() + " not found");
}
PluginBundleVersionIdentifier currentVersion = pluginBundleIdentifierToCurrentPluginBundleVersionIdentifier.get(pluginBundleVersionIdentifier.getPluginBundleIdentifier());
if (pluginBundleIdentifierToCurrentPluginBundleVersionIdentifier.remove(pluginBundleVersionIdentifier.getPluginBundleIdentifier()) == null) {
LOGGER.warn("Previous version of " + pluginBundleVersionIdentifier.getPluginBundleIdentifier() + " not found");
}
if (pluginBundleVersionIdentifierToPluginBundle.remove(currentVersion) == null) {
LOGGER.warn("Previous version (" + currentVersion + ") of " + pluginBundleVersionIdentifier.getPluginBundleIdentifier() + " not found");
}
for (PluginContext pluginContext : existingPluginBundle) {
Set<PluginContext> set = implementations.get(pluginContext.getPluginInterface());
set.remove(pluginContext);
}
if (existingPluginBundle.getPluginBundle().getInstalledVersion().getType() == SPluginBundleType.MAVEN) {
Path target = pluginsDir.resolve(currentVersion.getFileName());
Files.delete(target);
}
// for (PluginContext pluginContext : existingPluginBundle) {
// pluginChangeListener.pluginUninstalled(pluginContext);
// }
} catch (IOException e) {
LOGGER.error("", e);
}
Path target = pluginsDir.resolve(pluginBundleVersionIdentifier.getFileName());
if (Files.exists(target)) {
throw new PluginException("This plugin has already been installed " + target.getFileName().toString());
}
Files.copy(jarFile, target);
MavenXpp3Reader mavenreader = new MavenXpp3Reader();
Model model = null;
try (FileReader fileReader = new FileReader(pomFile.toFile())) {
model = mavenreader.read(fileReader);
}
DelegatingClassLoader delegatingClassLoader = new DelegatingClassLoader(getClass().getClassLoader());
for (org.apache.maven.model.Dependency dependency : model.getDependencies()) {
if (dependency.getGroupId().equals("org.opensourcebim") && (dependency.getArtifactId().equals("shared") || dependency.getArtifactId().equals("pluginbase"))) {
// TODO Skip, we should also check the version though
} else {
PluginBundleIdentifier pluginBundleIdentifier = new PluginBundleIdentifier(dependency.getGroupId(), dependency.getArtifactId());
if (pluginBundleIdentifierToPluginBundle.containsKey(pluginBundleIdentifier)) {
// if (false) {
// VersionRange versionRange =
// VersionRange.createFromVersion(dependency.getVersion());
// String version =
// pluginBundleIdentifierToPluginBundle.get(pluginBundleIdentifier).getPluginBundleVersion().getVersion();
// ArtifactVersion artifactVersion = new
// DefaultArtifactVersion(version);
// if (versionRange.containsVersion(artifactVersion)) {
// // OK
// } else {
// throw new Exception("Required dependency " +
// pluginBundleIdentifier + " is installed, but it's version
// (" + version + ") does not comply to the required version
// (" + dependency.getVersion() + ")");
// }
// } else {
LOGGER.info("Skipping strict dependency checking for dependency " + dependency.getArtifactId());
// }
} else {
if (dependency.getGroupId().equals("org.opensourcebim") && (dependency.getArtifactId().equals("shared") || dependency.getArtifactId().equals("pluginbase"))) {
throw new Exception("Required dependency " + pluginBundleIdentifier + " is not installed");
} else {
MavenPluginLocation mavenPluginLocation = mavenPluginRepository.getPluginLocation(model.getRepositories().get(0).getUrl(), dependency.getGroupId(), dependency.getArtifactId());
try {
Path depJarFile = mavenPluginLocation.getVersionJar(dependency.getVersion());
FileJarClassLoader jarClassLoader = new FileJarClassLoader(this, delegatingClassLoader, depJarFile);
jarClassLoaders.add(jarClassLoader);
delegatingClassLoader.add(jarClassLoader);
} catch (Exception e) {
}
}
}
}
}
PluginBundle pluginBundle = null;
// Stage 1, load all plugins from the JAR file and initialize them
try {
pluginBundle = loadPluginsFromJar(pluginBundleVersionIdentifier, target, sPluginBundle, pluginBundleVersion, delegatingClassLoader);
for (SPluginInformation sPluginInformation : plugins) {
if (sPluginInformation.isEnabled()) {
PluginContext pluginContext = pluginBundle.getPluginContext(sPluginInformation.getIdentifier());
pluginContext.getPlugin().init(pluginContext);
}
}
} catch (Exception e) {
Files.delete(target);
LOGGER.error("", e);
throw e;
}
// uninstalled
try {
long pluginBundleVersionId = pluginChangeListener.pluginBundleUpdated(pluginBundle);
for (SPluginInformation sPluginInformation : plugins) {
if (sPluginInformation.isEnabled()) {
PluginContext pluginContext = pluginBundle.getPluginContext(sPluginInformation.getIdentifier());
pluginChangeListener.pluginUpdated(pluginBundleVersionId, pluginContext, sPluginInformation);
}
}
return pluginBundle;
} catch (Exception e) {
uninstall(pluginBundleVersionIdentifier);
LOGGER.error("", e);
throw e;
}
}
use of org.bimserver.shared.exceptions.UserException in project BIMserver by opensourceBIM.
the class JsonReflector method callMethod.
@Override
public Object callMethod(String interfaceName, String methodName, Class<?> definedReturnType, KeyValuePair... args) throws ServerException, UserException, ReflectorException {
try {
JsonObject request = new JsonObject();
request.add("interface", new JsonPrimitive(interfaceName));
request.add("method", new JsonPrimitive(methodName));
JsonObject parameters = new JsonObject();
for (KeyValuePair arg : args) {
parameters.add(arg.getFieldName(), converter.toJson(arg.getValue()));
}
request.add("parameters", parameters);
JsonObject requestObject = new JsonObject();
requestObject.add("request", request);
JsonObject jsonResult = call(requestObject);
if (!isOneWay()) {
if (jsonResult == null) {
return null;
}
JsonObject response = jsonResult.getAsJsonObject("response");
if (response.has("exception")) {
JsonObject exceptionJson = response.getAsJsonObject("exception");
String exceptionType = exceptionJson.get("__type").getAsString();
String message = exceptionJson.has("message") ? exceptionJson.get("message").getAsString() : "unknown";
if (exceptionType.equals(UserException.class.getSimpleName())) {
if (exceptionJson.has("errorCode")) {
throw new UserException(message, ErrorCode.parse(exceptionJson.get("errorCode").getAsInt()));
} else {
throw new UserException(message);
}
} else if (exceptionType.equals(ServerException.class.getSimpleName())) {
if (exceptionJson.has("errorCode")) {
throw new ServerException(message, ErrorCode.parse(exceptionJson.get("errorCode").getAsInt()));
} else {
throw new ServerException(message);
}
} else {
if (exceptionJson.has("errorCode")) {
throw new ServerException(message, ErrorCode.parse(exceptionJson.get("errorCode").getAsInt()));
} else {
throw new ServerException(message);
}
}
} else if (response.has("result")) {
Object result = response.get("result");
SMethod method = servicesMap.getBySimpleName(interfaceName).getSMethod(methodName);
return converter.fromJson(method.getReturnType(), method.getGenericReturnType(), result);
} else {
return null;
}
} else {
return null;
}
} catch (ReflectorException e) {
throw e;
} catch (UserException e) {
throw e;
} catch (ServerException e) {
throw e;
} catch (Exception e) {
throw new ReflectorException(e);
}
}
use of org.bimserver.shared.exceptions.UserException in project BIMserver by opensourceBIM.
the class TestInOut method start.
private void start(String[] args) {
BimServerConfig config = new BimServerConfig();
Path homeDir = Paths.get("home");
try {
if (Files.isDirectory(homeDir)) {
PathUtils.removeDirectoryWithContent(homeDir);
}
} catch (IOException e) {
e.printStackTrace();
}
config.setClassPath(System.getProperty("java.class.path"));
config.setHomeDir(homeDir);
config.setPort(8080);
config.setStartEmbeddedWebServer(true);
config.setResourceFetcher(new LocalDevelopmentResourceFetcher(Paths.get("../")));
BimServer bimServer = new BimServer(config);
try {
LocalDevPluginLoader.loadPlugins(bimServer.getPluginManager(), new OptionsParser(args).getPluginDirectories());
bimServer.start();
if (bimServer.getServerInfo().getServerState() == ServerState.NOT_SETUP) {
AdminInterface adminInterface = bimServer.getServiceFactory().get(new SystemAuthorization(1, TimeUnit.HOURS), AccessMethod.INTERNAL).get(AdminInterface.class);
adminInterface.setup("http://localhost:8080", "Administrator", "admin@bimserver.org", "admin", null, null, null);
SettingsInterface settingsInterface = bimServer.getServiceFactory().get(new SystemAuthorization(1, TimeUnit.HOURS), AccessMethod.INTERNAL).get(SettingsInterface.class);
settingsInterface.setCacheOutputFiles(false);
}
BimServerClientInterface client = LocalDevSetup.setupJson("http://localhost:8080");
SProject project = client.getServiceInterface().addProject("test", "ifc2x3tc1");
SDeserializerPluginConfiguration deserializer = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
Path inputFile = Paths.get("../TestData/data/AC11-Institute-Var-2-IFC.ifc");
client.checkin(project.getOid(), "test", deserializer.getOid(), false, Flow.SYNC, inputFile);
project = client.getServiceInterface().getProjectByPoid(project.getOid());
SSerializerPluginConfiguration serializer = client.getServiceInterface().getSerializerByContentType("application/ifc");
Path outputFile = Paths.get("output.ifc");
client.download(project.getLastRevisionId(), serializer.getOid(), outputFile);
Diff diff = new Diff(false, false, false, inputFile, outputFile);
diff.start();
} catch (ServerException e) {
e.printStackTrace();
} catch (DatabaseInitException e) {
e.printStackTrace();
} catch (BimserverDatabaseException e) {
e.printStackTrace();
} catch (PluginException e) {
e.printStackTrace();
} catch (DatabaseRestartRequiredException e) {
e.printStackTrace();
} catch (UserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (PublicInterfaceNotFoundException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (CompareException e) {
e.printStackTrace();
} catch (BimServerClientException e) {
e.printStackTrace();
}
}
use of org.bimserver.shared.exceptions.UserException in project BIMserver by opensourceBIM.
the class TestManyRevisions method start.
private void start(String[] args) {
try {
Path home = Paths.get("home");
PluginManager pluginManager = LocalDevPluginLoader.createPluginManager(home);
MetaDataManager metaDataManager = new MetaDataManager(home.resolve("tmp"));
pluginManager.setMetaDataManager(metaDataManager);
try (BimServerClientFactory factory = new JsonBimServerClientFactory(metaDataManager, "http://localhost:8080")) {
BimServerClientInterface client = factory.create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
try {
SProject project = client.getServiceInterface().addProject("lots2", "ifc2x3tc1");
Path[] files = new Path[] { Paths.get("../TestData/data/AC11-Institute-Var-2-IFC.ifc"), Paths.get("../TestData/data/AC11-FZK-Haus-IFC - Alt.ifc") };
SDeserializerPluginConfiguration deserializer = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
int fn = 0;
for (int i = 0; i < 20; i++) {
System.out.println(i + ": " + files[fn].getFileName().toString());
client.checkin(project.getOid(), "comment" + i, deserializer.getOid(), false, Flow.SYNC, files[fn]);
fn = 1 - fn;
}
} catch (ServerException | UserException | PublicInterfaceNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.bimserver.shared.exceptions.UserException in project BIMserver by opensourceBIM.
the class SyndicationServlet method writeCheckoutsFeed.
private void writeCheckoutsFeed(HttpServletRequest request, HttpServletResponse response, ServiceMap serviceMap) throws ServiceException, IOException, FeedException, PublicInterfaceNotFoundException {
long poid = Long.parseLong(request.getParameter("poid"));
SProject sProject = serviceMap.getServiceInterface().getProjectByPoid(poid);
SyndFeed feed = new SyndFeedImpl();
feed.setFeedType(FEED_TYPE);
feed.setTitle("BIMserver.org checkouts feed for project '" + sProject.getName() + "'");
feed.setLink(request.getContextPath());
feed.setDescription("This feed represents all the checkouts of project '" + sProject.getName() + "'");
List<SyndEntry> entries = new ArrayList<SyndEntry>();
try {
List<SCheckout> allCheckoutsOfProject = serviceMap.getServiceInterface().getAllCheckoutsOfProjectAndSubProjects(poid);
for (SCheckout sCheckout : allCheckoutsOfProject) {
SRevision revision = serviceMap.getServiceInterface().getRevision(sCheckout.getRevision().getOid());
SProject project = serviceMap.getServiceInterface().getProjectByPoid(sCheckout.getProjectId());
SUser user = serviceMap.getServiceInterface().getUserByUoid(sCheckout.getUserId());
SyndEntry entry = new SyndEntryImpl();
entry.setTitle("Checkout on " + project.getName() + ", revision " + revision.getId());
entry.setLink(request.getContextPath() + "/project.jsp?poid=" + sProject.getOid());
entry.setPublishedDate(sCheckout.getDate());
SyndContent description = new SyndContentImpl();
description.setType("text/plain");
description.setValue("<table><tr><td>User</td><td>" + user.getUsername() + "</td></tr><tr><td>Revision</td><td>" + sCheckout.getRevision().getOid() + "</td></tr></table>");
entry.setDescription(description);
entries.add(entry);
}
} catch (UserException e) {
LOGGER.error("", e);
}
feed.setEntries(entries);
SyndFeedOutput output = new SyndFeedOutput();
output.output(feed, response.getWriter());
}
Aggregations