Package com.dotmarketing.portlets.structure.model

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


        Iterator<Field> iterator = fields.iterator();
        Field field = iterator.next();

        //Creating the FieldVariables
        FieldVariable fieldVariable = new FieldVariable();
        fieldVariable.setFieldId( field.getInode() );
        fieldVariable.setName( NAME_ORIGINAL );
        fieldVariable.setKey( "test_variable_key" );
        fieldVariable.setValue( "test variable value" );
        fieldVariable.setLastModifierId( user.getUserId() );
        fieldVariable.setLastModDate( new Date() );

        FieldVariable fieldVariable2 = new FieldVariable();
        fieldVariable2.setFieldId( field.getInode() );
        fieldVariable2.setName( NAME_ORIGINAL + "_2" );
        fieldVariable2.setKey( "test_variable_key_2" );
        fieldVariable2.setValue( "test variable value_2" );
        fieldVariable2.setLastModifierId( user.getUserId() );
        fieldVariable2.setLastModDate( new Date() );

        //++++++++++++++++++++++++++++++++++++++++++++
        //Saving the field variable
        FieldFactory.saveFieldVariable( fieldVariable );

        //Validations
        assertNotNull( fieldVariable.getId() );

        //++++++++++++++++++++++++++++++++++++++++++++
        //Getting the variable we just saved
        FieldVariable savedVariable = FieldFactory.getFieldVariable( fieldVariable.getId() );

        //Validations
        assertEquals( fieldVariable.getId(), savedVariable.getId() );

        //++++++++++++++++++++++++++++++++++++++++++++
        //Updating the field variable
        savedVariable.setName( NAME_UPDATED );
        FieldFactory.saveFieldVariable( fieldVariable );

        //Getting again the saved variable
        fieldVariable = FieldFactory.getFieldVariable( fieldVariable.getId() );

        //Validations
        assertNotNull( fieldVariable.getId() );
        assertEquals( fieldVariable.getName(), NAME_UPDATED );

        //++++++++++++++++++++++++++++++++++++++++++++
        //Getting all the variables for a given field
        Collection<FieldVariable> variables = FieldFactory.getFieldVariablesForField( field.getInode() );

        //Validations
        assertTrue( variables != null && !variables.isEmpty() );

        //++++++++++++++++++++++++++++++++++++++++++++
        //Getting all the variables
        variables = FieldFactory.getAllFieldVariables();

        //Validations
        assertTrue( variables != null && !variables.isEmpty() );

        //++++++++++++++++++++++++++++++++++++++++++++
        //Delete a given variable
        String variableId = fieldVariable.getId();
        FieldFactory.deleteFieldVariable( fieldVariable );
        //Try to get the deleted variable
        FieldVariable tempFieldVariable = FieldFactory.getFieldVariable( variableId );

        //validations
        assertTrue( tempFieldVariable == null || tempFieldVariable.getId() == null || tempFieldVariable.getId().isEmpty() );

        //++++++++++++++++++++++++++++++++++++++++++++
        //Delete a given variable
        variableId = fieldVariable2.getId();
        FieldFactory.deleteFieldVariable( variableId );
        //Try to get the deleted variable
        tempFieldVariable = FieldFactory.getFieldVariable( variableId );

        //validations
        assertTrue( tempFieldVariable == null || tempFieldVariable.getId() == null || tempFieldVariable.getId().isEmpty() );
    }
View Full Code Here


 
    FieldAPI fieldAPI = APILocator.getFieldAPI();
 
    List<FieldVariable> variables = fieldAPI.getFieldVariablesForField(fieldId, user, false);
 
    FieldVariable fieldVariable = null;
    for (FieldVariable next : variables) {
      if (next.getKey().equals(key) && !next.getId().equals(id)) {
        return LanguageUtil.get(user, "message.fieldvariables.exist.error.key");
      }
      if(UtilMethods.isSet(id) && next.getId().equals(id)) {
        fieldVariable = next;
        continue;
      }
    }
   
    if(fieldVariable == null) {
      fieldVariable = new FieldVariable();
    }
 
    fieldVariable.setId(id);
    fieldVariable.setFieldId(fieldId);
    fieldVariable.setName(name);
    fieldVariable.setKey(key);
    fieldVariable.setValue(value);
    fieldVariable.setLastModifierId(user.getUserId());
    fieldVariable.setLastModDate(new Date());
    try {
      fieldAPI.saveFieldVariable(fieldVariable, user, respectFrontendRoles);
    } catch (DotSecurityException e) {
      return LanguageUtil.get(user, "message.fieldvariables.permission.error.save");
    }
View Full Code Here

    UserWebAPI userWebAPI = WebAPILocator.getUserWebAPI();
    User user = userWebAPI.getLoggedInUser(req);
    boolean respectFrontendRoles = userWebAPI.isLoggedToFrontend(req);

    FieldAPI fieldAPI = APILocator.getFieldAPI();
    FieldVariable fieldVar = fieldAPI.findFieldVariable(fieldVarId, user, respectFrontendRoles);
    fieldAPI.deleteFieldVariable(fieldVar, user, respectFrontendRoles);
   
    return LanguageUtil.get(user, "message.fieldvariables.deleted");
  }
View Full Code Here

  }

  public static FieldVariable getFieldVariable(String id){

    FieldVariable fVar = new FieldVariable();
     try {
       fVar = (FieldVariable) HibernateUtil.load(FieldVariable.class, id);
    } catch (DotHibernateException e) {
      Logger.error(FieldFactory.class, e.getMessage());
    }
View Full Code Here

    }
    return fVar;
  }

  public static void deleteFieldVariable(String id){
    FieldVariable fieldVar = getFieldVariable(id);
    deleteFieldVariable(fieldVar);
  }
View Full Code Here

        st.setOwner(user.getUserId());
        st.setStructureType(Structure.STRUCTURE_TYPE_CONTENT);
        StructureFactory.saveStructure(st);
        Field ff=new Field("title",FieldType.TEXT,Field.DataType.TEXT,st,true,true,true,1,false,false,true);
        FieldFactory.saveField(ff);
        FieldVariable fv=new FieldVariable();
        fv.setFieldId(ff.getInode());
        fv.setName("variable");
        fv.setKey("variable");
        fv.setValue("value");
        APILocator.getFieldAPI().saveFieldVariable(fv, user, false);
       
        // this should make it live in cache
        List<FieldVariable> list=APILocator.getFieldAPI().getFieldVariablesForField(ff.getInode(), user, false);
        assertEquals(1,list.size());
        assertEquals(list.get(0).getKey(),fv.getKey());
        assertEquals(list.get(0).getValue(),fv.getValue());
       
        List<FieldVariable> clist=(List<FieldVariable>) CacheLocator.getCacheAdministrator()
                .get(FieldsCache.getFieldsVarGroup()+ff.getInode(),
                     FieldsCache.getFieldsVarGroup());
        assertNotNull(clist);
        assertEquals(1,clist.size());
        assertEquals(clist.get(0).getKey(),fv.getKey());
        assertEquals(clist.get(0).getValue(),fv.getValue());
       
        // problems with second save ?
        // https://github.com/dotCMS/dotCMS/issues/2649
       
        FieldVariable fg=new FieldVariable();
        fg.setFieldId(ff.getInode());
        fg.setName("variable");
        fg.setKey("variable");
        fg.setValue("value");
        APILocator.getFieldAPI().saveFieldVariable(fg, user, false);
       
        list=APILocator.getFieldAPI().getFieldVariablesForField(ff.getInode(), user, false);
        assertEquals(2,list.size());
        assertEquals(list.get(0).getKey(),fv.getKey());
        assertEquals(list.get(0).getValue(),fv.getValue());
        assertEquals(list.get(1).getKey(),fg.getKey());
        assertEquals(list.get(1).getValue(),fg.getValue());
       
       
        FieldFactory.deleteField(ff);
        StructureFactory.deleteStructure(st);
    }
View Full Code Here

TOP

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

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.