String parameterValue;
try {
parameterValue = viewpointJSON.getString( parameterName );
} catch (JSONException e) {
logger.error("Impossible read value for the parameter [" + parameterName + "] into viewpoint's content", e);
throw new SpagoBIServiceException(SERVICE_NAME, "Impossible read value for the parameter [" + parameterName + "] into viewpoint's content", e);
}
// defines the string of parameters to save into db
if(!StringUtilities.isEmpty(parameterValue)) {
viewpointString += parameterName + "%3D" + parameterValue + "%26";
}
}
if (viewpointString.endsWith("%26")) {
viewpointString = viewpointString.substring(0, viewpointString.length() - 3);
}
logger.debug("Viewpoint's content will be saved on database as: [" + viewpointString + "]");
try {
viewpointDAO = DAOFactory.getViewpointDAO();
viewpoint = viewpointDAO.loadViewpointByNameAndBIObjectId(viewpointName, biobjectId);
if (viewpoint != null) throw new SpagoBIServiceException(SERVICE_NAME, "A viewpoint with the name [" + viewpointName + "] alredy exist");
//Assert.assertTrue(viewpoint == null, "A viewpoint with the name [" + viewpointName + "] alredy exist");
} catch (EMFUserError e) {
logger.error("Impossible to check if a viewpoint with name [" + viewpointName + "] already exists", e);
throw new SpagoBIServiceException(SERVICE_NAME, "Impossible to check if a viewpoint with name [" + viewpointName + "] already exists", e);
}
try {
viewpointDAO = DAOFactory.getViewpointDAO();
viewpointDAO.setUserProfile(userProfile);
viewpoint = new Viewpoint();
viewpoint.setBiobjId( biobjectId );
viewpoint.setVpName( viewpointName );
viewpoint.setVpOwner( viewpointOwner );
viewpoint.setVpDesc( viewpointDescription );
viewpoint.setVpScope( viewpointScope );
viewpoint.setVpValueParams( viewpointString );
viewpoint.setVpCreationDate(new Timestamp(System.currentTimeMillis()));
viewpointDAO.insertViewpoint(viewpoint);
} catch (EMFUserError e) {
logger.error("Impossible to save viewpoint [" + viewpointName + "]", e);
throw new SpagoBIServiceException(SERVICE_NAME, "Impossible to check if a viewpoint with name [" + viewpointName + "] already exists", e);
}
try {
JSONObject results = (JSONObject) SerializerFactory.getSerializer("application/json").serialize( viewpoint,null );
writeBackToClient( new JSONSuccess( results ) );
} catch (IOException e) {
throw new SpagoBIServiceException(SERVICE_NAME, "Impossible to write back the responce to the client", e);
} catch (SerializationException e) {
throw new SpagoBIServiceException(SERVICE_NAME, "Cannot serialize objects", e);
}
} finally {
logger.debug("OUT");
}