You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2018/02/07 12:35:50 UTC

[02/11] syncope git commit: Some clean up

Some clean up


Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/06d210bf
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/06d210bf
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/06d210bf

Branch: refs/heads/2_0_X
Commit: 06d210bf8de6c9f3fb3b83c166304e3b8db0f7a8
Parents: 446ddf2
Author: Francesco Chicchiriccò <il...@apache.org>
Authored: Tue Feb 6 16:05:28 2018 +0100
Committer: Francesco Chicchiriccò <il...@apache.org>
Committed: Tue Feb 6 16:48:53 2018 +0100

----------------------------------------------------------------------
 .../client/console/panels/DerSchemaDetails.java |  5 +--
 .../console/panels/PlainSchemaDetails.java      | 15 ++++-----
 .../client/console/panels/SchemaModalPanel.java | 11 +++++--
 .../client/console/panels/VirSchemaDetails.java |  4 +--
 core/persistence-jpa/pom.xml                    | 12 ++++----
 .../attrvalue/validation/BinaryValidator.java   | 32 ++++++++++----------
 pom.xml                                         | 13 ++++----
 7 files changed, 50 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/06d210bf/client/console/src/main/java/org/apache/syncope/client/console/panels/DerSchemaDetails.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/panels/DerSchemaDetails.java b/client/console/src/main/java/org/apache/syncope/client/console/panels/DerSchemaDetails.java
index d9f8b17..716fcb1 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/panels/DerSchemaDetails.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/panels/DerSchemaDetails.java
@@ -20,7 +20,7 @@ package org.apache.syncope.client.console.panels;
 
 import de.agilecoders.wicket.core.markup.html.bootstrap.components.TooltipConfig;
 import org.apache.syncope.client.console.commons.Constants;
-import org.apache.syncope.common.lib.to.AbstractSchemaTO;
+import org.apache.syncope.common.lib.to.DerSchemaTO;
 import org.apache.wicket.PageReference;
 import org.apache.wicket.markup.html.form.TextField;
 import org.apache.wicket.model.PropertyModel;
@@ -31,7 +31,8 @@ public class DerSchemaDetails extends AbstractSchemaDetailsPanel {
 
     public DerSchemaDetails(final String id,
             final PageReference pageReference,
-            final AbstractSchemaTO schemaTO) {
+            final DerSchemaTO schemaTO) {
+
         super(id, pageReference, schemaTO);
 
         TextField<String> expression = new TextField<>("expression", new PropertyModel<String>(schemaTO, "expression"));

http://git-wip-us.apache.org/repos/asf/syncope/blob/06d210bf/client/console/src/main/java/org/apache/syncope/client/console/panels/PlainSchemaDetails.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/panels/PlainSchemaDetails.java b/client/console/src/main/java/org/apache/syncope/client/console/panels/PlainSchemaDetails.java
index 686b1bd..443703b 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/panels/PlainSchemaDetails.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/panels/PlainSchemaDetails.java
@@ -67,7 +67,8 @@ public class PlainSchemaDetails extends AbstractSchemaDetailsPanel {
     public PlainSchemaDetails(
             final String id,
             final PageReference pageReference,
-            final AbstractSchemaTO schemaTO) {
+            final PlainSchemaTO schemaTO) {
+
         super(id, pageReference, schemaTO);
 
         final AjaxDropDownChoicePanel<AttrSchemaType> type = new AjaxDropDownChoicePanel<>(
@@ -110,19 +111,19 @@ public class PlainSchemaDetails extends AbstractSchemaDetailsPanel {
 
                     @Override
                     public String getValues() {
-                        return PlainSchemaTO.class.cast(schemaTO).getEnumerationValues();
+                        return schemaTO.getEnumerationValues();
                     }
 
                     @Override
                     public void setValues(final List<String> list) {
-                        PlainSchemaTO.class.cast(schemaTO).setEnumerationValues(getEnumValuesAsString(list));
+                        schemaTO.setEnumerationValues(getEnumValuesAsString(list));
                     }
                 };
             }
 
             @Override
             public void setObject(final List<String> object) {
-                PlainSchemaTO.class.cast(schemaTO).setEnumerationValues(PropertyList.getEnumValuesAsString(object));
+                schemaTO.setEnumerationValues(PropertyList.getEnumValuesAsString(object));
             }
         }) {
 
@@ -149,19 +150,19 @@ public class PlainSchemaDetails extends AbstractSchemaDetailsPanel {
 
                     @Override
                     public String getValues() {
-                        return PlainSchemaTO.class.cast(schemaTO).getEnumerationKeys();
+                        return schemaTO.getEnumerationKeys();
                     }
 
                     @Override
                     public void setValues(final List<String> list) {
-                        PlainSchemaTO.class.cast(schemaTO).setEnumerationKeys(PropertyList.getEnumValuesAsString(list));
+                        schemaTO.setEnumerationKeys(PropertyList.getEnumValuesAsString(list));
                     }
                 };
             }
 
             @Override
             public void setObject(final List<String> object) {
-                PlainSchemaTO.class.cast(schemaTO).setEnumerationKeys(PropertyList.getEnumValuesAsString(object));
+                schemaTO.setEnumerationKeys(PropertyList.getEnumValuesAsString(object));
             }
         }) {
 

http://git-wip-us.apache.org/repos/asf/syncope/blob/06d210bf/client/console/src/main/java/org/apache/syncope/client/console/panels/SchemaModalPanel.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/panels/SchemaModalPanel.java b/client/console/src/main/java/org/apache/syncope/client/console/panels/SchemaModalPanel.java
index dabeb85..4b191b5 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/panels/SchemaModalPanel.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/panels/SchemaModalPanel.java
@@ -22,6 +22,9 @@ import java.util.Arrays;
 import org.apache.syncope.client.console.wicket.markup.html.bootstrap.dialog.BaseModal;
 import org.apache.syncope.client.console.wicket.markup.html.form.AjaxDropDownChoicePanel;
 import org.apache.syncope.common.lib.to.AbstractSchemaTO;
+import org.apache.syncope.common.lib.to.DerSchemaTO;
+import org.apache.syncope.common.lib.to.PlainSchemaTO;
+import org.apache.syncope.common.lib.to.VirSchemaTO;
 import org.apache.syncope.common.lib.types.SchemaType;
 import org.apache.wicket.PageReference;
 import org.apache.wicket.markup.html.form.Form;
@@ -75,14 +78,16 @@ public class SchemaModalPanel extends AbstractModalPanel<AbstractSchemaTO> {
 
         switch (schemaType) {
             case DERIVED:
-                panel = new DerSchemaDetails(id, pageRef, schemaTO);
+                panel = new DerSchemaDetails(id, pageRef, (DerSchemaTO) schemaTO);
                 break;
+
             case VIRTUAL:
-                panel = new VirSchemaDetails(id, pageRef, schemaTO);
+                panel = new VirSchemaDetails(id, pageRef, (VirSchemaTO) schemaTO);
                 break;
+
             case PLAIN:
             default:
-                panel = new PlainSchemaDetails(id, pageRef, schemaTO);
+                panel = new PlainSchemaDetails(id, pageRef, (PlainSchemaTO) schemaTO);
         }
         panel.setOutputMarkupId(true);
         return panel;

http://git-wip-us.apache.org/repos/asf/syncope/blob/06d210bf/client/console/src/main/java/org/apache/syncope/client/console/panels/VirSchemaDetails.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/panels/VirSchemaDetails.java b/client/console/src/main/java/org/apache/syncope/client/console/panels/VirSchemaDetails.java
index ceb51be..041bfda 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/panels/VirSchemaDetails.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/panels/VirSchemaDetails.java
@@ -35,11 +35,11 @@ import org.apache.syncope.client.console.wicket.markup.html.form.AjaxCheckBoxPan
 import org.apache.syncope.client.console.wicket.markup.html.form.AjaxDropDownChoicePanel;
 import org.apache.syncope.client.console.wicket.markup.html.form.AjaxTextFieldPanel;
 import org.apache.syncope.common.lib.EntityTOUtils;
-import org.apache.syncope.common.lib.to.AbstractSchemaTO;
 import org.apache.syncope.common.lib.to.ConnIdObjectClassTO;
 import org.apache.syncope.common.lib.to.ConnInstanceTO;
 import org.apache.syncope.common.lib.to.ProvisionTO;
 import org.apache.syncope.common.lib.to.ResourceTO;
+import org.apache.syncope.common.lib.to.VirSchemaTO;
 import org.apache.syncope.common.lib.types.StandardEntitlement;
 import org.apache.wicket.PageReference;
 import org.apache.wicket.ajax.AjaxRequestTarget;
@@ -61,7 +61,7 @@ public class VirSchemaDetails extends AbstractSchemaDetailsPanel {
 
     public VirSchemaDetails(final String id,
             final PageReference pageReference,
-            final AbstractSchemaTO schemaTO) {
+            final VirSchemaTO schemaTO) {
 
         super(id, pageReference, schemaTO);
 

http://git-wip-us.apache.org/repos/asf/syncope/blob/06d210bf/core/persistence-jpa/pom.xml
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/pom.xml b/core/persistence-jpa/pom.xml
index b197eb2..a5567cf 100644
--- a/core/persistence-jpa/pom.xml
+++ b/core/persistence-jpa/pom.xml
@@ -96,7 +96,12 @@ under the License.
       <groupId>org.apache.commons</groupId>
       <artifactId>commons-jexl3</artifactId>
     </dependency>
-      
+    
+    <dependency>
+      <groupId>org.apache.tika</groupId>
+      <artifactId>tika-core</artifactId>
+    </dependency>
+
     <dependency>
       <groupId>org.apache.syncope.core</groupId>
       <artifactId>syncope-core-workflow-api</artifactId>
@@ -107,11 +112,6 @@ under the License.
       <artifactId>syncope-core-spring</artifactId>
       <version>${project.version}</version>
     </dependency>
-    
-    <dependency>
-      <groupId>org.apache.tika</groupId>
-      <artifactId>tika-core</artifactId>
-    </dependency>
         
     <!-- TEST -->
     <dependency> 

http://git-wip-us.apache.org/repos/asf/syncope/blob/06d210bf/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/attrvalue/validation/BinaryValidator.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/attrvalue/validation/BinaryValidator.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/attrvalue/validation/BinaryValidator.java
index 182b27f..e608ed7 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/attrvalue/validation/BinaryValidator.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/attrvalue/validation/BinaryValidator.java
@@ -20,6 +20,7 @@ package org.apache.syncope.core.persistence.jpa.attrvalue.validation;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
 import java.io.IOException;
+import javax.ws.rs.core.MediaType;
 import org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidPlainAttrValueException;
 import org.apache.syncope.core.persistence.api.entity.PlainAttrValue;
 import org.apache.syncope.core.persistence.api.entity.PlainSchema;
@@ -31,6 +32,12 @@ public class BinaryValidator extends AbstractValidator {
 
     private static final ObjectMapper MAPPER = new ObjectMapper();
 
+    private static final Tika TIKA = new Tika();
+
+    static {
+        TIKA.setMaxStringLength(-1);
+    }
+
     public BinaryValidator(final PlainSchema schema) {
         super(schema);
     }
@@ -39,13 +46,14 @@ public class BinaryValidator extends AbstractValidator {
     protected void doValidate(final PlainAttrValue attrValue) {
         // check Binary schemas MIME Type mismatches
         if (attrValue.getBinaryValue() != null) {
-            PlainSchema currentSchema = attrValue.getAttr().getSchema();
             byte[] binaryValue = attrValue.getBinaryValue();
-            String mimeType = detectSchemaMimeType(binaryValue);
+            String mimeType = TIKA.detect(binaryValue);
+
             boolean valid = true;
-            if (!mimeType.equals(currentSchema.getMimeType())) {
-                if (mimeType.equals("text/plain")
-                        && currentSchema.getMimeType().equals("application/json")) {
+            if (!mimeType.equals(attrValue.getAttr().getSchema().getMimeType())) {
+                if (MediaType.TEXT_PLAIN.equals(mimeType)
+                        && MediaType.APPLICATION_JSON.equals(attrValue.getAttr().getSchema().getMimeType())) {
+
                     String decoded = new String(binaryValue).trim();
                     valid = (decoded.startsWith("{") && decoded.endsWith("}"))
                             || (decoded.startsWith("[") && decoded.endsWith("]"))
@@ -56,26 +64,18 @@ public class BinaryValidator extends AbstractValidator {
             }
             if (!valid) {
                 throw new InvalidPlainAttrValueException(
-                        "Found MIME type: '"
-                        + mimeType
-                        + "', expecting: '"
-                        + currentSchema.getMimeType()
-                        + "'");
+                        "Found MIME type: '" + mimeType + "', expecting: '"
+                        + attrValue.getAttr().getSchema().getMimeType() + "'");
             }
         }
     }
 
-    private String detectSchemaMimeType(final byte[] value) {
-        Tika tika = new Tika();
-        tika.setMaxStringLength(-1);
-        return tika.detect(value);
-    }
-
     private boolean isValidJSON(final String value) {
         try {
             MAPPER.readTree(value);
             return true;
         } catch (IOException e) {
+            LOG.debug("Invalid JSON string: {}", value, e);
             return false;
         }
     }

http://git-wip-us.apache.org/repos/asf/syncope/blob/06d210bf/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 7af96f0..d5a97d2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1017,6 +1017,12 @@ under the License.
       </dependency>
 
       <dependency>
+        <groupId>org.apache.tika</groupId>
+        <artifactId>tika-core</artifactId>
+        <version>${tika.version}</version>
+      </dependency>
+
+      <dependency>
         <groupId>net.tirasa.connid</groupId>
         <artifactId>connector-framework</artifactId>
         <version>${connid.version}</version>
@@ -1582,12 +1588,6 @@ under the License.
       </dependency>
       
       <dependency>
-        <groupId>org.apache.tika</groupId>
-        <artifactId>tika-core</artifactId>
-        <version>${tika.version}</version>
-      </dependency>
-
-      <dependency>
         <groupId>org.netbeans.api</groupId>
         <artifactId>org-netbeans-api-annotations-common</artifactId>
         <version>${netbeans.version}</version>
@@ -2297,6 +2297,7 @@ under the License.
             <link>https://commons.apache.org/proper/commons-io/javadocs/api-2.6/</link>
             <link>https://commons.apache.org/proper/commons-jexl/apidocs/</link>
             <link>https://commons.apache.org/proper/commons-collections/javadocs/api-release/</link>
+            <link>https://tika.apache.org/1.17/api/</link>
             <link>http://docs.spring.io/spring/docs/4.3.x/javadoc-api/</link>
             <link>http://docs.spring.io/spring-security/site/docs/4.2.x/apidocs/</link>
             <link>http://activiti.org/javadocs/</link>