Some clean up
authorFrancesco Chicchiriccò <ilgrosso@apache.org>
Tue, 6 Feb 2018 15:05:28 +0000 (16:05 +0100)
committerFrancesco Chicchiriccò <ilgrosso@apache.org>
Tue, 6 Feb 2018 15:38:58 +0000 (16:38 +0100)
client/console/src/main/java/org/apache/syncope/client/console/panels/DerSchemaDetails.java
client/console/src/main/java/org/apache/syncope/client/console/panels/PlainSchemaDetails.java
client/console/src/main/java/org/apache/syncope/client/console/panels/SchemaModalPanel.java
client/console/src/main/java/org/apache/syncope/client/console/panels/VirSchemaDetails.java
core/persistence-jpa/pom.xml
core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/attrvalue/validation/BinaryValidator.java
pom.xml

index 52fbfe5..eae157c 100644 (file)
@@ -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<>(schemaTO, "expression"));
index c996bcc..c249397 100644 (file)
@@ -72,7 +72,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<>(
@@ -115,19 +116,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));
             }
         }) {
 
@@ -154,19 +155,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));
             }
         }) {
 
index c49dc36..9c00fd2 100644 (file)
@@ -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;
index e5d72ea..ef30352 100644 (file)
@@ -33,11 +33,11 @@ import org.apache.syncope.client.console.wicket.ajax.form.IndicatorAjaxFormCompo
 import org.apache.syncope.client.console.wicket.markup.html.form.AjaxCheckBoxPanel;
 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.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.EntityTO;
 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;
@@ -59,7 +59,7 @@ public class VirSchemaDetails extends AbstractSchemaDetailsPanel {
 
     public VirSchemaDetails(final String id,
             final PageReference pageReference,
-            final AbstractSchemaTO schemaTO) {
+            final VirSchemaTO schemaTO) {
 
         super(id, pageReference, schemaTO);
 
index 545e6cb..1ba5c3a 100644 (file)
@@ -92,7 +92,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>
@@ -103,11 +108,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> 
index a7dbb8d..b32f91c 100644 (file)
@@ -20,9 +20,9 @@ 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;
 import org.apache.tika.Tika;
 
 public class BinaryValidator extends AbstractValidator {
@@ -31,17 +31,24 @@ public class BinaryValidator extends AbstractValidator {
 
     private static final ObjectMapper MAPPER = new ObjectMapper();
 
+    private static final Tika TIKA = new Tika();
+
+    static {
+        TIKA.setMaxStringLength(-1);
+    }
+
     @Override
     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("]"))
@@ -52,26 +59,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;
         }
     }
diff --git a/pom.xml b/pom.xml
index 47752df..bc314b1 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -975,6 +975,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>
@@ -1491,12 +1497,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>
@@ -2241,7 +2241,7 @@ under the License.
             <link>https://commons.apache.org/proper/commons-lang/javadocs/api-release/</link>
             <link>https://commons.apache.org/proper/commons-io/javadocs/api-2.6/</link>
             <link>https://commons.apache.org/proper/commons-jexl/apidocs/</link>
-            <link>http://docs.spring.io/spring/docs/5.0.x/javadoc-api/</link>
+            <link>https://tika.apache.org/1.17/api/</link>
             <link>http://docs.spring.io/spring-security/site/docs/4.2.x/apidocs/</link>
             <link>http://www.flowable.org/docs/javadocs/</link>
             <link>https://build.shibboleth.net/nexus/content/sites/site/java-opensaml/3.3.0/apidocs/</link>