Package com.dotmarketing.portlets.structure.model

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


        return st;
  }*/

    public static Structure getStructureByInode(String inode) {
      DotCacheAdministrator cache = CacheLocator.getCacheAdministrator();
      Structure st = null;
      try{
        st = (Structure) cache.get(getPrimaryGroup() + inode,getPrimaryGroup());
      }catch (DotCacheException e) {
      Logger.debug(StructureCache.class,"Cache Entry not found", e);
      }
        if (st == null) {
            st = StructureFactory.getStructureByInode(inode);
            if(st != null && UtilMethods.isSet(st.getInode()))
              addStructure(st);
            else
              return null;
        }
        return st;
View Full Code Here


     * @deprecated getting the structure by its name might not be safe, since the
     * structure name can be changed by the user, use getStructureByVelocityVarName
     */
    public static Structure getStructureByName(String name) {
      DotCacheAdministrator cache = CacheLocator.getCacheAdministrator();
        Structure st = null;
        try{
          st = (Structure) cache.get(getPrimaryGroup() + name,getPrimaryGroup());
        }catch (DotCacheException e) {
      Logger.debug(StructureCache.class,"Cache Entry not found", e);
      }
View Full Code Here

     * @return The structure from cache
     *
     */
    public static Structure getStructureByVelocityVarName(String variableName) {
      DotCacheAdministrator cache = CacheLocator.getCacheAdministrator();
        Structure st = null;
        try{
          st = (Structure) cache.get(getPrimaryGroup() + variableName,getPrimaryGroup());
        }catch (DotCacheException e) {
      Logger.debug(StructureCache.class,"Cache Entry not found", e);
      }
View Full Code Here

        String structureInode = req.getParameter("structure_type");
       
        String reportName = "Content Ratings Report";
        Date reportDate = new Date();
       
        Structure structure = StructureFactory.getStructureByInode(structureInode);
       
        String reportComments = "Content Ratings Submitted for " + structure.getName();

        String dateString = (new java.text.SimpleDateFormat("M-d-yyyy")).format(reportDate);
        String reportFileName = structure.getName().replaceAll(" ", "") + "Report-" + dateString + ".xls";

        List<String> reportHeaders = new ArrayList<String>();

        reportHeaders.add("Structure Inode");
        reportHeaders.add("Structure Name");
        reportHeaders.add("Content Inode");
        reportHeaders.add("Content Title");
        reportHeaders.add("Content Rating");
        reportHeaders.add("Date");
        reportHeaders.add("User ID");
        reportHeaders.add("Session ID");
           
        List<List<String>> reportData = new ArrayList<List<String>>();
       
        List<Rating> list = ContentRatingsFactory.getContentRatingsByStructure(structure.getInode());
        List<String> row;
       
        for (Rating rating : list) {
           
            try {
                row = new ArrayList<String>();
                Identifier id = APILocator.getIdentifierAPI().find(rating.getIdentifier());
                Contentlet content = conAPI.findContentletByIdentifier(id.getInode(), false, langAPI.getDefaultLanguage().getId(), APILocator.getUserAPI().getSystemUser(), true);
                String conTitle = conAPI.getName(content, APILocator.getUserAPI().getSystemUser(), true);
                row.add("" + structure.getInode());
                row.add(UtilMethods.isSet(structure.getName()) ? structure.getName() : "");
                row.add("" + content.getInode());
                row.add(UtilMethods.isSet(conTitle) ? conTitle : "");
                row.add("" + rating.getRating());
                row.add(UtilMethods.isSet(rating.getRatingDate()) ? UtilMethods.dateToHTMLDate(rating.getRatingDate()) : "");
                row.add(UtilMethods.isSet(rating.getUserId()) ? rating.getUserId() : "");
View Full Code Here

  public void executeUpgrade() throws DotDataException, DotRuntimeException {
   
      upgradeStructureFields();
     
    Structure structure = StructureFactory.getStructureByVelocityVarName("Host");
    String structureInode = structure.getInode();
   
    Field field = new Field();
    field.setFieldName("Tag Storage");
        field.setStructureInode(structureInode);
        field.setFieldType(Field.FieldType.CUSTOM_FIELD.toString());
        field.setUnique(false);
        field.setFixed(true);
        field.setReadOnly(false);
        field.setIndexed(true);
        field.setReadOnly(false);
   
   
    List<Field> fields = FieldsCache.getFieldsByStructureInode(structure.getInode());
    int sortOrder = 0;
    boolean alreadyExists = false;
   
    for (Field f : fields) {
     
View Full Code Here

                        dc.executeStatement( "insert into inode values ('TEMP_INODE', 'DUMMY_OWNER', to_date('1900-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), 'DUMMY_TYPE') " );
                    } else {
                        dc.executeStatement( "insert into inode values ('TEMP_INODE', 'DUMMY_OWNER', '1900-01-01 00:00:00.00', 'DUMMY_TYPE') " );
                    }

                Structure fileAssetSt = StructureCache.getStructureByVelocityVarName("FileAsset");

                // lets see if we have structures referencing the folder, if so, let's use its host for the dummy identifier
                List<Structure> referencedStructures = APILocator.getFolderAPI().getStructures(folder, APILocator.getUserAPI().getSystemUser(), false);
                String hostForDummyFolder = "SYSTEM_HOST";

                if (referencedStructures!=null && !referencedStructures.isEmpty()) {
            Structure st = referencedStructures.get(0);
            hostForDummyFolder = st.getHost();
          }

                // 1.2) Insert dummy temp row on IDENTIFIER table

                dc.executeStatement("insert into identifier values ('TEMP_IDENTIFIER', '/System folder', 'DUMMY_ASSET_NAME', '"+hostForDummyFolder+"', "
View Full Code Here

            for (Map<String, Object> result : results) {
              String oldStructureInode = (String) result.get("local_inode");
              String newStructureInode = (String) result.get("remote_inode");

        Structure st = StructureCache.getStructureByInode(oldStructureInode);

        List<Contentlet> contents = APILocator.getContentletAPI().findByStructure(st, APILocator.getUserAPI().getSystemUser(), false, 0, 0);
        for (Contentlet contentlet : contents) {
          CacheLocator.getContentletCache().remove(contentlet.getInode());
        }

        StructureCache.removeStructure(st);


        // THIS IS THE NEW CODE

                // 1.1) Insert dummy temp row on INODE table
                if ( DbConnectionFactory.isOracle() ) {
                    dc.executeStatement("insert into inode values ('TEMP_INODE', 'DUMMY_OWNER', to_date('1900-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), 'DUMMY_TYPE') ");
                } else {
                    dc.executeStatement("insert into inode values ('TEMP_INODE', 'DUMMY_OWNER', '1900-01-01 00:00:00.00', 'DUMMY_TYPE') ");
                }

                // 1.2) Insert dummy temp row on STRUCTURE table

                if ( DbConnectionFactory.isOracle() ) {
                    dc.executeStatement("insert into structure values ('TEMP_INODE', 'DUMMY_NAME', 'DUMMY_DESC', '"+DbConnectionFactory.getDBFalse()+"', '', '', '', 1, '"+DbConnectionFactory.getDBTrue()+"', '"+DbConnectionFactory.getDBFalse()+"', 'DUMMY_VAR_NAME'"
                            + ", 'DUMMY_PATERN', '"+st.getHost()+"', '"+st.getFolder()+"', 'EXPIRE_DUMMY', 'PUBLISH_DUMMY', to_date('1900-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS'))");
                } else if ( DbConnectionFactory.isPostgres() ) {
                    dc.executeStatement( "insert into structure values ('TEMP_INODE', 'DUMMY_NAME', 'DUMMY_DESC', " + DbConnectionFactory.getDBFalse() + ", '', '', '', 1, " + DbConnectionFactory.getDBTrue() + ", " + DbConnectionFactory.getDBFalse() + ", 'DUMMY_VAR_NAME'"
                            + ", 'DUMMY_PATERN', '" + st.getHost() + "', '" + st.getFolder() + "', 'EXPIRE_DUMMY', 'PUBLISH_DUMMY', '1900-01-01 00:00:00.00')" );
                } else {
                    dc.executeStatement("insert into structure values ('TEMP_INODE', 'DUMMY_NAME', 'DUMMY_DESC', '"+DbConnectionFactory.getDBFalse()+"', '', '', '', 1, '"+DbConnectionFactory.getDBTrue()+"', '"+DbConnectionFactory.getDBFalse()+"', 'DUMMY_VAR_NAME'"
                            + ", 'DUMMY_PATERN', '"+st.getHost()+"', '"+st.getFolder()+"', 'EXPIRE_DUMMY', 'PUBLISH_DUMMY', '1900-01-01 00:00:00.00')");
                }

                // 2) Update references to the new dummies temps

            // update foreign tables references to TEMP
View Full Code Here

          }
        }
      }
    }
    else {
      Structure specificStructure = StructureCache.getStructureByInode(inodeFilter);
      if(specificStructure != null)
        structures.add(specificStructure);
    }
   
    JSONArray jsonStructures = new JSONArray();
View Full Code Here

        ContentletAPI contentletAPI = APILocator.getContentletAPI();

        //Create a test structure
        String structure1Suffix = String.valueOf( new Date().getTime() );
        Structure structure1 = new Structure();
        structure1.setName( "Import Test " + structure1Suffix );
        structure1.setVelocityVarName( "ImportTest_" + structure1Suffix );
        structure1.setDescription( "Testing import of csv files" );

        StructureFactory.saveStructure( structure1 );

        //Create test fields
        Field textFileStructure1 = new Field( "Title", Field.FieldType.TEXT, Field.DataType.TEXT, structure1, true, true, true, 1, false, false, true );
        FieldFactory.saveField( textFileStructure1 );

        Field hostFileStructure1 = new Field( "Host", Field.FieldType.HOST_OR_FOLDER, Field.DataType.TEXT, structure1, true, true, true, 2, false, false, true );
        FieldFactory.saveField( hostFileStructure1 );

        //----------------PREVIEW = TRUE------------------------------------------
        //------------------------------------------------------------------------
        //Create the csv file to import
        Reader reader = createTempFile( "Title, Host" + "\r\n" +
                "Test1, " + defaultHost.getIdentifier() + "\r\n" +
                "Test2, " + defaultHost.getIdentifier() + "\r\n" +
                "Test3, " + defaultHost.getIdentifier() + "\r\n" +
                "Test4, " + defaultHost.getIdentifier() + "\r\n" );
        CsvReader csvreader = new CsvReader( reader );
        csvreader.setSafetySwitch( false );
        String[] csvHeaders = csvreader.getHeaders();

        //Preview=true
        HashMap<String, List<String>> results = ImportUtil.importFile( 0L, defaultHost.getInode(), structure1.getInode(), new String[]{}, true, false, user, defaultLanguage.getId(), csvHeaders, csvreader, -1, -1, reader );
        //Validations
        validate( results, true, false, true );

        //As it was a preview nothing should be saved
        List<Contentlet> savedData = contentletAPI.findByStructure( structure1.getInode(), user, false, 0, 0 );
        //Validations
        assertNotNull( savedData );
        assertEquals( savedData.size(), 0 );

        //----------------PREVIEW = FALSE-----------------------------------------
        //------------------------------------------------------------------------
        //Create the csv file to import
        reader = createTempFile( "Title, Host" + "\r\n" +
                "Test1, " + defaultHost.getIdentifier() + "\r\n" +
                "Test2, " + defaultHost.getIdentifier() + "\r\n" +
                "Test3, " + defaultHost.getIdentifier() + "\r\n" +
                "Test4, " + defaultHost.getIdentifier() + "\r\n" );
        csvreader = new CsvReader( reader );
        csvreader.setSafetySwitch( false );
        csvHeaders = csvreader.getHeaders();

        //Preview=false
        results = ImportUtil.importFile( 0L, defaultHost.getInode(), structure1.getInode(), new String[]{}, false, false, user, defaultLanguage.getId(), csvHeaders, csvreader, -1, -1, reader );
        //Validations
        validate( results, false, false, true );

        //Now we should have saved data
        savedData = contentletAPI.findByStructure( structure1.getInode(), user, false, 0, 0 );
        //Validations
        assertNotNull( savedData );
        assertEquals( savedData.size(), 4 );

        //----------------USING WRONG HOST IDENTIFIERS----------------------------
        //------------------------------------------------------------------------
        //Create the csv file to import
        reader = createTempFile( "Title, Host" + "\r\n" +
                "Test5, " + defaultHost.getIdentifier() + "\r\n" +
                "Test6, " + "999-99999999-99999999-00000" + "\r\n" +
                "Test7, " + "44444444-5555555555-2222" + "\r\n" );
        csvreader = new CsvReader( reader );
        csvreader.setSafetySwitch( false );
        csvHeaders = csvreader.getHeaders();

        //Preview=true
        results = ImportUtil.importFile( 0L, defaultHost.getInode(), structure1.getInode(), new String[]{}, true, false, user, defaultLanguage.getId(), csvHeaders, csvreader, -1, -1, reader );
        //Validations
        validate( results, true, true, true );

        //We should have the same amount on data
        savedData = contentletAPI.findByStructure( structure1.getInode(), user, false, 0, 0 );
        //Validations
        assertNotNull( savedData );
        assertEquals( savedData.size(), 4 );

        //---------------USING KEY FIELDS-----------------------------------------
        //------------------------------------------------------------------------

        //Making sure the contentlets are in the indexes
        List<ContentletSearch> contentletSearchResults;
        int x = 0;
        do {
            Thread.sleep( 200 );
            //Verify if it was added to the index
            contentletSearchResults = contentletAPI.searchIndex( "+structureName:" + structure1.getVelocityVarName() + " +working:true +deleted:false +" + structure1.getVelocityVarName() + ".title:Test1 +languageId:1", 0, -1, null, user, true );
            x++;
        } while ( (contentletSearchResults == null || contentletSearchResults.isEmpty()) && x < 100 );

        //Create the csv file to import
        reader = createTempFile( "Title, Host" + "\r\n" +
                "Test1, " + defaultHost.getIdentifier() + "\r\n" +
                "Test2, " + defaultHost.getIdentifier() + "\r\n" );
        csvreader = new CsvReader( reader );
        csvreader.setSafetySwitch( false );
        csvHeaders = csvreader.getHeaders();

        //Preview=false
        results = ImportUtil.importFile( 0L, defaultHost.getInode(), structure1.getInode(), new String[]{textFileStructure1.getInode()}, false, false, user, defaultLanguage.getId(), csvHeaders, csvreader, -1, -1, reader );
        //Validations
        validate( results, false, false, true );//We should expect warnings: Line #X. The key fields chosen match 1 existing content(s) - more than one match suggests key(s) are not properly unique

        //We used the key fields, so the import process should update instead to add new records
        savedData = contentletAPI.findByStructure( structure1.getInode(), user, false, 0, 0 );
        //Validations
        assertNotNull( savedData );
        assertEquals( savedData.size(), 4 );

        //---------------USING IDENTIFIER COLUMN----------------------------------
        //------------------------------------------------------------------------
        //Create the csv file to import

        String id1 = null;
        String id2 = null;
        for ( Contentlet content : savedData ) {
            if ( content.getMap().get( "title" ).equals( "Test1" ) ) {
                id1 = content.getIdentifier();
            } else if ( content.getMap().get( "title" ).equals( "Test2" ) ) {
                id2 = content.getIdentifier();
            }
        }

        reader = createTempFile( "Identifier, Title, Host" + "\r\n" +
                id1 + ", Test1_edited, " + defaultHost.getIdentifier() + "\r\n" +
                id2 + ", Test2_edited, " + defaultHost.getIdentifier() + "\r\n" );
        csvreader = new CsvReader( reader );
        csvreader.setSafetySwitch( false );
        csvHeaders = csvreader.getHeaders();

        //Preview=false
        results = ImportUtil.importFile( 0L, defaultHost.getInode(), structure1.getInode(), new String[]{}, false, false, user, defaultLanguage.getId(), csvHeaders, csvreader, -1, -1, reader );
        //Validations
        validate( results, false, false, true );

        //We used a identifier column, so the import process should update instead to add new records
        savedData = contentletAPI.findByStructure( structure1.getInode(), user, false, 0, 0 );
        //Validations
        assertNotNull( savedData );
        assertEquals( savedData.size(), 4 );

        //-------------------------LANGUAGE AND KEY FIELDS------------------------
        //------------------------------------------------------------------------
        //Create the csv file to import
        reader = createTempFile( "languageCode, countryCode, Title, Host" + "\r\n" +
                "es, ES, Test1_edited, " + defaultHost.getIdentifier() + "\r\n" +
                "es, ES, Test2_edited, " + defaultHost.getIdentifier() + "\r\n" );
        csvreader = new CsvReader( reader );
        csvreader.setSafetySwitch( false );
        csvHeaders = csvreader.getHeaders();

        int languageCodeHeaderColumn = 0;
        int countryCodeHeaderColumn = 1;
        //Preview=false
        results = ImportUtil.importFile( 0L, defaultHost.getInode(), structure1.getInode(), new String[]{textFileStructure1.getInode()}, false, true, user, -1, csvHeaders, csvreader, languageCodeHeaderColumn, countryCodeHeaderColumn, reader );
        //Validations
        validate( results, false, false, false );

        //We used the key fields, so the import process should update instead to add new records
        savedData = contentletAPI.findByStructure( structure1.getInode(), user, false, 0, 0 );
        //Validations
        assertNotNull( savedData );
        assertEquals( savedData.size(), 6 );

        //Validate we saved the contentlets on spanish
View Full Code Here

          if (ignorableStructureIds.contains(stVelocityVarName
              .toLowerCase()))
            continue;

          Structure st = StructureFactory
              .getStructureByVelocityVarName(stVelocityVarName);

          if (!InodeUtils.isSet(st.getPagedetail()))
            continue;

          HTMLPage page = htmlAPI.loadLivePageById(
              st.getPagedetail(), systemUser, true);

          Logger.debug(this, " Creating Site Map for Structure "
              + stVelocityVarName);
          Identifier pageIdentifier = identAPI.find(page
              .getIdentifier());

          Logger.debug(this,
              " Performing Host Parameter validation Page Identifider Host ["
                  + pageIdentifier.getHostId()
                  + "], Host Identifider ["
                  + host.getIdentifier() + "], Deleted ["
                  + page.isDeleted() + "], Live ["
                  + page.isLive() + "]");

          if (!(host.getIdentifier().equals(
              pageIdentifier.getHostId()) && (!page.isDeleted() && page
              .isLive()))) {
            Logger.debug(this,
                "Host Parameter validation failed for structure ["
                    + stVelocityVarName + "]");
            continue;
          }

          String query = "+structureName:" + st.getVelocityVarName()
              + " +deleted:false +live:true";

          List<Contentlet> hits = conAPI.search(query, -1, 0, "",
              systemUser, true);

          String structureURLMap = st.getUrlMapPattern();

          List<RegExMatch> matches = null;

          if (useStructureURLMap
              && UtilMethods.isSet(structureURLMap)) {
            matches = RegEX.find(st.getUrlMapPattern(),
                "({[^{}]+})");
          }
          for (Contentlet contenlet : hits) {
            try {
              if (usePermalinks) {
                stringbuf = "<url><loc>"
                    + XMLUtils.xmlEscape("http://"
                        + host.getHostname()
                        + "/permalink/"
                        + contenlet.getIdentifier()
                        + "/" + st.getPagedetail()
                        + "/")
                    + "</loc><lastmod>"
                    + modifiedDateStringValue
                    + "</lastmod><changefreq>daily</changefreq></url>\n";
              } else if (useStructureURLMap
                  && UtilMethods.isSet(structureURLMap)
                  && (matches != null)) {
                String uri = structureURLMap;
                Logger.debug(this,
                    " Found the URL String for validation ["
                        + uri + "]");
                for (RegExMatch match : matches) {
                  String urlMapField = match.getMatch();
                  String urlMapFieldValue = contenlet
                      .getStringProperty(urlMapField
                          .substring(1, (urlMapField
                              .length() - 1)));
                  urlMapField = urlMapField.replaceFirst(
                      "\\{", "\\\\{");
                  urlMapField = urlMapField.replaceFirst(
                      "\\}", "\\\\}");

                  if (urlMapFieldValue != null) {
                    uri = uri.replaceAll(urlMapField,
                        urlMapFieldValue);
                  }
                  Logger.debug(this,
                      "Performing Variable replacement - urlMapField ["
                          + match.getMatch()
                          + "], urlMapField [ "
                          + urlMapField
                          + "], urlMapFieldValue ["
                          + urlMapFieldValue
                          + "], uri [" + uri + "]");
                }

                if (uri == null
                    && UtilMethods
                        .isSet(st.getDetailPage())) {
                  if (page != null
                      && UtilMethods.isSet(page
                          .getIdentifier())) {
                    uri = page.getURI() + "?id="
                        + contenlet.getInode();
View Full Code Here

TOP

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

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.