Skip to content
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
32 changes: 5 additions & 27 deletions src/main/java/config.java
Original file line number Diff line number Diff line change
@@ -1,36 +1,14 @@
/////////////////////////////////////////////////////////////////////
// Copyright (c) Autodesk, Inc. All rights reserved
// Written by Forge Partner Development
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
/////////////////////////////////////////////////////////////////////
package forgesample;

import java.util.ArrayList;

public class config {

// set environment variables or hard-code here

public static class credentials{

//get client id or secret from environment
// set environment variables or hard-code here
public static class credentials{
public static String client_id = System.getenv("FORGE_CLIENT_ID");
public static String client_secret = System.getenv("FORGE_CLIENT_SECRET");
//OR
//public static String client_id = "<your client id>";
//public static String client_secret = "<your client secret>";
};

};

// Required scopes for your application on server-side
public static ArrayList<String> scopeInternal = new ArrayList<String>() {{
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/modelderivative.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package forgesample;

import java.io.BufferedReader;
import java.io.IOException;
import java.util.Arrays;
Expand All @@ -10,15 +12,18 @@

import org.json.JSONObject;

import com.autodesk.client.auth.OAuth2TwoLegged;
import com.autodesk.client.auth.OAuth2TwoLegged;
import com.autodesk.client.ApiException;
import com.autodesk.client.ApiResponse;
import com.autodesk.client.api.*;
import com.autodesk.client.model.*;

@WebServlet({ "/modelderivative" })
@WebServlet(name = "modelderivative",
urlPatterns = {"/api/forge/modelderivative/jobs", "/modelderivative"})
public class modelderivative extends HttpServlet {

private static final long serialVersionUID = 1L;

public modelderivative() {
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/oauth.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package forgesample;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/oauthtoken.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package forgesample;

import org.codehaus.jettison.json.JSONObject;
import org.joda.time.DateTime;

Expand All @@ -12,9 +14,12 @@

import com.autodesk.client.auth.OAuth2TwoLegged;

@WebServlet({ "/oauthtoken" })
@WebServlet(name = "oauthtoken",
urlPatterns = {"/api/forge/oauth/token", "/oauthtoken"})
public class oauthtoken extends HttpServlet {

private static final long serialVersionUID = 1L;

public oauthtoken() {
}

Expand Down
10 changes: 8 additions & 2 deletions src/main/java/oss.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package forgesample;

import java.io.*;

import javax.servlet.ServletException;
Expand All @@ -14,9 +16,12 @@
import com.autodesk.client.model.*;


@WebServlet({ "/oss" })
@WebServlet(name = "oss",
urlPatterns = {"/api/forge/oss/buckets", "/oss"})
public class oss extends HttpServlet {

private static final long serialVersionUID = 1L;

public oss() {
}

Expand All @@ -37,6 +42,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se
if (id.equals("#")) {// root
BucketsApi bucketsApi = new BucketsApi();

//replace the first param with other values if it is other region, such as 'emea'
ApiResponse<Buckets> buckets = bucketsApi.getBuckets("us", 100, null, forgeOAuth,
forgeOAuth.getCredentials());

Expand Down Expand Up @@ -161,4 +167,4 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws S
public void destroy() {
super.destroy();
}
}
}
11 changes: 9 additions & 2 deletions src/main/java/ossuploads.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package forgesample;

import java.io.*;
import java.util.Iterator;
import java.util.List;
Expand All @@ -13,15 +15,20 @@
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;

import com.autodesk.client.auth.OAuth2TwoLegged;
import com.autodesk.client.auth.OAuth2TwoLegged;

import com.autodesk.client.ApiException;
import com.autodesk.client.ApiResponse;
import com.autodesk.client.api.ObjectsApi;
import com.autodesk.client.model.ObjectDetails;

@WebServlet({ "/ossuploads" })

@WebServlet(name = "ossuploads",
urlPatterns = {"/api/forge/oss/objects", "/ossuploads"})
public class ossuploads extends HttpServlet {

private static final long serialVersionUID = 1L;

public ossuploads() {
}

Expand Down
53 changes: 6 additions & 47 deletions src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
@@ -1,48 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >

<servlet>
<servlet-name>oauthtoken</servlet-name>
<servlet-class>oauthtoken</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>oauthtoken</servlet-name>
<url-pattern>/api/forge/oauth/token</url-pattern>
</servlet-mapping>

<servlet>
<servlet-name>oss</servlet-name>
<servlet-class>oss</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>oss</servlet-name>
<url-pattern>/api/forge/oss/buckets</url-pattern>
</servlet-mapping>

<servlet>
<servlet-name>modelderivative</servlet-name>
<servlet-class>modelderivative</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>modelderivative</servlet-name>
<url-pattern>/api/forge/modelderivative/jobs</url-pattern>
</servlet-mapping>

<servlet>
<servlet-name>ossuploads</servlet-name>
<servlet-class>ossuploads</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>ossuploads</servlet-name>
<url-pattern>/api/forge/oss/objects</url-pattern>
</servlet-mapping>


</web-app>
<web-app>
<display-name>Archetype Created Web Application</display-name>
</web-app>
4 changes: 2 additions & 2 deletions src/main/webapp/css/main.css
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
html, body{
html, body {
min-height: 100%;
height: 100%;
}

.fill{
.fill {
height: calc(100vh - 100px);
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/webapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>

<head>
<title>Autodesk Forge Tutorial</title>
<title>View Models - Autodesk Forge</title>
<meta charset="utf-8" />
<link rel="shortcut icon" href="https://github.com/Autodesk-Forge/learn.forge.viewmodels/raw/master/img/favicon.ico">
<!-- Common packages: jQuery, Bootstrap, jsTree -->
Expand All @@ -26,7 +26,7 @@
<div class="container-fluid">
<ul class="nav navbar-nav left">
<li>
<a href="http://developer.autodesk.com" target="_blank">
<a href="http://forge.autodesk.com" target="_blank">
<img alt="Autodesk Forge" src="//developer.static.autodesk.com/images/logo_forge-2-line.png" height="20">
</a>
</li>
Expand Down Expand Up @@ -85,4 +85,4 @@ <h4 class="modal-title" id="myModalLabel">Create new bucket</h4>
</div>
</body>

</html>
</html>
56 changes: 29 additions & 27 deletions src/main/webapp/js/ForgeTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,40 @@ $(document).ready(function () {
$('#createBucketModal').on('shown.bs.modal', function () {
$("#newBucketKey").focus();
})

$('#hiddenUploadField').change(function () {
var node = $('#appBuckets').jstree(true).get_selected(true)[0];
var _this = this;
if (_this.files.length == 0) return;
var file = _this.files[0];
switch (node.type) {
case 'bucket':
var formData = new FormData();
formData.append('fileToUpload', file);
formData.append('bucketKey', node.id);

$.ajax({
url: '/api/forge/oss/objects',
data: formData,
processData: false,
contentType: false,
type: 'POST',
success: function (data) {
$('#appBuckets').jstree(true).refresh_node(node);
_this.value = '';
}
});
break;
}
});
});

function createNewBucket() {
var bucketKey = $('#newBucketKey').val();
var policyKey = $('#newBucketPolicyKey').val();
jQuery.post({
url: '/api/forge/oss/buckets',
contentType: 'application/json',
data: JSON.stringify({ 'bucketKey': bucketKey, 'policyKey': policyKey }),
data: JSON.stringify({ 'bucketKey': bucketKey }),
success: function (res) {
$('#appBuckets').jstree(true).refresh();
$('#createBucketModal').modal('toggle');
Expand Down Expand Up @@ -96,8 +121,7 @@ function autodeskCustomMenu(autodeskNode) {
uploadFile: {
label: "Upload file",
action: function () {
var treeNode = $('#appBuckets').jstree(true).get_selected(true)[0];
uploadFile(treeNode);
uploadFile();
},
icon: 'glyphicon glyphicon-cloud-upload'
}
Expand All @@ -120,30 +144,8 @@ function autodeskCustomMenu(autodeskNode) {
return items;
}

function uploadFile(node) {
function uploadFile() {
$('#hiddenUploadField').click();
$('#hiddenUploadField').change(function () {
if (this.files.length == 0) return;
var file = this.files[0];
switch (node.type) {
case 'bucket':
var formData = new FormData();
formData.append('fileToUpload', file);
formData.append('bucketKey', node.id);

$.ajax({
url: '/api/forge/oss/objects',
data: formData,
processData: false,
contentType: false,
type: 'POST',
success: function (data) {
$('#appBuckets').jstree(true).refresh_node(node);
}
});
break;
}
});
}

function translateObject(node) {
Expand Down
24 changes: 3 additions & 21 deletions src/main/webapp/js/ForgeViewer.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
/////////////////////////////////////////////////////////////////////
// Copyright (c) Autodesk, Inc. All rights reserved
// Written by Forge Partner Development
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
/////////////////////////////////////////////////////////////////////

var viewer;

function launchViewer(urn) {
Expand All @@ -25,7 +7,7 @@ function launchViewer(urn) {
};

Autodesk.Viewing.Initializer(options, () => {
viewer = new Autodesk.Viewing.GuiViewer3D(document.getElementById('forgeViewer'));
viewer = new Autodesk.Viewing.GuiViewer3D(document.getElementById('forgeViewer'), { extensions: [ 'Autodesk.DocumentBrowser'] });
viewer.start();
var documentId = 'urn:' + urn;
Autodesk.Viewing.Document.load(documentId, onDocumentLoadSuccess, onDocumentLoadFailure);
Expand All @@ -39,8 +21,8 @@ function onDocumentLoadSuccess(doc) {
});
}

function onDocumentLoadFailure(viewerErrorCode) {
console.error('onDocumentLoadFailure() - errorCode:' + viewerErrorCode);
function onDocumentLoadFailure(viewerErrorCode, viewerErrorMsg) {
console.error('onDocumentLoadFailure() - errorCode:' + viewerErrorCode + '\n- errorMessage:' + viewerErrorMsg);
}

function getForgeToken(callback) {
Expand Down