Package com.dotmarketing.portlets.contentlet.business

Examples of com.dotmarketing.portlets.contentlet.business.ContentletAPI


  }
 
  @SuppressWarnings("deprecation")
  public ActionErrors validate(ActionMapping arg0, HttpServletRequest request)
  {
    ContentletAPI conAPI = APILocator.getContentletAPI();
    ActionErrors errors = new ActionErrors();
    Contentlet parentContentlet = new Contentlet()
    HttpSession session = request.getSession();
        Captcha captchaSession = (Captcha) session.getAttribute(Captcha.NAME);

        try{
      parentContentlet = conAPI.find(contentInode, APILocator.getUserAPI().getSystemUser(), true);
    }catch(DotDataException e){
      Logger.error(this, "Unable to look up contentlet with inode " + contentInode, e);
    }catch (DotSecurityException dse) {
      Logger.error(this, "Unable to look up contentlet with inode " + contentInode + " because of security issue", dse);
    }
   
    if(parentContentlet==null || !InodeUtils.isSet(parentContentlet.getInode())){
      errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("message.contentlet.required","Contentlet Inode"));       
      return errors;
    }
    if (!UtilMethods.isSet(name))
    {
      errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("message.contentlet.required","Name"));       
    }
    if (!UtilMethods.isSet(email) || ! UtilMethods.isValidEmail(email))
    {       
      errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("message.contentlet.required","Email"));       
    }
    /*  Try to find a title if we don't have one.  */
    if (!UtilMethods.isSet(commentTitle))
      {
      Structure s = StructureCache.getStructureByInode(parentContentlet.getStructureInode());
      List<Field> lf = s.getFields();
      for(Field f : lf){
        if("text".equals(f.getFieldType()) && f.isIndexed() && f.isListed()){
          try{
            commentTitle = "re: " + conAPI.getFieldValue(parentContentlet, f);
          }catch (Exception e) {
            Logger.error(CommentsForm.class, "Unable to set comment title", e);
          }
          break;
        }
View Full Code Here


    req.setAttribute(WebKeys.VERSIONS_INODE_EDIT, contentlet);

  }

  private void _loadContentletRelationshipsInRequest(ActionRequest request, Contentlet contentlet, Structure structure,User user) throws DotDataException {
    ContentletAPI contentletService = APILocator.getContentletAPI();
    contentlet.setStructureInode(structure.getInode());
    ContentletRelationships cRelationships = contentletService.getAllRelationships(contentlet);

    //DOTCMS-6097, if we don't have the related piece of content in the language the user is looking at, we show the flag of the language user is on but in gray.
    List<ContentletRelationships.ContentletRelationshipRecords> relationshipRecords = cRelationships.getRelationshipsRecords();
    for(ContentletRelationshipRecords contentletRelationshipRecords: relationshipRecords){
      List<Contentlet> contentletsList = contentletRelationshipRecords.getRecords();
View Full Code Here

  @SuppressWarnings("unchecked")
  public void _editWebAsset(ActionRequest req, ActionResponse res, PortletConfig config, ActionForm form, User user)
  throws Exception {

    ContentletForm cf = (ContentletForm) form;
    ContentletAPI contAPI = APILocator.getContentletAPI();

    Contentlet contentlet = (Contentlet) req.getAttribute(WebKeys.CONTENTLET_EDIT);
    Contentlet workingContentlet = null;

    String sib= req.getParameter("sibbling");
    Boolean populateaccept = Boolean.valueOf(req.getParameter("populateaccept"));

    ActionRequestImpl reqImpl = (ActionRequestImpl) req;
    HttpServletRequest httpReq = reqImpl.getHttpServletRequest();
    httpReq.getSession().setAttribute("populateAccept", populateaccept);


    if(UtilMethods.isSet(sib))
    {
      Contentlet sibbling=conAPI.find(sib, user,false);
      conAPI.unlock(sibbling, user, false);
      if(populateaccept){
        contentlet = sibbling;
        contentlet.setInode("");
        //http://jira.dotmarketing.net/browse/DOTCMS-5802
        Structure structure = contentlet.getStructure();
        List<Field> list = (List<Field>) FieldsCache.getFieldsByStructureInode(structure.getInode());
        for (Field field : list) {
          if(field.getFieldContentlet().startsWith("binary")){
            httpReq.getSession().setAttribute(field.getFieldContentlet() + "-sibling", sib+","+field.getVelocityVarName());
            java.io.File inputFile = APILocator.getContentletAPI().getBinaryFile(sib, field.getVelocityVarName(), user);
            if(inputFile != null){
              java.io.File acopyFolder=new java.io.File(APILocator.getFileAPI().getRealAssetPathTmpBinary()
                  + java.io.File.separator + user.getUserId() + java.io.File.separator + field.getFieldContentlet()
                                  + java.io.File.separator + UUIDGenerator.generateUuid());
             
              if(!acopyFolder.exists())
                              acopyFolder.mkdir();
             
              String shortFileName = FileUtil.getShortFileName(inputFile.getAbsolutePath());
             
              java.io.File binaryFile = new java.io.File(APILocator.getFileAPI().getRealAssetPathTmpBinary()
                  + java.io.File.separator + user.getUserId() + java.io.File.separator + field.getFieldContentlet()
                  + java.io.File.separator + shortFileName.trim());
             
              FileUtil.copyFile(inputFile, binaryFile);
            }
          }
        }
      }
    }

    if(InodeUtils.isSet(contentlet.getInode())){
      workingContentlet = contAPI.findContentletByIdentifier(contentlet.getIdentifier(), false, contentlet.getLanguageId(), user, false);
    }else{
      workingContentlet = contentlet;
    }

    if(!InodeUtils.isSet(contentlet.getInode())) {
View Full Code Here

    String inodesSt;
    String[] inodes;
    Relationship relationship;
    String inode;
    Contentlet contentlet;
    ContentletAPI contentletAPI = APILocator.getContentletAPI();
    List<Contentlet> records = null;

    for (String key : keys) {
      if (key.startsWith("rel_") && key.endsWith("_inodes")) {
        hasParent = key.indexOf("_P_") != -1;
        inodesSt = (String) req.getParameter(key);
        inodes = inodesSt.split(",");
        relationship = (Relationship) InodeFactory.getInode(inodes[0], Relationship.class);
        contentletRelationshipRecords = new ContentletRelationships(null).new ContentletRelationshipRecords(relationship, hasParent);
        records = new ArrayList<Contentlet>();

        for (int i = 1; i < inodes.length; i++) {
          try {
            inode = inodes[i];
            contentlet = contentletAPI.find(inode, user, false);
            if ((contentlet != null) && (InodeUtils.isSet(contentlet.getInode())))
              records.add(contentlet);
          } catch (Exception e) {
            Logger.warn(this, e.toString());
          }
View Full Code Here

    HttpServletRequest httpReq = reqImpl.getHttpServletRequest();

    //WebAsset webAsset = (WebAsset) req.getAttribute(webKeyEdit);
    com.dotmarketing.portlets.contentlet.model.Contentlet webAsset = (com.dotmarketing.portlets.contentlet.model.Contentlet)req.getAttribute(webKeyEdit);

    ContentletAPI conAPI;
    conAPI = APILocator.getContentletAPI();
    ActionResponseImpl resImpl = (ActionResponseImpl) res;
    // calls the Contentlet API delete the container version
    try{
      //conAPI.delete(webAsset, user, false, false);
      conAPI.deleteVersion(webAsset,user,false);


    }catch(Exception e){
      resImpl.getHttpServletResponse().getWriter().println("FAILURE:" + LanguageUtil.get(user, "message.contentlet.delete.live_or_working"));
    }
View Full Code Here

        MaintenanceUtil.flushCache();

        ReindexThread.startThread(Config.getIntProperty("REINDEX_THREAD_SLEEP", 500), Config.getIntProperty("REINDEX_THREAD_INIT_DELAY", 5000));

        ContentletAPI conAPI = APILocator.getContentletAPI();
        Logger.info(this, "Building Initial Index");
        try {
            APILocator.getContentletIndexAPI().getRidOfOldIndex();
        } catch (DotDataException e1) {
            Logger.warn(this, "Exception trying to delete old indexes",e1);
        }
        conAPI.refreshAllContent();
        long recordsToIndex = 0;
        try {
            recordsToIndex = APILocator.getDistributedJournalAPI().recordsLeftToIndexForServer();
            Logger.info(this, "Records left to index : " + recordsToIndex);
        } catch (DotDataException e) {
View Full Code Here

        Long time = new Date().getTime();

        CategoryAPI categoryAPI = APILocator.getCategoryAPI();
        PermissionAPI permissionAPI = APILocator.getPermissionAPI();
        ContentletAPI contentletAPI = APILocator.getContentletAPI();

        List<Category> categories = new ArrayList<Category>();

        //***************************************************************
        //Creating new categories

        HibernateUtil.startTransaction();

        //Adding the parent category
        Category parentCategory = new Category();
        parentCategory.setCategoryName( "Movies" + time );
        parentCategory.setKey( "movies" + time );
        parentCategory.setCategoryVelocityVarName( "movies" + time );
        parentCategory.setSortOrder( (String) null );
        parentCategory.setKeywords( null );
        //Saving it
        categoryAPI.save( null, parentCategory, user, false );

        //Creating child categories
        //New Child category
        Category childCategory1 = new Category();
        childCategory1.setCategoryName( "Action" + time );
        childCategory1.setKey( "action" + time );
        childCategory1.setCategoryVelocityVarName( "action" + time );
        childCategory1.setSortOrder( (String) null );
        childCategory1.setKeywords( null );
        //Saving it
        categoryAPI.save( parentCategory, childCategory1, user, false );
        categories.add( childCategory1 );
        //New Child category
        Category childCategory2 = new Category();
        childCategory2.setCategoryName( "Drama" + time );
        childCategory2.setKey( "drama" + time );
        childCategory2.setCategoryVelocityVarName( "drama" + time );
        childCategory2.setSortOrder( (String) null );
        childCategory2.setKeywords( null );
        //Saving it
        categoryAPI.save( parentCategory, childCategory2, user, false );
        categories.add( childCategory2 );

        HibernateUtil.commitTransaction();

        //***************************************************************
        //Verify If we find the parent for the categories we just added categories
        List<Category> parents = categoryAPI.getParents( childCategory1, user, false );
        assertNotNull( parents );
        assertTrue( parents.size() > 0 );
        assertEquals( parents.get( 0 ), parentCategory );

        parents = categoryAPI.getParents( childCategory2, user, false );
        assertNotNull( parents );
        assertTrue( parents.size() > 0 );
        assertEquals( parents.get( 0 ), parentCategory );

        //***************************************************************
        //Set up a new structure with categories

        HibernateUtil.startTransaction();

        //Create the new structure
        Structure testStructure = createStructure( "JUnit Test Categories Structure_" + String.valueOf( new Date().getTime() ), "junit_test_categories_structure_" + String.valueOf( new Date().getTime() ) );
        //Add a Text field
        Field textField = new Field( "JUnit Test Text", Field.FieldType.TEXT, Field.DataType.TEXT, testStructure, false, true, true, 1, false, false, false );
        FieldFactory.saveField( textField );
        //Add a Category field
        Field categoryField = new Field( "JUnit Movies", Field.FieldType.CATEGORY, Field.DataType.TEXT, testStructure, true, true, true, 2, false, false, true );
        categoryField.setValues( parentCategory.getInode() );
        FieldFactory.saveField( categoryField );

        //***************************************************************
        //Set up a content for the categories structure
        Contentlet contentlet = new Contentlet();
        contentlet.setStructureInode( testStructure.getInode() );
        contentlet.setHost( defaultHost.getIdentifier() );
        contentlet.setLanguageId( APILocator.getLanguageAPI().getDefaultLanguage().getId() );

        //Validate if the contenlet is OK
        contentletAPI.validateContentlet( contentlet, categories );

        //Saving the contentlet
        contentlet = APILocator.getContentletAPI().checkin( contentlet, categories, permissionAPI.getPermissions( contentlet, false, true ), user, false );
        APILocator.getContentletAPI().isInodeIndexed( contentlet.getInode() );
        APILocator.getVersionableAPI().setLive( contentlet );
View Full Code Here

      Field widgetTitle =  simpleWidgetSt.getFieldVar("widgetTitle");
      Field widgetCode = simpleWidgetSt.getFieldVar("code");


      ContentletAPI contentletAPI = APILocator.getContentletAPI();

      contentletAPI.setContentletProperty( widget, widgetTitle, "newsTestWidget" );
      contentletAPI.setContentletProperty( widget, widgetCode, "$URLMapContent.story" );

      widget = contentletAPI.checkin( widget, null, permissionAPI.getPermissions( simpleWidgetSt ), user, false );
      APILocator.getVersionableAPI().setLive(widget);

      // add the widget to the detail page
      MultiTreeFactory.saveMultiTree( new MultiTree( htmlPage.getIdentifier(), container.getIdentifier(), widget.getIdentifier() ) );

     
      // STRUCTURE
      testSt = new Structure();

      testSt.setDefaultStructure( false );
      testSt.setDescription( "News Test" );
      testSt.setFixed( false );
      testSt.setIDate( new Date() );
      testSt.setName( "NewsTest" +salt);
      testSt.setOwner( user.getUserId() );
      testSt.setStructureType( Structure.STRUCTURE_TYPE_CONTENT );
      testSt.setType( "structure" );
      testSt.setVelocityVarName( "NewsTest" +salt );
      testSt.setUrlMapPattern("/newstest"+salt+"/{urlNewsTitle}");
      testSt.setDetailPage( htmlPage.getIdentifier() );

      StructureFactory.saveStructure( testSt );

      //Creating and adding permissions
      Permission permissionRead = new Permission( testSt.getInode(), roleAPI.loadCMSAnonymousRole().getId(), PermissionAPI.PERMISSION_READ );
      Permission permissionEdit = new Permission( testSt.getInode(), roleAPI.loadCMSAnonymousRole().getId(), PermissionAPI.PERMISSION_EDIT );
      Permission permissionWrite = new Permission( testSt.getInode(), roleAPI.loadCMSAnonymousRole().getId(), PermissionAPI.PERMISSION_WRITE );

      permissionAPI.save( permissionRead, testSt, user, false );
      permissionAPI.save( permissionEdit, testSt, user, false );
      permissionAPI.save( permissionWrite, testSt, user, false );

      // FIELDS

      // headline
      Field headline = new Field();
      headline.setFieldName("Headline");
      headline.setFieldType(FieldType.TEXT.toString());
      headline.setListed(true);
      headline.setRequired(true);
      headline.setSearchable(true);
      headline.setStructureInode(testSt.getInode());
      headline.setType("field");
      headline.setValues("");
      headline.setVelocityVarName("testTitle");
      headline.setIndexed(true);
      headline.setFieldContentlet("text4");
      FieldFactory.saveField( headline );

      // URL Title
      Field urlTitle = new Field();
      urlTitle.setFieldName("URL Title");
      urlTitle.setFieldType(FieldType.CUSTOM_FIELD.toString());
      urlTitle.setRequired(true);
      urlTitle.setStructureInode(testSt.getInode());
      urlTitle.setType("field");
      urlTitle.setValues("#dotParse('//shared/vtl/custom-fields/url-title.vtl')");
      urlTitle.setVelocityVarName("urlNewsTitle");
      urlTitle.setSearchable(true);
      urlTitle.setIndexed(true);
      urlTitle.setFieldContentlet("text_area4");
      FieldFactory.saveField( urlTitle );

      // WYSIWYG
      Field story = new Field();
      story.setFieldName("Story");
      story.setFieldType(FieldType.WYSIWYG.toString());
      story.setRequired(true);
      story.setStructureInode(testSt.getInode());
      story.setType("field");
      story.setValues("");
      story.setVelocityVarName("story");
      story.setFieldContentlet("text_area3");
      FieldFactory.saveField( story );

      // ENGLISH CONTENT
      Contentlet englishContent = new Contentlet();
      englishContent.setReviewInterval( "1m" );
      englishContent.setStructureInode( testSt.getInode() );
      englishContent.setHost( demoHost.getIdentifier() );
      englishContent.setLanguageId(1);


      contentletAPI.setContentletProperty( englishContent, headline, "the-gas-price" );
      contentletAPI.setContentletProperty( englishContent, story, "the-gas-price" );
      contentletAPI.setContentletProperty( englishContent, urlTitle, "the-gas-price" );

      englishContent = contentletAPI.checkin( englishContent, null, permissionAPI.getPermissions( testSt ), user, false );
      APILocator.getVersionableAPI().setLive(englishContent);

      // SPANISH CONTENT
      Contentlet spanishContent = new Contentlet();
      spanishContent.setReviewInterval("1m");
      spanishContent.setStructureInode(testSt.getInode());
      spanishContent.setHost(demoHost.getIdentifier());
      spanishContent.setLanguageId(2);
      spanishContent.setIdentifier(englishContent.getIdentifier());

      contentletAPI.setContentletProperty( spanishContent, headline, "el-precio-del-gas" );
      contentletAPI.setContentletProperty( spanishContent, story, "el-precio-del-gas" );
      contentletAPI.setContentletProperty( spanishContent, urlTitle, "el-precio-del-gas" );

      spanishContent = contentletAPI.checkin( spanishContent, null, permissionAPI.getPermissions( testSt ), user, false );
      APILocator.getVersionableAPI().setLive(spanishContent);

      HibernateUtil.commitTransaction();

      if(!(contentletAPI.isInodeIndexed(englishContent.getInode(), true) &&
              contentletAPI.isInodeIndexed(spanishContent.getInode(), true) &&
                contentletAPI.isInodeIndexed(widget.getInode(), true))) {
        fail("Content indexing timeout.");

      }

    } catch (Exception e) {
View Full Code Here

TOP

Related Classes of com.dotmarketing.portlets.contentlet.business.ContentletAPI

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.