Package com.dotmarketing.portlets.structure.model

Examples of com.dotmarketing.portlets.structure.model.Field


    Iterator<Field> fieldsIt= fields.iterator();

    String widgetCode= "";

    while (fieldsIt.hasNext()) {
      Field field= (Field) fieldsIt.next();
      String contField= field.getFieldContentlet();
      String contFieldValue= null;
      Object contFieldValueObject= null;
      String velPath= (!EDIT_MODE) ? "live/" : "working/";
      if(fAPI.isElementConstant(field)){
          if(field.getVelocityVarName().equals("widgetPreexecute")){
          continue;
        }
        if(field.getVelocityVarName().equals("widgetCode")){
          widgetCode= "#set($" + field.getVelocityVarName() + "=$velutil.mergeTemplate(\"" + velPath +  content.getInode() + "_" + field.getInode() + "." + Config.getStringProperty("VELOCITY_FIELD_EXTENSION") + "\"))";
          continue;
        }else{
          String fieldValues=field.getValues()==null?"":field.getValues();
          if(fieldValues.contains("$") || fieldValues.contains("#")){
            sb.append("#set($" ).append( field.getVelocityVarName() ).append( "= $velutil.mergeTemplate(\"" ).append( velPath ).appendcontent.getInode() ).append( "_" ).append( field.getInode() ).append( "." ).append( Config.getStringProperty("VELOCITY_FIELD_EXTENSION") ).append( "\"))");
          }else{
            sb.append("#set($" ).append( field.getVelocityVarName() ).append( "= \"" ).append( UtilMethods.espaceForVelocity(fieldValues).trim() ).append( "\")");
          }
          continue;
        }
      }
      if (UtilMethods.isSet(contField)) {
        try {
          contFieldValueObject= conAPI.getFieldValue(content, field);
          contFieldValue= contFieldValueObject== null ? "" : contFieldValueObject.toString();
        } catch (Exception e) {
          Logger.error(ContentletServices.class, "writeContentletToFile: " + e.getMessage());
        }
        if (!field.getFieldType().equals(Field.FieldType.DATE_TIME.toString()) && !field.getFieldType().equals(Field.FieldType.DATE.toString())
            && !field.getFieldType().equals(Field.FieldType.TIME.toString())){
          if(contFieldValue.contains("$") || contFieldValue.contains("#")){
            sb.append("#set($" ).append( field.getVelocityVarName() ).append( "=$velutil.mergeTemplate(\"" ).append( velPath ).appendcontent.getInode() ).append( "_" ).append( field.getInode() ).append( "." ).append( Config.getStringProperty("VELOCITY_FIELD_EXTENSION") ).append( "\"))");
          }else{
            sb.append("#set($" ).append( field.getVelocityVarName() ).append( "=\"" ).append( UtilMethods.espaceForVelocity(contFieldValue).trim() ).append( "\")");
          }
        }

      }

      if (field.getFieldType().equals(Field.FieldType.IMAGE.toString())) {
        String identifierValue= content.getStringProperty(field.getVelocityVarName());
        if( InodeUtils.isSet(identifierValue) ) {
          if (EDIT_MODE){
            sb.append("#set($" ).append( field.getVelocityVarName() ).append( "Object= $filetool.getFile('" ).append( identifierValue ).append( "',false))");
          }else{
            sb.append("#set($" ).append( field.getVelocityVarName() ).append( "Object= $filetool.getFile('" ).append( identifierValue ).append( "',true))");
          }
        }else{
          sb.append("#set($" ).append( field.getVelocityVarName() ).append( "Object= $filetool.getNewFile())");
        }

        sb.append("#set($" ).append( field.getVelocityVarName() ).append( "ImageInode=$" ).append( field.getVelocityVarName() ).append( "Object.getInode() )");
        sb.append("#set($" ).append( field.getVelocityVarName() ).append( "ImageIdentifier=$" ).append( field.getVelocityVarName() ).append( "Object.getIdentifier() )");
        sb.append("#set($" ).append( field.getVelocityVarName() ).append( "ImageWidth=$" ).append( field.getVelocityVarName() ).append( "Object.getWidth() )");
        sb.append("#set($" ).append( field.getVelocityVarName() ).append( "ImageHeight=$" ).append( field.getVelocityVarName() ).append( "Object.getHeight() )");
        sb.append("#set($" ).append( field.getVelocityVarName() ).append( "ImageExtension=$" ).append( field.getVelocityVarName() ).append( "Object.getExtension() )");
        sb.append("#set($" ).append( field.getVelocityVarName() ).append( "ImageURI=$filetool.getURI($" ).append( field.getVelocityVarName() ).append( "Object))");
        sb.append("#set($" ).append( field.getVelocityVarName() ).append( "ImageTitle=$UtilMethods.espaceForVelocity($" ).append( field.getVelocityVarName() ).append( "Object.getTitle()) )");
        sb.append("#set($" ).append( field.getVelocityVarName() ).append( "ImageFriendlyName=$UtilMethods.espaceForVelocity($" ).append( field.getVelocityVarName() ).append( "Object.getFriendlyName()) )");

        sb.append("#set($" ).append( field.getVelocityVarName() ).append( "ImagePath=$" ).append( field.getVelocityVarName() ).append( "Object.getPath())");
        sb.append("#set($" ).append( field.getVelocityVarName() ).append( "ImageName=$" ).append( field.getVelocityVarName() ).append( "Object.getFileName())");

      }//  http://jira.dotmarketing.net/browse/DOTCMS-2178
      else if (field.getFieldType().equals(Field.FieldType.BINARY.toString())){
        java.io.File binFile;
        String fileName= "";
        String filesize= "";
        try {
          binFile= content.getBinary(field.getVelocityVarName());
          if(binFile != null) {
            fileName= binFile.getName();
            filesize= FileUtil.getsize(binFile);
          }
        } catch (IOException e) {
          Logger.error(ContentletServices.class, "Unable to retrive binary file for content id " + content.getIdentifier() + " field " + field.getVelocityVarName(), e);
          continue;
        }
           sb.append("#set($" ).append( field.getVelocityVarName() ).append( "BinaryFileTitle=\"" ).append( UtilMethods.espaceForVelocity(fileName) ).append( "\" )");
        sb.append("#set($" ).append( field.getVelocityVarName() ).append( "BinaryFileSize=\"" ).append( UtilMethods.espaceForVelocity(filesize) ).append( "\" )");
        String binaryFileURI= fileName.length()>0? UtilMethods.espaceForVelocity("/contentAsset/raw-data/"+content.getIdentifier()+"/"+ field.getVelocityVarName() + "/" + content.getInode()):"";
        sb.append("#set($" ).append( field.getVelocityVarName() ).append( "BinaryFileURI=\"" ).append( binaryFileURI).append("\" )");
      }else if (field.getFieldType().equals(Field.FieldType.FILE.toString())) {
        String identifierValue= content.getStringProperty(field.getVelocityVarName());
        if( InodeUtils.isSet(identifierValue) ) {
          if (EDIT_MODE){
            sb.append("#set($" ).append( field.getVelocityVarName() ).append( "Object= $filetool.getFile('" ).append( identifierValue ).append( "',false))");
          }else{
            sb.append("#set($" ).append( field.getVelocityVarName() ).append( "Object= $filetool.getFile('" ).append( identifierValue ).append( "',true))");
          }
        }else{
          sb.append("#set($" ).append( field.getVelocityVarName() ).append( "Object= $filetool.getNewFile())");
        }

        sb.append("#set($" ).append( field.getVelocityVarName() ).append( "FileInode=$" ).append( field.getVelocityVarName() ).append( "Object.getInode() )");
        sb.append("#set($" ).append( field.getVelocityVarName() ).append( "FileIdentifier=$" ).append( field.getVelocityVarName() ).append( "Object.getIdentifier() )");
        sb.append("#set($" ).append( field.getVelocityVarName() ).append( "FileExtension=$" ).append( field.getVelocityVarName() ).append( "Object.getExtension() )");
        sb.append("#set($" ).append( field.getVelocityVarName() ).append( "FileURI=$filetool.getURI($" ).append( field.getVelocityVarName() ).append( "Object))");
        sb.append("#set($" ).append( field.getVelocityVarName() ).append( "FileTitle=$" ).append( field.getVelocityVarName() ).append( "Object.getTitle() )");
        sb.append("#set($" ).append( field.getVelocityVarName() ).append( "FileFriendlyName=$UtilMethods.espaceForVelocity($" ).append( field.getVelocityVarName() ).append( "Object.getFriendlyName() ))");

        sb.append("#set($" ).append( field.getVelocityVarName() ).append( "FilePath=$UtilMethods.espaceForVelocity($" ).append( field.getVelocityVarName() ).append( "Object.getPath()) )");
        sb.append("#set($" ).append( field.getVelocityVarName() ).append( "FileName=$UtilMethods.espaceForVelocity($" ).append( field.getVelocityVarName() ).append( "Object.getFileName()) )");


      } else if (field.getFieldType().equals(Field.FieldType.SELECT.toString())) {
        sb.append("#set($" ).append( field.getVelocityVarName() ).append( "SelectLabelsValues=\"" ).append( field.getValues().replaceAll("\\r\\n", " ").replaceAll("\\n", " ") ).append( "\")");
      } else if (field.getFieldType().equals(Field.FieldType.RADIO.toString())) {
        sb.append("#set($" ).append( field.getVelocityVarName() ).append( "RadioLabelsValues=\"" ).append( field.getValues().replaceAll("\\r\\n", " ").replaceAll("\\n", " ") ).append( "\" )");
      } else if (field.getFieldType().equals(Field.FieldType.CHECKBOX.toString())) {
        sb.append("#set($" ).append( field.getVelocityVarName() ).append( "CheckboxLabelsValues=\"" ).append( field.getValues().replaceAll("\\r\\n", " ").replaceAll("\\n", " ") ).append( "\" )");
      } else if (field.getFieldType().equals(Field.FieldType.DATE.toString())) {
        String shortFormat= "";
        String dbFormat= "";
        if (contFieldValueObject != null && contFieldValueObject instanceof Date) {
          shortFormat= UtilMethods.dateToHTMLDate((Date) contFieldValueObject, "MM/dd/yyyy");
          dbFormat= UtilMethods.dateToHTMLDate((Date) contFieldValueObject, "yyyy-MM-dd");
        }
        sb.append("#set($" ).append( field.getVelocityVarName() ).append( "=$date.toDate(\"yyyy-MM-dd\", \"" ).append( dbFormat ).append( "\"))");
        sb.append("#set($" ).append( field.getVelocityVarName() ).append( "ShortFormat=\"" ).append( shortFormat ).append( "\" )");
        sb.append("#set($" ).append( field.getVelocityVarName() ).append( "DBFormat=\"" ).append( dbFormat ).append( "\" )");
      } else if (field.getFieldType().equals(Field.FieldType.TIME.toString())) {
        String shortFormat= "";
        if (contFieldValueObject != null && contFieldValueObject instanceof Date) {
          shortFormat= UtilMethods.dateToHTMLDate((Date) contFieldValueObject, "H:mm:ss");
        }
        sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "ShortFormat=\"" ).append( shortFormat ).append( "\" )");
        sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "= $date.toDate(\"H:mm:ss\", \"" ).append( shortFormat ).append( "\"))");
      } else if (field.getFieldType().equals(Field.FieldType.DATE_TIME.toString())) {
        String shortFormat= "";
        String longFormat= "";
        String dbFormat= "";
        if (contFieldValueObject != null && contFieldValueObject instanceof Date) {
          shortFormat= UtilMethods.dateToHTMLDate((Date) contFieldValueObject, "MM/dd/yyyy");
          longFormat= UtilMethods.dateToHTMLDate((Date) contFieldValueObject, "MM/dd/yyyy H:mm:ss");
          dbFormat= UtilMethods.dateToHTMLDate((Date) contFieldValueObject, "yyyy-MM-dd H:mm:ss");
        }
        sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "= $date.toDate(\"yyyy-MM-dd H:mm:ss\", \"" ).append( dbFormat ).append( "\"))");
        sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "ShortFormat=\"" ).append( shortFormat ).append( "\" )");
        sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "LongFormat=\"" ).append( longFormat ).append( "\" )");
        sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "DBFormat=\"" ).append( dbFormat ).append( "\" )");
      } else if (field.getFieldType().equals(Field.FieldType.BUTTON.toString())) {
        sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "ButtonValue=\"" ).append( (field.getFieldName()== null ? "" : field.getFieldName()) ).append( "\" )");
        sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "ButtonCode=\"" ).append( (field.getValues()== null ? "" : field.getValues()) ).append( "\" )");
      }//http://jira.dotmarketing.net/browse/DOTCMS-2869
//      else if (field.getFieldType().equals(Field.FieldType.CUSTOM_FIELD.toString())){
//         sb.append("#set( $" + field.getVelocityVarName() + "Code=\"" + UtilMethods.espaceForVelocity(field.getValues()) + "\" )");
//      }//http://jira.dotmarketing.net/browse/DOTCMS-3232
      else if (field.getFieldType().equals(Field.FieldType.HOST_OR_FOLDER.toString())){
        if(InodeUtils.isSet(content.getFolder())){
          sb.append("#set( $ConHostFolder='" ).append( content.getFolder() ).append( "' )");
        }else{
          sb.append("#set( $ConHostFolder='" ).append( content.getHost() ).append( "' )");
        }
      }

      else if (field.getFieldType().equals(Field.FieldType.CATEGORY.toString())) {

        // Get the Category Field
        Category category= categoryAPI.find(field.getValues(), systemUser, false);
        // Get all the Contentlets Categories
        List<Category> selectedCategories= categoryAPI.getParents(content, systemUser, false);

            //Initialize variables
            String catInodes= "";
            Set<Category> categoryList= new HashSet<Category>();
        List<Category> categoryTree= categoryAPI.getAllChildren(category, systemUser, false);

        if (selectedCategories.size() > 0 && categoryTree != null) {
          for (int k= 0; k < categoryTree.size(); k++) {
            Category cat= (Category) categoryTree.get(k);
            for (Category categ : selectedCategories) {
              if (categ.getInode().equalsIgnoreCase(cat.getInode())) {
                categoryList.add(cat);
              }
            }
          }
        }

        if (categoryList.size() > 0) {
            StringBuilder catbuilder=new StringBuilder();
          Iterator<Category> it= categoryList.iterator();
          while (it.hasNext()) {
            Category cat= (Category) it.next();
            catbuilder.append("\"").append(cat.getInode()).append("\"");
            if (it.hasNext()) {
              catbuilder.append(",");
            }
          }
          catInodes=catbuilder.toString();

          sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "FilteredCategories=$categories.filterCategoriesByUserPermissions([" ).append( catInodes ).append( "] ))");
                  sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "Categories=$categories.fetchCategoriesInodes($").append(field.getVelocityVarName()).append("FilteredCategories))");
                  sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "CategoriesNames=$categories.fetchCategoriesNames($").append(field.getVelocityVarName()).append("FilteredCategories))");
                  sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "=$").append(field.getVelocityVarName()).append("Categories)");
                  sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "CategoriesKeys=$categories.fetchCategoriesKeys($").append(field.getVelocityVarName()).append("FilteredCategories))");
        }
        else {
            sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "FilteredCategories=$contents.getEmptyList())");
                  sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "Categories=$contents.getEmptyList())");
                  sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "CategoriesNames=$contents.getEmptyList())");
                  sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "=$contents.getEmptyList())");
                  sb.append("#set( $" ).append( field.getVelocityVarName() ).append( "CategoriesKeys=$contents.getEmptyList())");
        }
      }
    }

View Full Code Here


        return;
      }
     
      Structure slideShowSt = StructureCache.getStructureByVelocityVarName("slideShow");
      List<Field> fields = FieldsCache.getFieldsByStructureVariableName("slideShow");
      Field slideShowTitleF = null;
      Field slideShowCreditsF = null;
      Field slideShowAudioTitleF = null;
      Field slideShowAudioFileF = null;
     
      if (slideShowSt == null ||(!InodeUtils.isSet(slideShowSt.getInode())) ) {
        slideShowSt = new Structure ();
        slideShowSt.setDefaultStructure(false);
        slideShowSt.setName("Slide Show");
        slideShowSt.setDescription("Slide Show Base Structure");
        slideShowSt.setFixed(true);
        slideShowSt.setStructureType(Structure.STRUCTURE_TYPE_CONTENT);
        //Create the structure
        StructureFactory.saveStructure(slideShowSt);       
      }
 
      if (fields != null)
        for (Field field : fields) {
          if (field.getFieldName().equals("Title")) {
            slideShowTitleF = field;
          } else if (field.getFieldName().equals("Credits")) {
            slideShowCreditsF = field;
          } else if (field.getFieldName().equals("Audio Title")) {
            slideShowAudioTitleF = field;
          } else if (field.getFieldName().equals("MP3 File")) {
            slideShowAudioFileF = field;
          }
        }
     
      boolean fieldAdded = false;
      if (slideShowTitleF == null) {
        //Creating the field
        slideShowTitleF = new Field("Title", FieldType.TEXT, DataType.TEXT, slideShowSt, true, true, true, 1, true, false,true);
        FieldFactory.saveField(slideShowTitleF);
        fieldAdded = true;
      }
      if (slideShowCreditsF == null) {
        //Creating the credits field
        slideShowCreditsF = new Field("Credits", FieldType.TEXT_AREA, DataType.LONG_TEXT, slideShowSt, false, false, true, 2, true, false, true);
        FieldFactory.saveField(slideShowCreditsF);
        fieldAdded = true;
      }
      if (slideShowAudioTitleF == null) {
        //Create the audio title field
        slideShowAudioTitleF = new Field("Audio Title", FieldType.TEXT, DataType.TEXT, slideShowSt, false, false, true, 3, true, false, true);
        FieldFactory.saveField(slideShowAudioTitleF);
        fieldAdded = true;
      }
      if (slideShowAudioFileF == null) {
        //Create the audio file
        slideShowAudioFileF = new Field("MP3 File", FieldType.FILE, DataType.INTEGER, slideShowSt, false, false, false, 4, true, false, true);
        FieldFactory.saveField(slideShowAudioFileF);
        fieldAdded = true;
      }
      if (fieldAdded) {
        FieldsCache.removeFields(slideShowSt);
        StructureCache.removeStructure(slideShowSt);
        StructureServices.removeStructureFile(slideShowSt);
        StructureFactory.saveStructure(slideShowSt);
      }
     
     
      Structure slideSt = StructureCache.getStructureByVelocityVarName("slideImage");
      fields = FieldsCache.getFieldsByStructureVariableName("slideImage");
      Field slideTitleF = null;
      Field slideImageF = null;
      Field slideTextBodyF = null;
      Field slideTimingF = null;
 
      if (slideSt == null || (!InodeUtils.isSet(slideSt.getInode()))) {
        //Create the structure
        slideSt = new Structure ();
        slideSt.setDefaultStructure(false);
        slideSt.setName("Slide Image");
        slideSt.setVelocityVarName("slideImage");
        slideSt.setDescription("Slide Image");
        slideSt.setFixed(true);
        slideSt.setStructureType(Structure.STRUCTURE_TYPE_CONTENT);
        //Create the structure
        StructureFactory.saveStructure(slideSt);
      }
 
      if (fields != null)
        for (Field field : fields) {
          if (field.getFieldName().equals("Title")) {
            slideTitleF = field;
          } else if (field.getFieldName().equals("Image")) {
            slideImageF = field;
          } else if (field.getFieldName().equals("Text Body")) {
            slideTextBodyF = field;
          } else if (field.getFieldName().equals("Timing")) {
            slideTimingF = field;
          }
        }
     
      fieldAdded = false;
      if (slideTitleF == null) {
        //Creating the field
        slideTitleF = new Field("Title", FieldType.TEXT, DataType.TEXT, slideSt, true, true, true, 1, true, false, true);
        FieldFactory.saveField(slideTitleF);
        fieldAdded = true;
      }
      if (slideImageF == null) {
        //Creating the field
        slideImageF = new Field("Image", FieldType.IMAGE, DataType.INTEGER, slideSt, true, true, true, 2, true, false, true);
        FieldFactory.saveField(slideImageF);
        fieldAdded = true;
      }
      if (slideTextBodyF == null) {
        //Creating the field
        slideTextBodyF = new Field("Text Body", FieldType.TEXT_AREA, DataType.LONG_TEXT, slideSt, true, true, true, 3, true, false, true);
        FieldFactory.saveField(slideTextBodyF);
        fieldAdded = true;
      }
      if (slideTimingF == null) {
        //Creating the field
        slideTimingF = new Field("Timing", FieldType.TEXT, DataType.INTEGER, slideSt, true, true, true, 4, "", "10", "", true, false, true);
        FieldFactory.saveField(slideTimingF);
        fieldAdded = true;
      }
      if (fieldAdded) {
        FieldsCache.removeFields(slideSt);
View Full Code Here

        s.setOwner(sysuser.getUserId());
        s.setVelocityVarName("testtesttest"+System.currentTimeMillis());
        StructureFactory.saveStructure(s);
        StructureCache.addStructure(s);

        Field field1 = new Field("testtext", Field.FieldType.TEXT, Field.DataType.TEXT, s,
                true, true, true, 3, "", "", "", true, false, true);
        field1.setVelocityVarName("testtext");
        field1.setListed(true);
        FieldFactory.saveField(field1);
        FieldsCache.addField(field1);

        Field field2 = new Field("f", Field.FieldType.HOST_OR_FOLDER, Field.DataType.TEXT, s,
                true, true, true, 4, "", "", "", true, false, true);
        field2.setVelocityVarName("f");
        FieldFactory.saveField(field2);
        FieldsCache.addField(field2);

        Contentlet cont1=new Contentlet();
        cont1.setStructureInode(s.getInode());
View Full Code Here

            s.setOwner(sysuser.getUserId());
            s.setVelocityVarName("str847"+System.currentTimeMillis());
            StructureFactory.saveStructure(s);
            StructureCache.addStructure(s);

            Field field = new Field("testtext", Field.FieldType.TEXT, Field.DataType.TEXT, s,
                    true, true, true, 3, "", "", "", true, false, true);
            field.setVelocityVarName("testtext");
            field.setListed(true);
            FieldFactory.saveField(field);
            FieldsCache.addField(field);

            field = new Field("f", Field.FieldType.HOST_OR_FOLDER, Field.DataType.TEXT, s,
                    true, true, true, 4, "", "", "", true, false, true);
            field.setVelocityVarName("f");
            FieldFactory.saveField(field);
            FieldsCache.addField(field);

            Contentlet cont1=new Contentlet();
            cont1.setStructureInode(s.getInode());
View Full Code Here

            s.setOwner(sysuser.getUserId());
            s.setVelocityVarName("issue560"+System.currentTimeMillis());
            StructureFactory.saveStructure(s);
            StructureCache.addStructure(s);

            Field field = new Field("testtext", Field.FieldType.TEXT, Field.DataType.TEXT, s,
                    true, true, true, 3, "", "", "", true, false, true);
            field.setVelocityVarName("testtext");
            field.setListed(true);
            FieldFactory.saveField(field);
            FieldsCache.addField(field);


            Map<String,String> mm=new HashMap<String,String>();
View Full Code Here

        Structure st=new Structure();
        st.setName("Rest test st "+salt);
        st.setVelocityVarName("restTestSt"+salt);
        st.setDescription("testing rest content creation with mandatory workflow");
        StructureFactory.saveStructure(st);
        Field field=new Field("Title",FieldType.TEXT,DataType.TEXT,st,true,true,true,1,false,false,true);
        FieldFactory.saveField(field);
        APILocator.getWorkflowAPI().saveSchemeForStruct(st, scheme);
       
        // send the Rest api call
        User sysuser=APILocator.getUserAPI().getSystemUser();
        User bill=APILocator.getUserAPI().loadUserById("dotcms.org.2806");
        Role billrole=APILocator.getRoleAPI().getUserRole(bill);
        ClientResponse response=contRes.path("/Save%20and%20Assign/1/wfActionComments/please%20do%20this%20for%20me/wfActionAssign/"+billrole.getId())
            .type(MediaType.APPLICATION_JSON_TYPE)
            .header(authheader, authvalue).put(ClientResponse.class,
                new JSONObject()
                    .put("stInode", st.getInode())
                    .put("languageId", 1)
                    .put(field.getVelocityVarName(), "test title "+salt)
                    .toString());
        Assert.assertEquals(200, response.getStatus());
       
        Contentlet cont = APILocator.getContentletAPI().find(response.getHeaders().getFirst("inode"), sysuser, false);
        Assert.assertNotNull(cont);
View Full Code Here

        Structure st=new Structure();
        st.setName("Rest Test File Img "+salt);
        st.setVelocityVarName("restTestSt"+salt);
        st.setDescription("testing rest content creation with file&image fields");
        StructureFactory.saveStructure(st);
        Field title=new Field("Title",FieldType.TEXT,DataType.TEXT,st,true,true,true,1,false,false,true);
        FieldFactory.saveField(title);
        Field file=new Field("aFile",FieldType.FILE,DataType.TEXT,st,true,false,true,2,false,false,true);
        FieldFactory.saveField(file);
        Field image=new Field("aImage",FieldType.IMAGE,DataType.TEXT,st,true,false,true,3,false,false,true);
        FieldFactory.saveField(image);
       
        Host demo=APILocator.getHostAPI().findByName("demo.dotcms.com", sysuser, false);
        Folder ff=APILocator.getFolderAPI().createFolders("/rest/"+salt, demo, sysuser, false);
       
        java.io.File filefile = java.io.File.createTempFile("filefile", ".txt");
        java.io.File imgimg = java.io.File.createTempFile("imgimg", ".jpg");
       
        Contentlet filea=new Contentlet();
        filea.setFolder(ff.getInode());
        filea.setHost(demo.getIdentifier());
        filea.setStructureInode(StructureCache.getStructureByVelocityVarName("fileAsset").getInode());
        filea.setStringProperty(FileAssetAPI.HOST_FOLDER_FIELD, ff.getInode());
        filea.setStringProperty(FileAssetAPI.TITLE_FIELD, "filefile.txt");
        filea.setStringProperty(FileAssetAPI.FILE_NAME_FIELD, "filefile.txt");
        filea.setBinary(FileAssetAPI.BINARY_FIELD, filefile);
        filea.setLanguageId(1);
        filea = APILocator.getContentletAPI().checkin(filea, sysuser, false);
       
        Contentlet imga=new Contentlet();
        imga.setFolder(ff.getInode());
        imga.setHost(demo.getIdentifier());
        imga.setStructureInode(StructureCache.getStructureByVelocityVarName("fileAsset").getInode());
        imga.setStringProperty(FileAssetAPI.HOST_FOLDER_FIELD, ff.getInode());
        imga.setStringProperty(FileAssetAPI.FILE_NAME_FIELD, "imgimg.jpg");
        imga.setStringProperty(FileAssetAPI.TITLE_FIELD, "imgimg.jpg");
        imga.setBinary(FileAssetAPI.BINARY_FIELD, imgimg);
        imga.setLanguageId(1);
        imga = APILocator.getContentletAPI().checkin(imga, sysuser, false);
       
        ClientResponse response=contRes.path("/publish/1")
            .type(MediaType.APPLICATION_JSON_TYPE)
            .header(authheader, authvalue).put(ClientResponse.class,
                new JSONObject()
                    .put("stName", st.getVelocityVarName())
                    .put(file.getVelocityVarName(),"//demo.dotcms.com/rest/"+salt+"/filefile.txt")
                    .put(image.getVelocityVarName(), "//demo.dotcms.com/rest/"+salt+"/imgimg.jpg")
                    .put(title.getVelocityVarName(), "a simple title")
                    .toString());
        Assert.assertEquals(200, response.getStatus());
       
        String inode=response.getHeaders().getFirst("inode");
        Contentlet cont = APILocator.getContentletAPI().find(inode, sysuser, false);
        Assert.assertEquals(filea.getIdentifier(),cont.getStringProperty(file.getVelocityVarName()));
        Assert.assertEquals(imga.getIdentifier(),cont.getStringProperty(image.getVelocityVarName()));
    }
View Full Code Here

        Structure st1=new Structure();
        st1.setName("Rest Test rel "+salt);
        st1.setVelocityVarName("restTestSt"+salt);
        st1.setDescription("testing rest content creation with relationships");
        StructureFactory.saveStructure(st1);
        Field title1=new Field("Title",FieldType.TEXT,DataType.TEXT,st1,true,true,true,1,false,false,true);
        FieldFactory.saveField(title1);
       
        Structure st2=new Structure();
        st2.setName("Rest Test rel 2 "+salt);
        st2.setVelocityVarName("restTestSt2"+salt);
        st2.setDescription("testing rest content creation with relationships 2");
        StructureFactory.saveStructure(st2);
        Field title2=new Field("Title",FieldType.TEXT,DataType.TEXT,st2,true,true,true,1,false,false,true);
        FieldFactory.saveField(title2);
       
        Contentlet c1=new Contentlet();
        c1.setLanguageId(1);
        c1.setStringProperty(title2.getVelocityVarName(), "title 2");
        c1.setStructureInode(st2.getInode());
        c1 = APILocator.getContentletAPI().checkin(c1, sysuser, false);
       
        Contentlet c2=new Contentlet();
        c2.setLanguageId(1);
        c2.setStringProperty(title2.getVelocityVarName(), "title 222");
        c2.setStructureInode(st2.getInode());
        c2 = APILocator.getContentletAPI().checkin(c2, sysuser, false);
       
        APILocator.getContentletAPI().isInodeIndexed(c1.getInode());
        APILocator.getContentletAPI().isInodeIndexed(c2.getInode());
View Full Code Here

        testStructure.setVelocityVarName( structureName );
        StructureFactory.saveStructure( testStructure );
        StructureCache.addStructure( testStructure );
        //Adding test field

        Field field = new Field( "testSearchIndexByDateField", Field.FieldType.DATE_TIME,  Field.DataType.DATE, testStructure, true, true, true, 1, false, false, true );
        field.setVelocityVarName( "testSearchIndexByDateField" );
        field.setListed( true );
        FieldFactory.saveField( field );
        FieldsCache.addField( field );

        //Creating a test contentlet
        testContent = new Contentlet();
View Full Code Here

        testStructure.setOwner( user.getUserId() );
        testStructure.setVelocityVarName( structureName );
        StructureFactory.saveStructure( testStructure );
        StructureCache.addStructure( testStructure );
        //Adding test field
        Field field = new Field( "Wysiwyg", Field.FieldType.WYSIWYG, Field.DataType.LONG_TEXT, testStructure, true, true, true, 1, false, false, false );
        field.setVelocityVarName( "wysiwyg" );
        field.setListed( true );
        FieldFactory.saveField( field );
        FieldsCache.addField( field );

        return testStructure;
    }
View Full Code Here

TOP

Related Classes of com.dotmarketing.portlets.structure.model.Field

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.