Package com.dotmarketing.portlets.containers.model

Examples of com.dotmarketing.portlets.containers.model.Container


  @SuppressWarnings("unchecked")
  public Container getLiveContainerById(String id, User user, boolean respectFrontendRoles) throws DotDataException, DotSecurityException {
   
    //Trying to get the container from Live cache.
    Container container = CacheLocator.getContainerCache().getLive(id);
   
    //If it is not in cache.
    if(container == null){
     
      //Get container from DB.
      HibernateUtil dh = new HibernateUtil(Container.class);
     
      dh.setSQLQuery("select {containers.*} from containers, inode containers_1_, container_version_info vv " +
          "where containers.inode = containers_1_.inode and vv.live_inode=containers.inode and " +
          "vv.identifier = ?");
     
      dh.setParam(id);
     
      List<Container> list = dh.list();

      //If DB return something.
      if(!list.isEmpty()){
        Container containerAux = list.get(0);

        if (!permissionAPI.doesUserHavePermission(containerAux, PermissionAPI.PERMISSION_READ, user, respectFrontendRoles)) {
          throw new DotSecurityException("You don't have permission to read the source file.");
        }

        if(InodeUtils.isSet(containerAux.getInode())){
          //container is the one we are going to return.
          container = containerAux;
          //Add to cache.
          CacheLocator.getContainerCache().add(container.getIdentifier(), container);
        }
View Full Code Here


             "and template_containers.template_id = ? ");
    dh.setParam(parentTemplate.getIdentifier());
    List<Identifier> identifiers = dh.list();
    List<Container> containers = new ArrayList<Container>();
    for(Identifier id : identifiers) {
      Container cont = (Container) APILocator.getVersionableAPI().findWorkingVersion(id,APILocator.getUserAPI().getSystemUser(),false);
      containers.add(cont);
    }
    return containers;
  }
View Full Code Here

    return containerFactory.findContainersUnder(parentPermissionable);
  }

  @SuppressWarnings("unchecked")
  public Container save(Container container, List<ContainerStructure> containerStructureList, Host host, User user, boolean respectFrontendRoles) throws DotDataException, DotSecurityException {
    Container currentContainer = null;
    List<Template> currentTemplates = null;
    Identifier identifier = null;
    boolean existingId=false;
    boolean existingInode=false;

    if(UtilMethods.isSet(container.getInode())) {
            try {
                Container existing=(Container) HibernateUtil.load(Container.class, container.getInode());
                existingInode = existing==null || !UtilMethods.isSet(existing.getInode());
            }
            catch(Exception ex) {
                existingInode=true;
            }
        }
View Full Code Here

 
  @Override
  protected Container getWorking(String identifier) {
    String key = primaryGroup + identifier + CONTAINER_WORKING;
   
    Container container = null;
      try{
        container = (Container)cache.get(key,primaryGroup);
      }catch (DotCacheException e) {
      Logger.debug(this, "Cache Entry not found", e);
    }
View Full Code Here

 
  @Override
  protected Container getLive(String identifier) {
    String key = primaryGroup + identifier + CONTAINER_LIVE;
   
    Container container = null;
      try{
        container = (Container)cache.get(key,primaryGroup);
      }catch (DotCacheException e) {
      Logger.debug(this, "Cache Entry not found", e);
    }
View Full Code Here

        User sysuser=APILocator.getUserAPI().getSystemUser();
        Host host=APILocator.getHostAPI().findDefaultHost(sysuser, false);
        String ext="."+Config.getStringProperty("VELOCITY_PAGE_EXTENSION");

        // a container to use inside the template
        Container container = new Container();
        container.setFriendlyName("test container");
        container.setTitle("his is the title");
        container.setMaxContentlets(5);
        container.setPreLoop("preloop code");
        container.setPostLoop("postloop code");
        Structure st=StructureCache.getStructureByVelocityVarName("FileAsset");

        List<ContainerStructure> csList = new ArrayList<ContainerStructure>();
        ContainerStructure cs = new ContainerStructure();
        cs.setStructureId(st.getInode());
        cs.setCode("this is the code");
        csList.add(cs);

        container = APILocator.getContainerAPI().save(container, csList, host, sysuser, false);

        // a template for the page
        Template template=new Template();
        template.setTitle("a template "+UUIDGenerator.generateUuid());
        template.setBody("<html><body> #parseContainer('"+container.getIdentifier()+"') </body></html>");
        template=APILocator.getTemplateAPI().saveTemplate(template, host, sysuser, false);

        // folder where the page lives
        Folder folder=APILocator.getFolderAPI().createFolders(
                "/test_junit/test_"+UUIDGenerator.generateUuid().replaceAll("-", "_"), host, sysuser, false);

        // the page
        HTMLPage page=new HTMLPage();
        page.setPageUrl("testpage"+ext);
        page.setFriendlyName("testpage"+ext);
        page.setTitle("testpage"+ext);
        page=APILocator.getHTMLPageAPI().saveHTMLPage(page, template, folder, sysuser, false);

        // associate some contentlets with the page/container
        List<Contentlet> conns=APILocator.getContentletAPI().search(
                "+structureName:"+st.getVelocityVarName(), 5, 0, "moddate", sysuser, false);
        assertEquals(5, conns.size());

        for(Contentlet cc : conns) {
            MultiTreeFactory.saveMultiTree(
              new MultiTree(page.getIdentifier(),container.getIdentifier(),cc.getIdentifier()));
        }

        final String pageInode=page.getInode(),pageIdent=page.getIdentifier(),
                     templateInode=template.getInode(), templateIdent=template.getIdentifier(),
                     containerInode=container.getInode(), containerIdent=container.getIdentifier();

        // let's delete

        APILocator.getHTMLPageAPI().delete(page, sysuser, false);
        APILocator.getTemplateAPI().delete(template, sysuser, false);
View Full Code Here

    @Test
    public void move() throws Exception {
      User sysuser=null;
      HTMLPage page=null;
      Template template=null;
      Container container=null;
      Role role=null;
      Folder folderWithPerms=null;
      Folder folder=null;

      try {
        sysuser=APILocator.getUserAPI().getSystemUser();
        Host host=APILocator.getHostAPI().findDefaultHost(sysuser, false);
        String ext="."+Config.getStringProperty("VELOCITY_PAGE_EXTENSION");

        // a container to use inside the template
        container = new Container();
        container.setFriendlyName("test container");
        container.setTitle("his is the title");
        container.setMaxContentlets(5);
        container.setPreLoop("preloop code");
        container.setPostLoop("postloop code");
        Structure st=StructureCache.getStructureByVelocityVarName("FileAsset");
        // commented by issue-2093

        List<ContainerStructure> csList = new ArrayList<ContainerStructure>();
            ContainerStructure cs = new ContainerStructure();
            cs.setStructureId(st.getInode());
            cs.setCode("this is the code");
            csList.add(cs);

        container = APILocator.getContainerAPI().save(container, csList, host, sysuser, false);

        // a template for the page
        template=new Template();
        template.setTitle("a template "+UUIDGenerator.generateUuid());
        template.setBody("<html><body> #parseContainer('"+container.getIdentifier()+"') </body></html>");
        template=APILocator.getTemplateAPI().saveTemplate(template, host, sysuser, false);

        // folder where the page gets moved from
        folder=APILocator.getFolderAPI().createFolders(
            "/test_junit/test_"+UUIDGenerator.generateUuid().replaceAll("-", "_"), host, sysuser, false);
View Full Code Here

                    true, true, true, 1, "", "", "", true, false, true);
            field.setVelocityVarName("html");
            FieldFactory.saveField(field);
            FieldsCache.addField(field);

            container=new Container();
            container.setTitle("LinkChecker Container "+uuid);
            container.setCode("$html");
            container.setMaxContentlets(0);

            List<ContainerStructure> csList = new ArrayList<ContainerStructure>();
View Full Code Here

import com.liferay.portal.model.User;

public class ContainerAPITest extends ContentletBaseTest {
    @Test
    public void save() throws Exception {
        Container c = new Container();
        c.setFriendlyName("test container");
        c.setTitle("his is the title");
        c.setMaxContentlets(5);
        c.setPreLoop("preloop code");
        c.setPostLoop("postloop code");

        Container cc = new Container();
        BeanUtils.copyProperties(cc, c);

        Structure st=StructureCache.getStructureByVelocityVarName("host");

        User user = APILocator.getUserAPI().getSystemUser();
        Host host = APILocator.getHostAPI().findDefaultHost(user, false);

        List<ContainerStructure> csList = new ArrayList<ContainerStructure>();
        ContainerStructure cs = new ContainerStructure();
        cs.setStructureId(st.getInode());
        cs.setCode("this is the code");
        csList.add(cs);

        cc = APILocator.getContainerAPI().save(cc, csList, host, user, false);

        assertTrue(UtilMethods.isSet(cc.getInode()));
        assertTrue(UtilMethods.isSet(cc.getIdentifier()));

        cc = APILocator.getContainerAPI().getWorkingContainerById(cc.getIdentifier(), user, false);

        assertTrue(UtilMethods.isSet(cc.getInode()));
        assertTrue(UtilMethods.isSet(cc.getIdentifier()));

        List<ContainerStructure> csListCopy = APILocator.getContainerAPI().getContainerStructures(cc);
        ContainerStructure csCopy = csListCopy.get(0);
        assertTrue(csCopy.getCode().equals(cs.getCode()));
        assertTrue(cc.getFriendlyName().equals(c.getFriendlyName()));
        assertTrue(cc.getTitle().equals(c.getTitle()));
        assertTrue(cc.getMaxContentlets()==c.getMaxContentlets());
        assertTrue(cc.getPreLoop().equals(c.getPreLoop()));
        assertTrue(cc.getPostLoop().equals(c.getPostLoop()));
    }
View Full Code Here

        assertTrue(cc.getPostLoop().equals(c.getPostLoop()));
    }

    @Test
    public void saveWithExistingIds() throws Exception {
        Container c = new Container();
        c.setFriendlyName("test container for existing inode/identifier");
        c.setTitle("his is the title for existing inode/identifier");
        c.setMaxContentlets(5);
        c.setPreLoop("preloop code");
        c.setPostLoop("postloop code");

        // here comes the existing inode/identifier
        String existingInode=UUIDGenerator.generateUuid();
        String existingIdentifier=UUIDGenerator.generateUuid();
        c.setInode(existingInode);
        c.setIdentifier(existingIdentifier);

        Container cc = new Container();
        BeanUtils.copyProperties(cc, c);

        Structure st=StructureCache.getStructureByVelocityVarName("host");

        User user = APILocator.getUserAPI().getSystemUser();
        Host host = APILocator.getHostAPI().findDefaultHost(user, false);

        List<ContainerStructure> csList = new ArrayList<ContainerStructure>();
        ContainerStructure cs = new ContainerStructure();
        cs.setStructureId(st.getInode());
        cs.setCode("this is the code");
        csList.add(cs);

        cc = APILocator.getContainerAPI().save(cc, csList, host, user, false);

        assertTrue(UtilMethods.isSet(cc.getInode()));
        assertTrue(UtilMethods.isSet(cc.getIdentifier()));

        cc = APILocator.getContainerAPI().getWorkingContainerById(cc.getIdentifier(), user, false);

        assertTrue(UtilMethods.isSet(cc.getInode()));
        assertTrue(UtilMethods.isSet(cc.getIdentifier()));

        // existing inode/identifier should match
        assertEquals(cc.getInode(),existingInode);
        assertEquals(cc.getIdentifier(), existingIdentifier);

        assertEquals(cc.getCode(),c.getCode());
        assertEquals(cc.getFriendlyName(),c.getFriendlyName());
        assertEquals(cc.getTitle(),c.getTitle());
        assertEquals(cc.getMaxContentlets(),c.getMaxContentlets());
        assertEquals(cc.getPreLoop(),c.getPreLoop());
        assertEquals(cc.getPostLoop(),c.getPostLoop());

        // now an update with existing inode
        String newInode=UUIDGenerator.generateUuid();
        cc.setPreLoop("new preloop");
        cc.setInode(newInode);
        cc = APILocator.getContainerAPI().save(cc, csList, host, user, false);
        assertEquals(newInode, cc.getInode());
        assertEquals(existingIdentifier, cc.getIdentifier());
        cc = APILocator.getContainerAPI().getWorkingContainerById(cc.getIdentifier(), user, false);
        assertEquals(newInode, cc.getInode());
        assertEquals(existingIdentifier, cc.getIdentifier());
        assertEquals(cc.getPreLoop(),"new preloop");
    }
View Full Code Here

TOP

Related Classes of com.dotmarketing.portlets.containers.model.Container

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.