diff --git a/Dockerfile b/Dockerfile index 9ea8d2ad..f485f1de 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM sismics/debian-java7-jetty9 MAINTAINER benjamin.gam@gmail.com -RUN apt-get -y -q install tesseract-ocr tesseract-ocr-fra +RUN apt-get -y -q install tesseract-ocr tesseract-ocr-fra tesseract-ocr-jpn ENV TESSDATA_PREFIX /usr/share/tesseract-ocr ENV LC_NUMERIC C diff --git a/docs-android/app/src/main/java/com/sismics/docs/MainApplication.java b/docs-android/app/src/main/java/com/sismics/docs/MainApplication.java index 232f224b..340abdbf 100644 --- a/docs-android/app/src/main/java/com/sismics/docs/MainApplication.java +++ b/docs-android/app/src/main/java/com/sismics/docs/MainApplication.java @@ -20,7 +20,7 @@ public class MainApplication extends Application { JSONObject json = PreferenceUtil.getCachedJson(getApplicationContext(), PreferenceUtil.PREF_CACHED_USER_INFO_JSON); ApplicationContext.getInstance().setUserInfo(getApplicationContext(), json); - // TODO Fullscreen preview + // TODO google docs app: right drawer with all actions, with acls, with deep metadatas // TODO Provide documents to intent action get content super.onCreate(); diff --git a/docs-android/app/src/main/java/com/sismics/docs/activity/DocumentViewActivity.java b/docs-android/app/src/main/java/com/sismics/docs/activity/DocumentViewActivity.java index f927e9ae..5ecc3dee 100644 --- a/docs-android/app/src/main/java/com/sismics/docs/activity/DocumentViewActivity.java +++ b/docs-android/app/src/main/java/com/sismics/docs/activity/DocumentViewActivity.java @@ -12,7 +12,9 @@ import android.os.Build; import android.os.Bundle; import android.os.Environment; import android.support.v4.app.DialogFragment; +import android.support.v4.view.GravityCompat; import android.support.v4.view.ViewPager; +import android.support.v4.widget.DrawerLayout; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.text.TextUtils; @@ -21,11 +23,14 @@ import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; +import android.widget.Button; import android.widget.ImageView; +import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; import com.sismics.docs.R; +import com.sismics.docs.adapter.AclListAdapter; import com.sismics.docs.adapter.FilePagerAdapter; import com.sismics.docs.event.DocumentDeleteEvent; import com.sismics.docs.event.DocumentEditEvent; @@ -184,6 +189,58 @@ public class DocumentViewActivity extends AppCompatActivity { ImageView sharedImageView = (ImageView) findViewById(R.id.sharedImageView); sharedImageView.setVisibility(shared ? View.VISIBLE : View.GONE); + // Action edit document + Button button = (Button) findViewById(R.id.actionEditDocument); + button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(DocumentViewActivity.this, DocumentEditActivity.class); + intent.putExtra("document", DocumentViewActivity.this.document.toString()); + startActivityForResult(intent, REQUEST_CODE_EDIT_DOCUMENT); + } + }); + + // Action upload file + button = (Button) findViewById(R.id.actionUploadFile); + button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(Intent.ACTION_GET_CONTENT) + .setType("*/*") + .putExtra("android.intent.extra.ALLOW_MULTIPLE", true) + .addCategory(Intent.CATEGORY_OPENABLE); + startActivityForResult(Intent.createChooser(intent, getText(R.string.upload_from)), REQUEST_CODE_ADD_FILE); + } + }); + + // Action download document + button = (Button) findViewById(R.id.actionDownload); + button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + downloadZip(); + } + }); + + // Action delete document + button = (Button) findViewById(R.id.actionDelete); + button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + deleteDocument(); + } + }); + + // Action share + button = (Button) findViewById(R.id.actionSharing); + button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + DialogFragment dialog = DocShareFragment.newInstance(DocumentViewActivity.this.document.optString("id")); + dialog.show(getSupportFragmentManager(), "DocShareFragment"); + } + }); + // Grab the attached files updateFiles(); @@ -202,41 +259,23 @@ public class DocumentViewActivity extends AppCompatActivity { @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { + case R.id.info: + DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); + if (drawerLayout.isDrawerVisible(GravityCompat.END)) { + drawerLayout.closeDrawer(GravityCompat.END); + } else { + drawerLayout.openDrawer(GravityCompat.END); + } + return true; + case R.id.download_file: downloadCurrentFile(); return true; - case R.id.download_document: - downloadZip(); - return true; - - case R.id.share: - DialogFragment dialog = DocShareFragment.newInstance(document.optString("id")); - dialog.show(getSupportFragmentManager(), "DocShareFragment"); - return true; - - case R.id.upload_file: - Intent intent = new Intent(Intent.ACTION_GET_CONTENT) - .setType("*/*") - .putExtra("android.intent.extra.ALLOW_MULTIPLE", true) - .addCategory(Intent.CATEGORY_OPENABLE); - startActivityForResult(Intent.createChooser(intent, getText(R.string.upload_from)), REQUEST_CODE_ADD_FILE); - return true; - - case R.id.edit: - intent = new Intent(this, DocumentEditActivity.class); - intent.putExtra("document", document.toString()); - startActivityForResult(intent, REQUEST_CODE_EDIT_DOCUMENT); - return true; - case R.id.delete_file: deleteCurrentFile(); return true; - case R.id.delete_document: - deleteDocument(); - return true; - case android.R.id.home: finish(); return true; @@ -514,17 +553,21 @@ public class DocumentViewActivity extends AppCompatActivity { DocumentResource.get(this, document.optString("id"), new JsonHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, JSONObject response) { - boolean writable = response.optBoolean("writable"); + document = response; + boolean writable = document.optBoolean("writable"); if (menu != null) { - menu.findItem(R.id.share).setVisible(writable); - menu.findItem(R.id.upload_file).setVisible(writable); - menu.findItem(R.id.edit).setVisible(writable); menu.findItem(R.id.delete_file).setVisible(writable); - menu.findItem(R.id.delete_document).setVisible(writable); } - // TODO Show the ACLs in a sliding panel from the right + findViewById(R.id.actionEditDocument).setVisibility(writable ? View.VISIBLE : View.INVISIBLE); + findViewById(R.id.actionUploadFile).setVisibility(writable ? View.VISIBLE : View.INVISIBLE); + findViewById(R.id.actionSharing).setVisibility(writable ? View.VISIBLE : View.INVISIBLE); + findViewById(R.id.actionDelete).setVisibility(writable ? View.VISIBLE : View.INVISIBLE); + + // ACLs + ListView aclListView = (ListView) findViewById(R.id.aclListView); + aclListView.setAdapter(new AclListAdapter(document.optJSONArray("acls"))); } }); } diff --git a/docs-android/app/src/main/java/com/sismics/docs/adapter/AclListAdapter.java b/docs-android/app/src/main/java/com/sismics/docs/adapter/AclListAdapter.java new file mode 100644 index 00000000..f7aabce7 --- /dev/null +++ b/docs-android/app/src/main/java/com/sismics/docs/adapter/AclListAdapter.java @@ -0,0 +1,77 @@ +package com.sismics.docs.adapter; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.TextView; + +import com.sismics.docs.R; + +import org.json.JSONArray; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.List; + +/** + * ACL list adapter. + * + * @author bgamard. + */ +public class AclListAdapter extends BaseAdapter { + /** + * Shares. + */ + private List acls; + + /** + * ACL list adapter. + * + * @param acls ACLs + */ + public AclListAdapter(JSONArray acls) { + this.acls = new ArrayList<>(); + + // Extract only share ACLs + for (int i = 0; i < acls.length(); i++) { + JSONObject acl = acls.optJSONObject(i); + this.acls.add(acl); + } + } + + @Override + public int getCount() { + return acls.size(); + } + + @Override + public JSONObject getItem(int position) { + return acls.get(position); + } + + @Override + public long getItemId(int position) { + return getItem(position).optString("id").hashCode(); + } + + @Override + public View getView(int position, View view, final ViewGroup parent) { + if (view == null) { + LayoutInflater vi = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); + view = vi.inflate(R.layout.acl_list_item, parent, false); + } + + // Fill the view + final JSONObject acl = getItem(position); + TextView typeTextView = (TextView) view.findViewById(R.id.typeTextView); + typeTextView.setText(acl.optString("type")); + TextView nameTextView = (TextView) view.findViewById(R.id.nameTextView); + nameTextView.setText(acl.optString("name")); + TextView permTextView = (TextView) view.findViewById(R.id.permTextView); + permTextView.setText(acl.optString("perm")); + + return view; + } +} diff --git a/docs-android/app/src/main/res/drawable-xhdpi/ic_create_grey600_24dp.png b/docs-android/app/src/main/res/drawable-xhdpi/ic_create_grey600_24dp.png new file mode 100644 index 00000000..4c95bd57 Binary files /dev/null and b/docs-android/app/src/main/res/drawable-xhdpi/ic_create_grey600_24dp.png differ diff --git a/docs-android/app/src/main/res/drawable-xhdpi/ic_create_white_24dp.png b/docs-android/app/src/main/res/drawable-xhdpi/ic_create_white_24dp.png deleted file mode 100644 index 7f0ea51b..00000000 Binary files a/docs-android/app/src/main/res/drawable-xhdpi/ic_create_white_24dp.png and /dev/null differ diff --git a/docs-android/app/src/main/res/drawable-xhdpi/ic_file_download_grey600_24dp.png b/docs-android/app/src/main/res/drawable-xhdpi/ic_file_download_grey600_24dp.png new file mode 100644 index 00000000..aa89d497 Binary files /dev/null and b/docs-android/app/src/main/res/drawable-xhdpi/ic_file_download_grey600_24dp.png differ diff --git a/docs-android/app/src/main/res/drawable-xhdpi/ic_file_upload_grey600_24dp.png b/docs-android/app/src/main/res/drawable-xhdpi/ic_file_upload_grey600_24dp.png new file mode 100644 index 00000000..908b1567 Binary files /dev/null and b/docs-android/app/src/main/res/drawable-xhdpi/ic_file_upload_grey600_24dp.png differ diff --git a/docs-android/app/src/main/res/drawable-xhdpi/ic_info_white_24dp.png b/docs-android/app/src/main/res/drawable-xhdpi/ic_info_white_24dp.png new file mode 100644 index 00000000..bee33abb Binary files /dev/null and b/docs-android/app/src/main/res/drawable-xhdpi/ic_info_white_24dp.png differ diff --git a/docs-android/app/src/main/res/drawable-xhdpi/ic_people_grey600_24dp.png b/docs-android/app/src/main/res/drawable-xhdpi/ic_people_grey600_24dp.png new file mode 100644 index 00000000..8fabd783 Binary files /dev/null and b/docs-android/app/src/main/res/drawable-xhdpi/ic_people_grey600_24dp.png differ diff --git a/docs-android/app/src/main/res/drawable-xxhdpi/ic_create_grey600_24dp.png b/docs-android/app/src/main/res/drawable-xxhdpi/ic_create_grey600_24dp.png new file mode 100644 index 00000000..6ed4351c Binary files /dev/null and b/docs-android/app/src/main/res/drawable-xxhdpi/ic_create_grey600_24dp.png differ diff --git a/docs-android/app/src/main/res/drawable-xxhdpi/ic_create_white_24dp.png b/docs-android/app/src/main/res/drawable-xxhdpi/ic_create_white_24dp.png deleted file mode 100644 index 34ec7092..00000000 Binary files a/docs-android/app/src/main/res/drawable-xxhdpi/ic_create_white_24dp.png and /dev/null differ diff --git a/docs-android/app/src/main/res/drawable-xxhdpi/ic_file_download_grey600_24dp.png b/docs-android/app/src/main/res/drawable-xxhdpi/ic_file_download_grey600_24dp.png new file mode 100644 index 00000000..e61a48a4 Binary files /dev/null and b/docs-android/app/src/main/res/drawable-xxhdpi/ic_file_download_grey600_24dp.png differ diff --git a/docs-android/app/src/main/res/drawable-xxhdpi/ic_file_upload_grey600_24dp.png b/docs-android/app/src/main/res/drawable-xxhdpi/ic_file_upload_grey600_24dp.png new file mode 100644 index 00000000..77d80081 Binary files /dev/null and b/docs-android/app/src/main/res/drawable-xxhdpi/ic_file_upload_grey600_24dp.png differ diff --git a/docs-android/app/src/main/res/drawable-xxhdpi/ic_info_white_24dp.png b/docs-android/app/src/main/res/drawable-xxhdpi/ic_info_white_24dp.png new file mode 100644 index 00000000..185d18d1 Binary files /dev/null and b/docs-android/app/src/main/res/drawable-xxhdpi/ic_info_white_24dp.png differ diff --git a/docs-android/app/src/main/res/drawable-xxhdpi/ic_people_grey600_24dp.png b/docs-android/app/src/main/res/drawable-xxhdpi/ic_people_grey600_24dp.png new file mode 100644 index 00000000..198a5795 Binary files /dev/null and b/docs-android/app/src/main/res/drawable-xxhdpi/ic_people_grey600_24dp.png differ diff --git a/docs-android/app/src/main/res/layout/acl_list_item.xml b/docs-android/app/src/main/res/layout/acl_list_item.xml new file mode 100644 index 00000000..40384f83 --- /dev/null +++ b/docs-android/app/src/main/res/layout/acl_list_item.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/docs-android/app/src/main/res/layout/document_view_activity.xml b/docs-android/app/src/main/res/layout/document_view_activity.xml index bae34ac1..19744f59 100644 --- a/docs-android/app/src/main/res/layout/document_view_activity.xml +++ b/docs-android/app/src/main/res/layout/document_view_activity.xml @@ -1,85 +1,16 @@ - - - - - - - - - - - - - - - - + + android:layout_height="match_parent"> - \ No newline at end of file + + + + + + + + + + + + +
+ + -
-
-
- - - -
-
- +
+

+ {{ file.status }} +

+
+
-
- -
-
-
-

- {{ file.status }} -

-
- -
-
+

+ + Drag & drop files here to upload +

-

- - Drag & drop files here to upload -

-
- -
- +
+ +
-
-
    -
  • Version: {{ app.current_version }}
  • -
  • Memory: {{ app.free_memory / 1000000 | number: 0 }}/{{ app.total_memory / 1000000 | number: 0 }} MB
  • -
-
+
+

Latest activity

+ +
+ +
+
    +
  • Version: {{ app.current_version }}
  • +
  • Memory: {{ app.free_memory / 1000000 | number: 0 }}/{{ app.total_memory / 1000000 | number: 0 }} MB
  • +
+
\ No newline at end of file diff --git a/docs-web/src/main/webapp/src/partial/docs/document.html b/docs-web/src/main/webapp/src/partial/docs/document.html index 1d773b59..e4b91b11 100644 --- a/docs-web/src/main/webapp/src/partial/docs/document.html +++ b/docs-web/src/main/webapp/src/partial/docs/document.html @@ -68,6 +68,6 @@
-
+
\ No newline at end of file diff --git a/docs-web/src/main/webapp/src/partial/docs/document.view.html b/docs-web/src/main/webapp/src/partial/docs/document.view.html index 1560225c..2643b426 100644 --- a/docs-web/src/main/webapp/src/partial/docs/document.view.html +++ b/docs-web/src/main/webapp/src/partial/docs/document.view.html @@ -1,4 +1,11 @@ - + + +
+

+ + Document not found +

+
@@ -135,6 +142,14 @@
+ + + + Activity + + + +
diff --git a/docs-web/src/main/webapp/src/partial/docs/file.view.html b/docs-web/src/main/webapp/src/partial/docs/file.view.html index b0ecd077..8bf1cdb1 100644 --- a/docs-web/src/main/webapp/src/partial/docs/file.view.html +++ b/docs-web/src/main/webapp/src/partial/docs/file.view.html @@ -22,5 +22,12 @@
- + +

+ + File not found +

diff --git a/docs-web/src/main/webapp/src/partial/docs/settings.html b/docs-web/src/main/webapp/src/partial/docs/settings.html index 6434e06b..d3246e12 100644 --- a/docs-web/src/main/webapp/src/partial/docs/settings.html +++ b/docs-web/src/main/webapp/src/partial/docs/settings.html @@ -18,6 +18,6 @@
-
+
\ No newline at end of file diff --git a/docs-web/src/main/webapp/src/partial/docs/settings.session.html b/docs-web/src/main/webapp/src/partial/docs/settings.session.html index e2f1794d..8d32a86d 100644 --- a/docs-web/src/main/webapp/src/partial/docs/settings.session.html +++ b/docs-web/src/main/webapp/src/partial/docs/settings.session.html @@ -4,6 +4,7 @@ Created date Last connection date + From Current @@ -11,6 +12,7 @@ {{ session.create_date | date: 'yyyy-MM-dd HH:mm' }} {{ session.last_connection_date | date: 'yyyy-MM-dd HH:mm' }} + {{ session.ip }} diff --git a/docs-web/src/main/webapp/src/partial/docs/tag.html b/docs-web/src/main/webapp/src/partial/docs/tag.html index 5f8d465c..c8f02165 100644 --- a/docs-web/src/main/webapp/src/partial/docs/tag.html +++ b/docs-web/src/main/webapp/src/partial/docs/tag.html @@ -30,18 +30,14 @@
-
-

{{ tags.length }} tag{{ tags.length > 1 ? 's' : '' }}

-
-
{{ stat.name }} {{ stat.count }}
-
-
-
+

{{ tags.length }} tag{{ tags.length > 1 ? 's' : '' }}

+
+
{{ stat.name }} {{ stat.count }}
+
+
-
- -
+
\ No newline at end of file diff --git a/docs-web/src/prod/resources/config.properties b/docs-web/src/prod/resources/config.properties index 04b5153a..f935e8fa 100644 --- a/docs-web/src/prod/resources/config.properties +++ b/docs-web/src/prod/resources/config.properties @@ -1,3 +1,3 @@ api.current_version=${project.version} api.min_version=1.0 -db.version=9 \ No newline at end of file +db.version=10 \ No newline at end of file diff --git a/docs-web/src/test/java/com/sismics/docs/rest/TestAppResource.java b/docs-web/src/test/java/com/sismics/docs/rest/TestAppResource.java index 3c79eb07..64e2e7fb 100644 --- a/docs-web/src/test/java/com/sismics/docs/rest/TestAppResource.java +++ b/docs-web/src/test/java/com/sismics/docs/rest/TestAppResource.java @@ -41,7 +41,6 @@ public class TestAppResource extends BaseJerseyTest { Assert.assertTrue(freeMemory > 0); Long totalMemory = json.getLong("total_memory"); Assert.assertTrue(totalMemory > 0 && totalMemory > freeMemory); - Assert.assertEquals(0, json.getInt("document_count")); // Rebuild Lucene index appResource = resource().path("/app/batch/reindex"); diff --git a/docs-web/src/test/java/com/sismics/docs/rest/TestAuditLogResource.java b/docs-web/src/test/java/com/sismics/docs/rest/TestAuditLogResource.java new file mode 100644 index 00000000..c94ad714 --- /dev/null +++ b/docs-web/src/test/java/com/sismics/docs/rest/TestAuditLogResource.java @@ -0,0 +1,98 @@ +package com.sismics.docs.rest; + +import java.util.Date; + +import com.sismics.docs.rest.filter.CookieAuthenticationFilter; +import com.sun.jersey.api.client.ClientResponse; +import com.sun.jersey.api.client.ClientResponse.Status; +import com.sun.jersey.api.client.WebResource; +import com.sun.jersey.core.util.MultivaluedMapImpl; + +import junit.framework.Assert; + +import org.codehaus.jettison.json.JSONArray; +import org.codehaus.jettison.json.JSONException; +import org.codehaus.jettison.json.JSONObject; +import org.junit.Test; + +/** + * Test the audit log resource. + * + * @author bgamard + */ +public class TestAuditLogResource extends BaseJerseyTest { + /** + * Test the audit log resource. + * + * @throws JSONException + */ + @Test + public void testAuditLogResource() throws JSONException { + // Login auditlog1 + clientUtil.createUser("auditlog1"); + String auditlog1Token = clientUtil.login("auditlog1"); + + // Create a tag + WebResource tagResource = resource().path("/tag"); + tagResource.addFilter(new CookieAuthenticationFilter(auditlog1Token)); + MultivaluedMapImpl postParams = new MultivaluedMapImpl(); + postParams.add("name", "SuperTag"); + postParams.add("color", "#ffff00"); + ClientResponse response = tagResource.put(ClientResponse.class, postParams); + Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus())); + JSONObject json = response.getEntity(JSONObject.class); + String tag1Id = json.optString("id"); + Assert.assertNotNull(tag1Id); + + // Create a document + WebResource documentResource = resource().path("/document"); + documentResource.addFilter(new CookieAuthenticationFilter(auditlog1Token)); + postParams = new MultivaluedMapImpl(); + postParams.add("title", "My super title document 1"); + postParams.add("description", "My super description for document 1"); + postParams.add("tags", tag1Id); + postParams.add("language", "eng"); + long create1Date = new Date().getTime(); + postParams.add("create_date", create1Date); + response = documentResource.put(ClientResponse.class, postParams); + Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus())); + json = response.getEntity(JSONObject.class); + String document1Id = json.optString("id"); + Assert.assertNotNull(document1Id); + + // Get all logs for the document + WebResource auditLogResource = resource().path("/auditlog"); + auditLogResource.addFilter(new CookieAuthenticationFilter(auditlog1Token)); + response = auditLogResource.queryParam("document", document1Id).get(ClientResponse.class); + Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus())); + json = response.getEntity(JSONObject.class); + JSONArray logs = json.getJSONArray("logs"); + Assert.assertTrue(logs.length() == 3); + + // Get all logs for the current user + auditLogResource = resource().path("/auditlog"); + auditLogResource.addFilter(new CookieAuthenticationFilter(auditlog1Token)); + response = auditLogResource.get(ClientResponse.class); + Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus())); + json = response.getEntity(JSONObject.class); + logs = json.getJSONArray("logs"); + Assert.assertTrue(logs.length() == 3); + + // Deletes a tag + tagResource = resource().path("/tag/" + tag1Id); + tagResource.addFilter(new CookieAuthenticationFilter(auditlog1Token)); + response = tagResource.delete(ClientResponse.class); + Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus())); + json = response.getEntity(JSONObject.class); + Assert.assertEquals("ok", json.getString("status")); + + // Get all logs for the current user + auditLogResource = resource().path("/auditlog"); + auditLogResource.addFilter(new CookieAuthenticationFilter(auditlog1Token)); + response = auditLogResource.get(ClientResponse.class); + Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus())); + json = response.getEntity(JSONObject.class); + logs = json.getJSONArray("logs"); + Assert.assertTrue(logs.length() == 4); + } +} \ No newline at end of file diff --git a/docs-web/src/test/java/com/sismics/docs/rest/TestDocumentResource.java b/docs-web/src/test/java/com/sismics/docs/rest/TestDocumentResource.java index 88ebe3b1..3e818114 100644 --- a/docs-web/src/test/java/com/sismics/docs/rest/TestDocumentResource.java +++ b/docs-web/src/test/java/com/sismics/docs/rest/TestDocumentResource.java @@ -282,8 +282,7 @@ public class TestDocumentResource extends BaseJerseyTest { documentResource = resource().path("/document/" + document1Id); documentResource.addFilter(new CookieAuthenticationFilter(document1Token)); response = documentResource.get(ClientResponse.class); - json = response.getEntity(JSONObject.class); - Assert.assertEquals(Status.BAD_REQUEST, Status.fromStatusCode(response.getStatus())); + Assert.assertEquals(Status.NOT_FOUND, Status.fromStatusCode(response.getStatus())); } /** diff --git a/docs-web/src/test/java/com/sismics/docs/rest/TestFileResource.java b/docs-web/src/test/java/com/sismics/docs/rest/TestFileResource.java index c29dfec5..dc66674d 100644 --- a/docs-web/src/test/java/com/sismics/docs/rest/TestFileResource.java +++ b/docs-web/src/test/java/com/sismics/docs/rest/TestFileResource.java @@ -178,6 +178,12 @@ public class TestFileResource extends BaseJerseyTest { json = response.getEntity(JSONObject.class); Assert.assertEquals("ok", json.getString("status")); + // Get the file data (not found) + fileResource = resource().path("/file/" + file1Id + "/data"); + fileResource.addFilter(new CookieAuthenticationFilter(file1AuthenticationToken)); + response = fileResource.get(ClientResponse.class); + Assert.assertEquals(Status.NOT_FOUND, Status.fromStatusCode(response.getStatus())); + // Check that files are deleted from FS storedFile = Paths.get(DirectoryUtil.getStorageDirectory().getPath(), file1Id).toFile(); java.io.File webFile = Paths.get(DirectoryUtil.getStorageDirectory().getPath(), file1Id + "_web").toFile(); diff --git a/docs-web/src/test/java/com/sismics/docs/rest/TestTagResource.java b/docs-web/src/test/java/com/sismics/docs/rest/TestTagResource.java index cd8d1ecf..bacedd6e 100644 --- a/docs-web/src/test/java/com/sismics/docs/rest/TestTagResource.java +++ b/docs-web/src/test/java/com/sismics/docs/rest/TestTagResource.java @@ -75,12 +75,61 @@ public class TestTagResource extends BaseJerseyTest { documentResource = resource().path("/document"); documentResource.addFilter(new CookieAuthenticationFilter(tag1Token)); postParams = new MultivaluedMapImpl(); - postParams.add("title", "My super document 1"); + postParams.add("title", "My super document 2"); postParams.add("tags", tag4Id); postParams.add("language", "eng"); response = documentResource.put(ClientResponse.class, postParams); Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus())); json = response.getEntity(JSONObject.class); + String document2Id = json.getString("id"); + + // Check tags on a document + documentResource = resource().path("/document/" + document2Id); + documentResource.addFilter(new CookieAuthenticationFilter(tag1Token)); + response = documentResource.get(ClientResponse.class); + json = response.getEntity(JSONObject.class); + Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus())); + JSONArray tags = json.getJSONArray("tags"); + Assert.assertEquals(1, tags.length()); + Assert.assertEquals(tag4Id, tags.getJSONObject(0).getString("id")); + + // Update tags on a document + documentResource = resource().path("/document/" + document2Id); + documentResource.addFilter(new CookieAuthenticationFilter(tag1Token)); + postParams = new MultivaluedMapImpl(); + postParams.add("tags", tag3Id); + postParams.add("tags", tag4Id); + response = documentResource.post(ClientResponse.class, postParams); + Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus())); + + // Check tags on a document + documentResource = resource().path("/document/" + document2Id); + documentResource.addFilter(new CookieAuthenticationFilter(tag1Token)); + response = documentResource.get(ClientResponse.class); + json = response.getEntity(JSONObject.class); + Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus())); + tags = json.getJSONArray("tags"); + Assert.assertEquals(2, tags.length()); + Assert.assertEquals(tag3Id, tags.getJSONObject(0).getString("id")); + Assert.assertEquals(tag4Id, tags.getJSONObject(1).getString("id")); + + // Update tags on a document + documentResource = resource().path("/document/" + document2Id); + documentResource.addFilter(new CookieAuthenticationFilter(tag1Token)); + postParams = new MultivaluedMapImpl(); + postParams.add("tags", tag4Id); + response = documentResource.post(ClientResponse.class, postParams); + Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus())); + + // Check tags on a document + documentResource = resource().path("/document/" + document2Id); + documentResource.addFilter(new CookieAuthenticationFilter(tag1Token)); + response = documentResource.get(ClientResponse.class); + json = response.getEntity(JSONObject.class); + Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus())); + tags = json.getJSONArray("tags"); + Assert.assertEquals(1, tags.length()); + Assert.assertEquals(tag4Id, tags.getJSONObject(0).getString("id")); // Get tag stats tagResource = resource().path("/tag/stats"); @@ -99,7 +148,7 @@ public class TestTagResource extends BaseJerseyTest { response = tagResource.get(ClientResponse.class); Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus())); json = response.getEntity(JSONObject.class); - JSONArray tags = json.getJSONArray("tags"); + tags = json.getJSONArray("tags"); Assert.assertTrue(tags.length() > 0); Assert.assertEquals("Tag4", tags.getJSONObject(1).getString("name")); Assert.assertEquals("#00ff00", tags.getJSONObject(1).getString("color")); diff --git a/docs-web/src/test/java/com/sismics/docs/rest/TestUserResource.java b/docs-web/src/test/java/com/sismics/docs/rest/TestUserResource.java index b36f3105..022f4b3f 100644 --- a/docs-web/src/test/java/com/sismics/docs/rest/TestUserResource.java +++ b/docs-web/src/test/java/com/sismics/docs/rest/TestUserResource.java @@ -144,6 +144,9 @@ public class TestUserResource extends BaseJerseyTest { Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus())); json = response.getEntity(JSONObject.class); Assert.assertTrue(json.getJSONArray("sessions").length() > 0); + JSONObject session = json.getJSONArray("sessions").getJSONObject(0); + Assert.assertEquals("127.0.0.1", session.getString("ip")); + Assert.assertTrue(session.getString("user_agent").startsWith("Java")); // Delete all sessions userResource = resource().path("/user/session");