@Override public Object clone() { Category clone = new Category(); // shallow copies clone( clone ); clone.setParent( getParent() ); // deep copies clone.setLogicalColumns( new ArrayList<LogicalColumn>() ); for ( LogicalColumn col : getLogicalColumns() ) { clone.addLogicalColumn( col ); } return clone; } }
/** * Creates a lightweight, serializable category objects from a logical model category * * @param m * @param c * @return */ private Category createCategory( LogicalModel m, org.pentaho.metadata.model.Category c ) { // create a thin category object Category cat = new Category(); cat.setName( c.getName( getLocale() ) ); cat.setId( c.getId() ); List<Column> columns = new ArrayList<Column>(); for ( LogicalColumn col : c.getLogicalColumns() ) { columns.add( createColumn( m, col, c ) ); } cat.setColumns( columns.toArray( new Column[ columns.size() ] ) ); return cat; }
/** * Returns the full category object for a given column within the logical model * * @param columnId * @param logicalModel * @return */ protected org.pentaho.metadata.model.Category getCategory( String columnId, LogicalModel logicalModel ) { for ( org.pentaho.metadata.model.Category category : logicalModel.getCategories() ) { if ( category.findLogicalColumn( columnId ) != null ) { return category; } } return null; }
public Category() { super(); // category has the following default properties setName( new LocalizedString() ); setDescription( new LocalizedString() ); }
protected void populateCategories( ModelerWorkspace workspace ) { RelationalModelNode model = workspace.getRelationalModel(); LogicalModel logicalModel = workspace.getDomain().getLogicalModels().get( 0 ); logicalModel.getCategories().clear(); for ( CategoryMetaData catMeta : model.getCategories() ) { Category cat = new Category(); cat.setName( new LocalizedString( this.getLocale(), catMeta.getName() ) ); cat.setId( catMeta.getName() ); for ( FieldMetaData fieldMeta : catMeta ) { LogicalColumn lCol = fieldMeta.getLogicalColumn(); LogicalTable lTable = lCol.getLogicalTable(); if ( !lTable.getLogicalColumns().contains( lCol ) ) { lTable.addLogicalColumn( lCol ); } lCol.setName( new LocalizedString( locale, fieldMeta.getName() ) ); AggregationType type = fieldMeta.getDefaultAggregation(); lCol.setAggregationType( type ); setLogicalColumnFormat( fieldMeta.getFormat(), lCol ); Set<AggregationType> possibleAggs = new HashSet<AggregationType>(); possibleAggs.add( fieldMeta.getDefaultAggregation() ); possibleAggs.addAll( fieldMeta.getSelectedAggregations() ); lCol.setAggregationList( Arrays.<AggregationType>asList( possibleAggs .toArray( new AggregationType[possibleAggs.size()] ) ) ); cat.addLogicalColumn( lCol ); } logicalModel.addCategory( cat ); } }
if ( category.getId() != null ) { tableNode.addElement( "view_id" ).setText( category.getId() ); //$NON-NLS-1$ if ( category.getName( locale ) != null ) { tableNode.addElement( "view_name" ).setText( category.getName( locale ) ); //$NON-NLS-1$ if ( category.getDescription( locale ) != null ) { tableNode.addElement( "view_description" ).setText( category.getDescription( locale ) ); //$NON-NLS-1$ for ( LogicalColumn column : category.getLogicalColumns() ) { Boolean hidden = (Boolean) column.getProperty( "hidden" ); //$NON-NLS-1$ if ( hidden != null && hidden ) {
Category cat = new Category( logicalModel ); cat.setId( category.getAttribute( "name" ) ); //$NON-NLS-1$ xmiConceptMap.put( category.getAttribute( "xmi.id" ), cat ); //$NON-NLS-1$ bindParentConcept( category, domain, cat ); if ( col == null ) { logger.warn( Messages.getString( "XmiParser.ERROR_0010_UNABLE_TO_FIND_COL_FOR_CATEGORY", name, cat.getId() ) ); //$NON-NLS-1$ } else { cat.addLogicalColumn( col );
/** * searches the category for a specific column id. * * @param columnId * column to search for * * @return logical column object if found */ public LogicalColumn findLogicalColumn( String columnId ) { for ( LogicalColumn col : getLogicalColumns() ) { if ( columnId.equals( col.getId() ) ) { return col; } } return null; }
for ( Category category : model.getCategories() ) { Element extent = doc.createElement( "CWM:Extent" ); //$NON-NLS-1$ extent.setAttribute( "name", category.getId() ); //$NON-NLS-1$ idstr = idGen.getNextId(); extent.setAttribute( "xmi.id", idstr ); //$NON-NLS-1$ modelElement.appendChild( createTaggedValue( doc, "BUSINESS_CATEGORY_ROOT", "Y", idGen.getNextId() ) ); //$NON-NLS-1$ //$NON-NLS-2$ if ( category.getParentConcept() != null ) { modelElement.appendChild( createTaggedValue( doc, "CONCEPT_PARENT_NAME", category.getParentConcept().getId(), idGen.getNextId() ) ); //$NON-NLS-1$ for ( LogicalColumn col : category.getLogicalColumns() ) { Element attribute = doc.createElement( "CWM:Attribute" ); //$NON-NLS-1$ attribute.setAttribute( "name", col.getId() ); //$NON-NLS-1$
for ( Category cat : lModel.getCategories() ) { String catName = BaseModelerWorkspaceHelper.getCleanCategoryName( cat.getName( workspaceHelper.getLocale() ), this, i++ ); CategoryMetaData catMeta = new CategoryMetaData( catName ); for ( LogicalColumn col : cat.getLogicalColumns() ) { LogicalTable table = col.getLogicalTable();
public Category findCategory( String categoryId ) { for ( Category category : getCategories() ) { if ( categoryId.equals( category.getId() ) ) { return category; } } return null; }
public static WAQRTransport createFromMetadata( Domain domain ) { // this assumes a single logical model with a single logical category LogicalModel model = domain.getLogicalModels().get( 0 ); Iterator<String> iter = model.getName().getLocales().iterator(); String locale = iter.next(); Category category = model.getCategories().get( 0 ); String domainId = domain.getId(); String modelId = model.getId(); String modelName = model.getName() != null ? model.getName().getString( locale ) : null; String categoryId = category.getId(); String categoryName = category.getName() != null ? category.getName().getString( locale ) : null; String schemaName = model.getName( locale ); return createDomain( domainId, modelId, modelName, categoryId, categoryName, schemaName ); }
for ( LogicalColumn col : category.getLogicalColumns() ) { if ( col.getId().equals( column.getId() ) ) { view = category; "<mql><domain_type>relational</domain_type><domain_id>" + domainName + "</domain_id><model_id>" + modelId + "</model_id>"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ if ( column.getProperty( "lookup" ) == null ) { //$NON-NLS-1$ mql += "<selection><view>" + view.getId() + "</view><column>" + column.getId() + "</column></selection>"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ mql += "<orders><order><direction>asc</direction><view_id>" + view.getId() + "</view_id><column_id>" + column.getId() + "</column_id></order></orders>"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"QueryXmlHelper.ERROR_0015_BUSINESS_CATEGORY_NOT_FOUND", view ) ); //$NON-NLS-1$ LogicalColumn businessColumn = category.findLogicalColumn( column ); if ( businessColumn == null ) { throw new PentahoMetadataException( Messages.getErrorString( "QueryXmlHelper.ERROR_0013_BUSINESS_COL_NOT_FOUND", category.getId(), column ) ); //$NON-NLS-1$
Category category = new Category( logicalModel ); convertConceptFromLegacy( bizCategory, category ); category.getLogicalColumns().add( logicalModel.findLogicalColumn( businessColumn.getId() ) );
public static final String proposeSqlBasedCategoryId( String locale, LogicalTable table, Category category ) { String baseID = ( table != null ) ? Util.toId( (String) table.getProperty( SqlPhysicalTable.TARGET_TABLE ) ) : ""; //$NON-NLS-1$ String namePart = ( ( category != null ) && ( category.getName( locale ) != null ) ) ? "_" + Util.toId( category.getName( locale ) ) : ""; //$NON-NLS-1$ //$NON-NLS-2$ String id = Util.getCategoryIdPrefix() + baseID + namePart; return id.toUpperCase(); }
logicalModel.setName( new LocalizedString( locale.getCode(), modelName ) ); Category mainCategory = new Category( logicalModel ); String categoryID = Settings.getBusinessCategoryIDPrefix() + modelName; mainCategory.setId( categoryID ); mainCategory.setName( new LocalizedString( locale.getCode(), modelName ) ); mainCategory.addLogicalColumn( logicalColumn );
/** * finds a logical column within the model. * * @param columnId the column to find * @return a logical column object. */ public LogicalColumn findLogicalColumnInCategories( String columnId ) { for ( Category cat : getCategories() ) { for ( LogicalColumn column : cat.getLogicalColumns() ) { if ( columnId.equals( column.getId() ) ) { return column; } } } return null; }
@Override protected void addSelectionToDocument( Document doc, Selection selection, Element selectionElement ) { AliasedSelection aliasedSelection = (AliasedSelection) selection; Category view = selection.getCategory(); LogicalColumn column = selection.getLogicalColumn(); Element element = null; if ( view != null && column != null ) { element = doc.createElement( "view" ); //$NON-NLS-1$ element.appendChild( doc.createTextNode( view.getId() ) ); selectionElement.appendChild( element ); element = doc.createElement( "column" ); //$NON-NLS-1$ element.appendChild( doc.createTextNode( column.getId() ) ); selectionElement.appendChild( element ); if ( aliasedSelection.getAlias() != null ) { element = doc.createElement( "alias" ); //$NON-NLS-1$ element.appendChild( doc.createTextNode( aliasedSelection.getAlias() ) ); selectionElement.appendChild( element ); } } else if ( aliasedSelection.getFormula() != null ) { element = doc.createElement( "formula" ); //$NON-NLS-1$ element.appendChild( doc.createTextNode( aliasedSelection.getFormula() ) ); selectionElement.appendChild( element ); } }