Java Code Examples for org.olap4j.OlapException

The following examples show how to use org.olap4j.OlapException. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * Gets the name of the column of the measure
 *
 * @param member
 * @return
 * @throws SpagoBIEngineException
 */
public String getMeasureColumn(Member member) throws SpagoBIEngineException {
	String measure = member.getName();
	try {
		if ((member.getDimension().getDimensionType().equals(Type.MEASURE))) {
			for (int i = 0; i < editCube.measures.length; i++) {
				if (editCube.measures[i].name.equals(measure)) {
					return editCube.measures[i].column;
				}
			}
		}
	} catch (OlapException e) {
		logger.error("Error loading the measure linked to the member " + member.getUniqueName(), e);
		throw new SpagoBIEngineException("Error loading the measure linked to the member " + member.getUniqueName(), e);
	}

	return null;
}
 
Example 2
Source Project: olaper   Source File: SqlQuery.java    License: MIT License 6 votes vote down vote up
protected void filterLayer(LevelMemberSet layer) throws OlapException {
	OlapOp func =layer.getFunction();
	if(func!=null){
		SetSubquery sub_query = func.query(mapping, layer);
		if(sub_query!=null){
			
			Condition condition = sub_query.condition();
			if(condition!=null)
				addCondition(condition);

			Condition having_condition = sub_query.havingCondition();
			if(having_condition!=null)
				addHavingCondition(having_condition);
			
		}
			

	}
}
 
Example 3
Source Project: olaper   Source File: ServerCube.java    License: MIT License 6 votes vote down vote up
@Override
public Member lookupMember(List<IdentifierSegment> nameParts)
		throws OlapException {
	
	Dimension dim = getDimensions().get(nameParts.get(0).getName());
	if(dim instanceof ServerMeasureDimension){
		String mp = nameParts.get(1).getName();
		for(Measure m : getMeasures()){
			if(m.getName()!=null && m.getName().equals(mp))
				return m;
		}
	}else if(dim instanceof ServerDimension && nameParts.size()>2){
		Hierarchy h = dim.getHierarchies().get(nameParts.get(1).getName());
		if(h!=null){
			Level level = h.getLevels().get(nameParts.get(2).getName());
			if(level!=null){
				if(level.getLevelType()==Type.ALL)
					return h.getDefaultMember();
				else if(nameParts.size()>3)
					return new LevelMember(level, nameParts.get(3).getName(), 0);
			}
		}
		
	}
	return null;
}
 
Example 4
/**
 * @param member
 * @return
 */
public static boolean isVisible(Member member) {
	try {
		if (member.getDimension().getDimensionType() == Type.MEASURE) {
			return member.isVisible();
		}
	} catch (OlapException e) {
		throw new PivotException(e);
	}

	return true;
}
 
Example 5
/**
 * @see org.olap4j.metadata.Member#getChildMembers()
 */

public NamedList<? extends Member> getChildMembers() throws OlapException {
	if (isBaseMember()) {
		return baseMember.getChildMembers();
	}

	return children;
}
 
Example 6
/**
 * @see org.olap4j.metadata.Member#getChildMemberCount()
 */

public int getChildMemberCount() throws OlapException {
	if (isBaseMember()) {
		return baseMember.getChildMemberCount();
	}

	return 1;
}
 
Example 7
/**
 * @see org.olap4j.metadata.Member#getPropertyValue(org.olap4j.metadata.Property)
 */

public Object getPropertyValue(Property property) throws OlapException {
	if (isBaseMember()) {
		return baseMember.getPropertyValue(property);
	}

	return null;
}
 
Example 8
/**
 * @see org.olap4j.metadata.Member#setProperty(org.olap4j.metadata.Property,
 *      java.lang.Object)
 */

public void setProperty(Property property, Object value) throws OlapException {
	if (isBaseMember()) {
		baseMember.setProperty(property, value);
	} else {
		throw new UnsupportedOperationException();
	}
}
 
Example 9
/**
 * @return
 */
public Set<NodeFilter> build() {
	Set<NodeFilter> nodes = new TreeSet<NodeFilter>();
	try {
		for (Member member : hierarchy.getRootMembers()) {

			nodes.add(new NodeFilter(member, nodeLimit, treeMembers, visibleMembers, showSiblings));
		}
	} catch (OlapException e) {
		logger.error("Error while creating filter tree", e);
		throw new SpagoBIRuntimeException("Error while creating filter tree", e);
	}

	return nodes;
}
 
Example 10
@Override

	public void injectField(Member parentMember, IdentifierNode calculatedNode) {

		try {
			if (contains(rootNode, parentMember) && isMeasureOrHasAnyChildren(parentMember)) {
				rootNode.getArgList().add(getCFPosition(parentMember.getChildMembers()), getCFNode(calculatedNode));

			}
		} catch (OlapException e) {
			logger.error("Error while injecting cf in braces", e);
			throw new SpagoBIEngineRuntimeException("Error while injecting cf in braces", e);
		}

	}
 
Example 11
@POST
@Path("/properties")
@Produces("text/html; charset=UTF-8")

public String getProperties(@javax.ws.rs.core.Context HttpServletRequest req) throws OlapException, JSONException {

	String name = null;

	try {
		JSONObject paramsObj = RestUtilities.readBodyAsJSONObject(req);

		name = paramsObj.getString("memberUniqueName");
	} catch (Exception e) {
		logger.error("Error reading body", e);
	}

	WhatIfEngineInstance ei = getWhatIfEngineInstance();
	SpagoBIPivotModel model = (SpagoBIPivotModel) ei.getPivotModel();
	NonInternalPropertyCollector np = new NonInternalPropertyCollector();

	JSONArray propsArray = new JSONArray();
	Member m = CubeUtilities.getMember(model.getCube(), name);
	Level l = m.getLevel();
	List<Property> properties = np.getProperties(l);

	for (Property property : properties) {
		JSONObject obj = new JSONObject();
		obj.put("name", property.getName());
		obj.put("value", m.getPropertyFormattedValue(property));
		propsArray.put(obj);
	}
	return propsArray.toString();
}
 
Example 12
public static Member getMember(Cube cube, String memberUniqueName) throws OlapException {
	Hierarchy hierarchy = null;
	NamedList<Hierarchy> hierarchies = cube.getHierarchies();

	for (int i = 0; i < hierarchies.size(); i++) {
		String hName = hierarchies.get(i).getUniqueName();
		if (memberUniqueName.startsWith(hName)) {
			hierarchy = hierarchies.get(i);
			break;
		}
	}

	return getMember(hierarchy.getLevels().get(0).getMembers(), memberUniqueName);
}
 
Example 13
Source Project: olaper   Source File: ServerDatabase.java    License: MIT License 5 votes vote down vote up
@Override
public NamedList<Catalog> getCatalogs() throws OlapException {
	
	NamedList<Catalog> list = MetadataUtils.catalogNamedList(new ArrayList<Catalog>());
    for(CatalogDefinition cdef: definition.catalogs){
    	list.add(new ServerCatalog(this, cdef));
    }

	return list;
}
 
Example 14
/**
 * Searches in the cube for the hierarchy
 *
 * @param cube
 *            the cube
 * @param hierarchyUniqueName
 *            the unique name of the hierarchy to search
 * @return
 * @throws OlapException
 */
public static Hierarchy getHierarchy(Cube cube, String hierarchyUniqueName) throws OlapException {
	Hierarchy hierarchy = null;
	NamedList<Hierarchy> hierarchies = cube.getHierarchies();
	for (int i = 0; i < hierarchies.size(); i++) {
		String hName = hierarchies.get(i).getUniqueName();
		if (hName.equals(hierarchyUniqueName)) {
			hierarchy = hierarchies.get(i);
			break;
		}
	}
	return hierarchy;
}
 
Example 15
Source Project: olaper   Source File: ServerDatabase.java    License: MIT License 5 votes vote down vote up
public ServerDatabase(OlapConnection serverConnection, String url,
		Properties info) throws OlapException {
		
	this.serverConnection = serverConnection;
	this.url = url;
	try{
		this.definition = DatabaseDefinition.getDatabase(url);
	}catch(Exception ex){
		throw new OlapException("Failed to connect to "+url+", unable to read datasource due to "+ex.getMessage(), ex);
	}
		
}
 
Example 16
private static String getMemberPropertyValue(Member member, String propertyName) {
	logger.debug("IN: Member is " + member.getUniqueName() + ", propertyName is " + propertyName);
	String toReturn = null;
	Property property = member.getProperties().get(propertyName);
	if (property != null) {
		try {
			toReturn = member.getPropertyValue(property).toString();
		} catch (OlapException e) {
			logger.error("Error getting the property " + propertyName + " from the cube ", e);
			throw new SpagoBIEngineRuntimeException("Error getting the property " + propertyName + " ", e);
		}
	}
	logger.debug("OUT: returning " + toReturn);
	return toReturn;
}
 
Example 17
public SbiMember(Member member, boolean visible, String description) {

		this.uniqueName = member.getUniqueName();
		this.id = member.getUniqueName();
		this.name = member.getCaption();
		this.text = calculateText(member.getName(), member.getCaption());

		try {
			this.leaf = member.getChildMemberCount() == 0;
		} catch (OlapException e) {
			throw new SpagoBIEngineRuntimeException("Error getting the childs count for the member " + member.getUniqueName(), e);
		}
		this.visible = visible;
		this.qtip = description;
	}
 
Example 18
Source Project: olaper   Source File: Colon.java    License: MIT License 5 votes vote down vote up
@Override
public SetSubquery query(TableMapping mapping, LevelMemberSet layer)
		throws OlapException {
			
	LevelMapping lmap = mapping.getMapping(member_from.getLevel());
	
	return new SetSubquery(lmap.join, lmap.key_column, 
			((LevelMember)member_from).getKey(),
			((LevelMember)member_to).getKey());		
}
 
Example 19
public SbiDimension(Dimension dimension, int axis, int positionInAxis) {
	super();
	this.name = dimension.getName();
	this.caption = dimension.getCaption();
	this.uniqueName = dimension.getUniqueName();
	this.axis = axis;
	this.hierarchies = new ArrayList<SbiHierarchy>();
	this.positionInAxis = positionInAxis;

	try {
		this.measure = dimension.getDimensionType().equals(Dimension.Type.MEASURE) ? 1 : 0;
	} catch (OlapException e) {
		logger.error("Error setting getting the type of the dimension", e);
	}
}
 
Example 20
public String executeUpdate(Member[] members, double prop, Connection connection, Integer version) throws Exception {
	// list of the coordinates for the members
	List<IMemberCoordinates> memberCordinates = new ArrayList<IMemberCoordinates>();

	// init the query with the update set statement
	StringBuffer query = new StringBuffer();

	// gets the measures and the coordinates of the dimension members
	for (int i = 0; i < members.length; i++) {
		Member aMember = members[i];

		try {
			if (!(aMember.getDimension().getDimensionType().equals(Type.MEASURE))) {
				memberCordinates.add(retriver.getMemberCordinates(aMember));
			} else {
				buildUpdate(query, aMember, prop);
			}
		} catch (OlapException e) {
			logger.error("Error loading the type of the dimension of the member " + aMember.getUniqueName(), e);
			throw new SpagoBIEngineException("Error loading the type of the dimension of the member " + aMember.getUniqueName(), e);
		}
	}

	String whereClause = buildFromAndWhereClauseForCell(members, version, useInClause);
	query.append(whereClause);

	String queryString = query.toString();

	SqlUpdateStatement updateStatement = new SqlUpdateStatement(queryString);
	updateStatement.executeStatement(connection);

	return queryString.toString();

}
 
Example 21
Source Project: olaper   Source File: OlapFunction.java    License: MIT License 5 votes vote down vote up
@Override
public Collection<ServerMeasure> getAllMeasuresUsed() throws OlapException {
	if(node instanceof CallNode){
		Set<ServerMeasure> result = new HashSet<ServerMeasure>();
		for(IdentifierNode inode : ParseUtils.getAllIdentifiers((CallNode) node)){
			Member m = cube.lookupMember(inode.getSegmentList());
			if(m instanceof ServerMeasure)
				result.add((ServerMeasure) m);
		}
		return result;
	}else
		return Collections.emptyList();
}
 
Example 22
private void initializeInternal(TableRenderContext context) {
	if (!this.initialized) {
		this.measureOnRows = true;
		this.initialized = true;
		this.positionMeasureMap = new HashMap<Integer, String>();

		// check if the measures are in the rows or in the columns
		List<Member> columnMembers = null;
		Position p = context.getColumnPosition();
		if (p != null) {
			columnMembers = p.getMembers();
		}

		try {
			if (columnMembers != null) {
				for (int i = 0; i < columnMembers.size(); i++) {
					Member member = columnMembers.get(i);
					if (member.getDimension().getDimensionType().equals(Dimension.Type.MEASURE)) {
						this.measureOnRows = false;
					}
				}
			}
		} catch (OlapException e) {
			throw new SpagoBIEngineRuntimeException("Erro getting the measure of a rendered cell ", e);
		}
	}
}
 
Example 23
Source Project: olaper   Source File: BottomCount.java    License: MIT License 5 votes vote down vote up
@Override
public SetSubquery query(TableMapping mapping, LevelMemberSet layer)
		throws OlapException {
	SetSubquery ss = super.query(mapping, layer);
	layer.getSorter().setDirectionString("ASC");
	return ss;
}
 
Example 24
Source Project: olaper   Source File: ResultAxis.java    License: MIT License 5 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
public Set<ServerMeasure> collectAllUsedMeasures() throws OlapException{
	
	Set measures = new HashSet();
	for(LevelMemberSet layer : layers){
		if(layer.isMeasure()){
			measures.addAll(layer.getMembers());
		}
		measures.addAll(layer.getFunction().getAllMeasuresUsed());
	}
	
	return measures;
	
}
 
Example 25
Source Project: olaper   Source File: ServerDimension.java    License: MIT License 5 votes vote down vote up
private void readHierarchies() throws OlapException {
	
	hierarchies = MetadataUtils.metadataNamedList(new ArrayList<Hierarchy>());  
	
	Map<String, AttributeDefinition> attributeMap = new HashMap<String, AttributeDefinition>();
	
    if(definition.attributes!=null)        
    for(AttributeDefinition cdef: definition.attributes){
    	attributeMap.put(cdef.name, cdef);
    	if(cdef.auto_hierarchy){
    		hierarchies.add(new ServerHierarchy(this, cdef,  Collections.singletonList((NamedElement)cdef)));
    	}
    }
    
    if(definition.hierarchies!=null)
    for(HierarchyDefinition hdef : definition.hierarchies){
    	
    	List<NamedElement> levelDefs = new ArrayList<NamedElement>();
    	for(String level : hdef.levels){	
    		AttributeDefinition attr_def = attributeMap.get(level);
    		if(attr_def==null)
    			throw new OlapException("Fail to find attribute "+level+" used in dimension "+ getName());
    		levelDefs.add(attr_def);
    	}
    	
    	hierarchies.add(new ServerHierarchy(this, hdef, levelDefs));
    }
}
 
Example 26
Source Project: olaper   Source File: SqlMembersQuery.java    License: MIT License 5 votes vote down vote up
@Override
public void process(ResultSet result) throws SQLException, OlapException {
	members = new ArrayList<Member>();
	while(result.next()){
		
		String key = result.getString(ID_ALIAS);
		String name = result.getString(NAME_ALIAS);
		
		members.add(new LevelMember(level, key, name, members.size()));
		
	}
}
 
Example 27
Source Project: olaper   Source File: SqlConnector.java    License: MIT License 5 votes vote down vote up
public Connection getConnection() throws OlapException{
	try {
		return dataSource.getConnection();
	} catch (SQLException e) {
		throw new OlapException("Fail to get connection", e);
	}		
}
 
Example 28
Source Project: olaper   Source File: Colon.java    License: MIT License 5 votes vote down vote up
@Override
public List<LevelMemberSet> memberSet() throws OlapException {

	List<LevelMemberSet> arg_set_from = createLevelMemberSet(node.getArgList().get(0));
	List<LevelMemberSet> arg_set_to = createLevelMemberSet(node.getArgList().get(1));
	
	member_from = arg_set_from.get(0).getMembers().get(0);
	member_to = arg_set_to.get(0).getMembers().get(0);

	if(member_from.getLevel()!=member_to.getLevel())
		throw new OlapException("Levels mismatch: "+node.toString());
	
	return Collections.singletonList(new LevelMemberSet(member_from.getLevel(), node, this));
}
 
Example 29
Source Project: olaper   Source File: ServerHierarchy.java    License: MIT License 4 votes vote down vote up
@Override
public int getChildMemberCount() throws OlapException {
	return 0;
}
 
Example 30
/**
 * @param member
 * @param cube
 */
RaggedMemberWrapper(Member member, Cube cube) {
	this.baseMember = member;
	this.level = member.getLevel();
	this.ancestors = new LinkedList<Member>();

	List<IdentifierSegment> segments = Collections.unmodifiableList(IdentifierParser.parseIdentifier(member.getUniqueName()));
	List<IdentifierSegment> resolvableSegments = new LinkedList<IdentifierSegment>();

	int i = 0;
	int count = segments.size();

	List<Level> levels = member.getHierarchy().getLevels();

	for (IdentifierSegment segment : segments) {
		resolvableSegments.add(segment);

		Level currentLevel = levels.get(i);

		Member ancestor;

		try {
			ancestor = cube.lookupMember(resolvableSegments);

			if (ancestor == null && i == 0) {
				ancestor = member.getHierarchy().getDefaultMember();
			}
		} catch (OlapException e) {
			throw new PivotException(e);
		}

		if (i == 0 && ancestor == null) {
			throw new PivotException("Can't determine top level parent for the ragged member : " + member.getUniqueName());
		}

		i++;

		if (i >= count) {
			this.uniqueName = getUniqueName(resolvableSegments);
		} else if (ancestor == null) {
			String currentName = getUniqueName(segments.subList(0, i));

			ancestor = new RaggedMemberWrapper(currentName, currentLevel, new LinkedList<Member>(ancestors), baseMember, topMember);
			ancestors.add(0, ancestor);

			resolvableSegments.remove(segment);
		} else {
			ancestors.add(0, ancestor);

			this.topMember = ancestor;
		}
	}

	if (topMember == null) {
		throw new IllegalArgumentException("Unable to find a non-ragged ancestor of the specified member : " + member);
	}
}