How to render the content of a Tomcat 7 server location in your html/jsp

This is a short but useful tutorial. I’ve googled for 3 hours before understanding how to access a tomcat folder location.
The following example should help you.

If you want to render images from a server location in Tomcat 7, you need to create a your-web-app/META-INF/context.xml file and specify a location:

<?xml version="1.0"?>
<Context path="/images" docBase="/home/laura/gallery" reloadable="true"/>

Then in your .jsp file you will simply set the img tag like the following:

<img src="/images/picture.jpg" width="30%"  />

Alternatively you can also set the context xml file in the /tomcat-7.0.23/conf/Catalina/localhost folder, by giving it the same name of the webapp, (that is yourWebApp.xml).
I prefer to place the file in the meta-inf folder of the project so I can control il in the IDE enviroment.

I’m doing this to make my development in local host, but in the future i will need it to access an externa image folder for a database.

Discussions are welcome 🙂

Liferay search container pagination problem when passing form parameter SOLVED

Hello, guys!
I’ve been struggling for a couple of days trying to make my seach container pagination works.
When you clicking on the next page and you need to use a form parameter value submitted to get the rows, you need to store it in the portlet preferences, otherwise you lose it in the page “refresh”.

I haven’t found a solution on the web so far, so I’m posting my code snippets… that WORKS lol:
but I’m using portlet preferences … check it out!

[b]action method in the controller:[/b]

		public void searchVolume(ActionRequest request, ActionResponse response)
			throws IOException, PortletException, PortalException,
			SystemException, NoSuchVolumeException {

		String volumeIdentifier = request.getParameter("volumeId");
		long volumeId = (long) Integer.parseInt(volumeIdentifier);
		long idVol = 0;

		boolean found = false;
		boolean emptyList = false;

		List volume = new ArrayList();
		volume = VolumeLocalServiceUtil.getAllVolumes();
		List caseArchive = new ArrayList();
		caseArchive = CaseArchiveLocalServiceUtil
				.getAllCasesbyVolumeId(volumeId);

		if (caseArchive.size() == 0) {
			emptyList = true;
		}

		for (Volume itemVolume : volume) {
			if (itemVolume.getVolumeId() == volumeId)
				found = true;
		}

		if (found && emptyList) {
			SessionMessages.add(request, "no-cases-found");
		} else if (found && !emptyList) {
			Volume vol = DBUtil.getVolumefromRequest(request);
			idVol = vol.getVolumeId();

			if (idVol == 1) {
				System.out.println("Volume id iniziale: " + volumeId);
				SessionErrors.add(request, "error-volume");
			} else if (SearchValidator.volumeNotNull(idVol) && !(idVol == 1))

			{
				System.out.println("Volume id action : " + vol.getVolumeId());

				response.setRenderParameter("volId", volumeIdentifier);
				System.out.println("search volume clicked");

				PortletPreferences prefs = request.getPreferences();
				String volumeIdent = request.getParameter("volumeId");
				if (volumeIdent != null) {
					prefs.setValue("volumeIdPref", volumeIdent);
					prefs.store();
				}

				VolumeLocalServiceUtil.clearService();

				SessionMessages.add(request, "search-volume");

			}
		} else
			SessionErrors.add(request, "error-volume");

		response.setRenderParameter("jspPage", viewDatabaseJSP);

	}

[b]JSP page[/b]:


	CaseArchiveLocalServiceUtil.clearCache();
	VolumeLocalServiceUtil.clearCache();

	//RoiLocalServiceUtil.clearCache();
	//ImageDBLocalServiceUtil.clearCache();
	//DicomLocalServiceUtil.clearCache();
	ImageTypeLocalServiceUtil.clearCache();

	List volumes = VolumeLocalServiceUtil.getAllVolumes();
	List cases = CaseArchiveLocalServiceUtil.getAllCases();
	Long volumeIdentifier = 1L;

	Collections.sort(volumes, new Comparator() {
		public int compare(Volume o1, Volume o2) {
			Volume p1 = (Volume) o1;
			Volume p2 = (Volume) o2;
			return p1.getVolumeName().compareToIgnoreCase(
					p2.getVolumeName());
		}
	});

	PortletURL portletURL = renderResponse.createRenderURL();

	portletURL.setParameter("jspPage", "/html/admin/viewDatabase.jsp");

	int selected = 0;
	String volSel = null;

	PortletPreferences prefs = renderRequest.getPreferences();
	String volumeId = (String) prefs.getValue("volumeIdPref", "1");
%>

	method="post">

		 1) {
						volumeIdentifier = (long) Integer.parseInt(volumeId);

					}

					List tempResults = DBUtil
							.getAllCasesOk(volumeIdentifier);

					results = ListUtil.subList(tempResults,
							searchContainer.getStart(),
							searchContainer.getEnd());

					total = tempResults.size();

					pageContext.setAttribute("results", results);
					pageContext.setAttribute("total", total);

					portletURL.setParameter("cur",
							searchContainer.getCurParam());
					System.out.println("Cur PRINT:" + searchContainer.getCur());
		%>

					href="" name='view Case' />

 <a href="<%=cancelURL%>">← Back to Menu</a>

In the example above, volumeId is the form action parameter (passed by the select option), while volumeIdPref is the portlet preferences parameter, which keeps the value while consulting the pages.
In the action method, that is invoked when submitting the form value, i’ve set a response parameter called volId which is used in the jsp to set the variable value when invoking the search-container result page “1”. The render parameter is null when visiting the other pages, but it can be retrieved by the portlet preferences value.

I hope this helps. Let me know if you have questions or suggestions.
Regards
Laura

Liferay Service Builder with external database

To make a Liferay Service Builder with external database there are some rules to follow. This post will help you to get straight to the point.
Keep in mind that:

  • You can’t deploy more than one portlet mapping column with the same entity name, otherwise you get a hot-Deployment error.
  • the names of the portlet name, namespace and database must be distinct (ex. portlet=”imageview“, namespace=”mammography“, database=”dicomviewer“).
  • when you add external jar, you must add them in the Tomcat/lib/ext
    so liferay can find them in the global classpath.

The steps to make the service builder with the external database mapping are:

  1. make the service.xml file in the /docroot/WEB-INF/
  2. launch the build-service ant command
  3. add the ext-spring.xml file in the /docroot/WEB-INF/src/META-INF/ folder
  4. deploy the portlet.

The example below might be helpful.

—service.xml ————

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.0.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_6_0_0.dtd">


<service-builder package-path="it.dicom">
<author>Laura Liparulo</author>
<namespace>mammography</namespace>

<entity name="Volume" local-service="true" remote-service="true" table="volume"
data-source="mammographyDataSource" session-factory="mammographySessionFactory" tx-manager="mammographyTransactionManager">
<!-- PK Fields -->
<column name="volumeId" type="long" primary="true" />
<!-- Other Fields -->
<column name="volumeName" type="String" />
<!-- Relationships -->
<column name="caseVolume" type="Collection" entity="CaseArchive"
mapping-key="volumeId" />
<order by="asc">
<order-column name="volumeName" />

</order>
<finder name="Volume_Name" return-type="Collection">
<finder-column name="volumeName" />
</finder>
</entity>

<entity name="CaseArchive" local-service="true" remote-service="true" table="case_archive"
data-source="mammographyDataSource" session-factory="mammographySessionFactory" tx-manager="mammographyTransactionManager">
<!-- PK Fields -->
<column name="caseId" type="long" primary="true" />
<!-- Other Fields -->
<column name="caseName" type="String" />
<column name="volumeId" type="long" />
<column name="notes" type="String" />
<!-- Relationships -->
<column name="image_Case" type="Collection" entity="Image"
mapping-key="caseId" />
<order by="asc">
<order-column name="caseName" />
</order>
<finder name="Case_Name" return-type="Collection">
<finder-column name="caseName" />

</finder>
</entity>

</service-builder>
;

—ext-spring.xml ————

<?xml version="1.0"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean
class="
org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
</bean>
<bean id="mammographyDataSourceTarget"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/dicomviewer" />
<property name="username" value="root" />

<property name="password" value="tigertailz" />
</bean>
<bean id="mammographyDataSource"
class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy">
<property name="targetDataSource">
<ref bean="mammographyDataSourceTarget" />
</property>
</bean>
<bean id="mammographyHibernateSessionFactory"
class="com.liferay.portal.spring.hibernate.PortletHibernateConfiguration">
<property name="dataSource">
<ref bean="mammographyDataSource" />
</property>
</bean>
<bean id="mammographySessionFactory">
<property name="sessionFactoryImplementor">
<ref bean="mammographyHibernateSessionFactory" />

</property>
</bean>
<bean id="mammographyTransactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="dataSource">
<ref bean="mammographyDataSource" />
</property>
<property name="sessionFactory">
<ref bean="mammographyHibernateSessionFactory" />
</property>
</bean>
</beans>

Now you can make it fast as a shark! 🙂

WordPress: How to remove items in the administration dashboards

Yeah, you have understood that this blog is powered by WordPress.

Surfing the web, I have found plugins and posts about removing items from the wordpress dashboard.

Loggin as administrator, i’ve tried a plugin called: “remove-posts-from-admin”, but that doesn’t remove the comments.

I’ve tried some code modifications suggested by other bloggers, so I’ve found a way to make it.

Nobody tells it straight. So here it is :-). You have to modify a file in your theme folder:

/www/wp-content/themes/yourtheme/functions.php

To remove “posts” and “comments” simply add this code at the end of the file:

 

 

add_action( 'admin_menu', 'remove_links_menu' );
function remove_links_menu() {
remove_menu_page('index.php'); // Dashboard
// remove_menu_page('edit.php'); // Posts
// remove_menu_page('upload.php'); // Media
// remove_menu_page('link-manager.php'); // Links
// remove_menu_page('edit.php?post_type=page'); // Pages
remove_menu_page('edit-comments.php'); // Comments
// remove_menu_page('themes.php'); // Appearance
// remove_menu_page('plugins.php'); // Plugins
// remove_menu_page('users.php'); // Users
//remove_menu_page('tools.php'); // Tools
// remove_menu_page('options-general.php'); // Settings
}
?>

 

 

Another way is the following. This is a core modification and may cause incompatibility problems if you want to upgrade. Anyway it works:

You simply need to edit the file called menu.php in the wp-admin directory.

I’ve commented the “posts” and “comments” sections and moved Pages to the top (changed the number in the array, $menu[5] is now Posts) :

$menu[5] = array( __('Pages'), 'edit_pages', 'edit.php?post_type=page', '', 'menu-top menu-icon-page', 'menu-pages', 'div' );
$submenu['edit.php?post_type=page'][5] = array( __('All Pages'), 'edit_pages', 'edit.php?post_type=page' );
/* translators: add new page */
$submenu['edit.php?post_type=page'][10] = array( _x('Add New', 'page'), 'edit_pages', 'post-new.php?post_type=page' );
$i = 15;
foreach ( get_taxonomies( array(), 'objects' ) as $tax ) {
if ( ! $tax->show_ui || ! in_array('page', (array) $tax->object_type, true) )
continue;

$submenu['edit.php?post_type=page'][$i++] = array( esc_attr( $tax->labels->menu_name ), $tax->cap->manage_terms, 'edit-tags.php?taxonomy=' . $tax->name . '&post_type=page' );
}
unset($tax);

$awaiting_mod = wp_count_comments();

$awaiting_mod = $awaiting_mod->moderated;

To remove a section you must comment the piece of code, adding /* at the beginning and */ at the end. Like this:

POSTS:
/*$menu[5] = array( __('Posts'), 'edit_posts', 'edit.php', '', 'open-if-no-js menu-top menu-icon-post', 'menu-posts', 'div' );
$submenu['edit.php'][5] = array( __('All Posts'), 'edit_posts', 'edit.php' );
/* translators: add new post */ /*
$submenu['edit.php'][10] = array( _x('Add New', 'post'), 'edit_posts', 'post-new.php' );

$i = 15;
foreach ( get_taxonomies( array(), 'objects' ) as $tax ) {
if ( ! $tax->show_ui || ! in_array('post', (array) $tax->object_type, true) )
continue;

$submenu['edit.php'][$i++] = array( esc_attr( $tax->labels->menu_name ), $tax->cap->manage_terms, 'edit-tags.php?taxonomy=' . $tax->name );
}
unset($tax); */

COMMENTS:

/*$menu[25] = array( sprintf( __('Comments %s'), "" . number_format_i18n($awaiting_mod) . "" ), 'edit_posts', 'edit-comments.php', '', 'menu-top menu-icon-comments', 'menu-comments', 'div' );
unset($awaiting_mod);

$submenu[ 'edit-comments.php' ][0] = array( __('All Comments'), 'edit_posts', 'edit-comments.php' );

$_wp_last_object_menu = 25; // The index of the last top-level menu in the object menu group
*/

Easy, right?

Liferay Upload file portlet (working) example with upload progress bar :-)

Hi guys I’m posting you my Portlet method and edit.jsp.. it works fine 🙂 I’ve also included the upload progress bar 🙂  :kid::kid:
:kid:

[b]<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui"%>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui"%>
<%@ page import="com.liferay.portal.kernel.util.ParamUtil"%>
<%@ page import="com.liferay.portal.kernel.util.Validator"%>
<%@ page import="javax.portlet.PortletPreferences"%>
<%@ page import="com.liferay.util.PwdGenerator"%>
<portlet:defineObjects />
<%
String uploadProgressId = PwdGenerator.getPassword(PwdGenerator.KEY3, 4);
PortletPreferences prefs = renderRequest.getPreferences();

%>



<portlet:actionURL var="editCaseURL" name="uploadCase">
<portlet:param name="jspPage" value="/edit.jsp" />
</portlet:actionURL>
<liferay-ui:success key="success" message=" YEAH. Case uploaded successfully!" />
<liferay-ui:error key="error"
message="Sorry, an error prevented the upload. Please try again." />
<liferay-ui:upload-progress
id="<%= uploadProgressId %>"
message="uploading"
redirect="<%= editCaseURL %>"
/>

<aui:form action="<%= editCaseURL %>" enctype="multipart/form-data" method="post" >
<aui:input type="file" name="fileName" size="75"/>
<input type="submit" value="<liferay-ui:message key="upload" />" onClick="<%= uploadProgressId %>.startProgress(); return true;"/>
<!--  aui:button type="submit" value="Save" /-->
</aui:form>


<br />
<br />
<br />
<br />
<portlet:renderURL var="viewCaseURL">
<portlet:param name="jspPage" value="/view2.jsp" />
</portlet:renderURL>

<aui:button onClick="<%=viewCaseURL%>" value="view Uploaded Case" />[/b]

this is the UPLOAD method:

[b] public void uploadCase(ActionRequest actionRequest,
			ActionResponse actionRresponse) throws PortletException,
			IOException {

		String folder = getInitParameter("uploadFolder");
		realPath = getPortletContext().getRealPath("/");

		logger.info("RealPath" + realPath + " UploadFolder :" + folder);
		try {
			logger.info("Siamo nel try");
			UploadPortletRequest uploadRequest = PortalUtil
					.getUploadPortletRequest(actionRequest);
		 System.out.println("Size: "+uploadRequest.getSize("fileName"));
		 
		if (uploadRequest.getSize("fileName")==0) {
			SessionErrors.add(actionRequest, "error");
		}
			
		
			String sourceFileName = uploadRequest.getFileName("fileName");
			File file = uploadRequest.getFile("fileName");

			logger.info("Nome file:" + uploadRequest.getFileName("fileName"));
			File newFile = null;
			newFile = new File(folder + sourceFileName);
			logger.info("New file name: " + newFile.getName());
			logger.info("New file path: " + newFile.getPath());

			InputStream in = new BufferedInputStream(uploadRequest.getFileAsStream("fileName"));
			FileInputStream fis = new FileInputStream(file);
			FileOutputStream fos = new FileOutputStream(newFile);

			byte[] bytes_ = FileUtil.getBytes(in);
			int i = fis.read(bytes_);

			while (i != -1) {
				fos.write(bytes_, 0, i);
				i = fis.read(bytes_);
			}
			fis.close();
			fos.close();
			Float size = (float) newFile.length();
			System.out.println("file size bytes:" + size);
			System.out.println("file size Mb:" + size / 1048576);

			logger.info("File created: " + newFile.getName());
			SessionMessages.add(actionRequest, "success");

		} catch (FileNotFoundException e) {
			System.out.println("File Not Found.");
			e.printStackTrace();
			SessionMessages.add(actionRequest, "error");
		} catch (NullPointerException e) {
			System.out.println("File Not Found");
			e.printStackTrace();
			SessionMessages.add(actionRequest, "error");
		}

		catch (IOException e1) {
			System.out.println("Error Reading The File.");
			SessionMessages.add(actionRequest, "error");
			e1.printStackTrace();
		}

	}

[/b]

It works fine! the errors get properly notified when the file size exceeds 100 MB

MySQL Stored Procedure for calculating total file_size in MByte or GByte

I’m currently working on my Master degree thesis and I’m projecting a demo database about a Mammography archive. The purpose is providing an archive, whose clinical cases can be consulted on a portal page by a user interface.
I must create a database for a Liferay portal. Liferay is a very powerful opensouce CMS / web application framework written in Java that allows creating the database and the queries by an xml file.
Before developing the portlet I need to study the situation. I’m analyzing and evaluating the query formulations, as I will have to develop GUIs to consult the image (Echography) archive and upload new cases.

I’ve started with some sql scripts.
I’ve made a sql script to create and populate the Mammography database. Then I’ve made another script to add the archive zip file size of each clinical case and a stored procedure to update the volume table (grouping clinical cases of the same category) with the sum of the cases’ zip file size.
You can download the ER diagram clicking on the image above (powered by MySQLWorkbench!).

The script to create and populate the DB is:

/*Mammography demo database */

CREATE DATABASE `mammography`;
/* access database */
USE `mammography`;

CREATE TABLE scanner (
id_scanner INT(2) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
scanner_type VARCHAR(100) NOT NULL
);

CREATE TABLE volume (
id_volume INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
volume_name VARCHAR(100) NOT NULL,
cases INT(10), /* filled by a query */
total_size VARCHAR(10), /*filled by a query calculating the Gb*/
id_scanner INT(2) NOT NULL,
bits INT(10) NOT NULL,
resolution VARCHAR(50) NOT NULL, /*es. 42 microon , might be calculated*/
overview TEXT,
FOREIGN KEY(id_scanner) REFERENCES scanner (id_scanner)
);

/* 1:N* - one volume - n cases*/
CREATE TABLE case_archive (
id_case INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
case_name VARCHAR(100) NOT NULL,
id_volume INT(10) NOT NULL REFERENCES volume(id_volume) ,
ics_version VARCHAR(50) NOT NULL,
date_case DATE NOT NULL,
age_patient INT(3) NOT NULL,
film VARCHAR(50) ,
film_type VARCHAR(50) ,
density INT(10) NOT NULL,
digitizer_dba INT(10) NOT NULL,
notes TEXT,
zip_folder_link TEXT NOT NULL,
FOREIGN KEY (id_volume) REFERENCES volume(id_volume)
);

/* 1 image type : N images*/
CREATE TABLE image_type (
id_image_type INT(2) NOT NULL AUTO_INCREMENT PRIMARY KEY,
image_type VARCHAR(100)
);

/* 1:N* - one case - n images*/
CREATE TABLE image (
id_image INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
id_case INT(10) NOT NULL,
image_name VARCHAR(150),
image_type INT(2) NOT NULL,
link TEXT NOT NULL,
bits_pixel INT(10) NOT NULL, /*might be null*/
resolution VARCHAR(50) NOT NULL,
left_cc_lines int(10) NOT NULL,
pixels_per_line INT(10) NOT NULL,
/* the following column might null in normal cases - demo:only 2 columns */
total_abnormality INT(10),
abnormality INT(2),
FOREIGN KEY (id_case) REFERENCES case_archive (id_case),
FOREIGN KEY(image_type) REFERENCES image_type (id_image_type)
);

/*————————————————————————————*/

/* 3 scanner types */
insert into scanner(scanner_type) values('DBA');
insert into scanner(scanner_type) values('HOWTECK');
insert into scanner(scanner_type) values('LUMISYS');

/* 2 Volumes, 2 Cases X Volume*/
insert into volume (volume_name, id_scanner, bits, resolution, overview) values ('normal_01', 1, 16,'42 microns', 'overview notes ');
insert into volume (volume_name, id_scanner, bits, resolution, overview) values ('cancer_01', 3, 12, '50 microns', 'overview notes');

/* Image type*/
insert into image_type(image_type) values('Left_cc 0');
insert into image_type(image_type) values('Right_cc 1');
insert into image_type(image_type) values(' Left_mcl 2');
insert into image_type(image_type) values(' Right_mcl 3');

/* 2 Cases*/
insert into case_archive (case_name, id_volume, ics_version, date_case, age_patient, density, digitizer_dba, notes, zip_folder_link) values ('A-0002-1', 1, 1.0,'2008-06-13', 63, 2, 21,'n/a','/home/laura/project/case/normal1_case0001.zip' );
insert into case_archive (case_name, id_volume, ics_version, date_case, age_patient, density, digitizer_dba, notes, zip_folder_link) values ('A-0002-1', 1, 1.0,'2007-04-23', 43, 3, 23,'n/a','/home/laura/project/case/normal1_case0002.zip' );
insert into case_archive (case_name, id_volume, ics_version, date_case, age_patient, density, digitizer_dba, notes, zip_folder_link) values ('A-0002-1', 2, 1.0,'2009-07-12', 56, 2, 20,'n/a','/home/laura/project/case/cancer1_case0001.zip' );
insert into case_archive (case_name, id_volume, ics_version, date_case, age_patient, density, digitizer_dba, notes, zip_folder_link) values ('A-0002-1', 2, 1.0,'2007-03-12', 48, 3, 19,'n/a','/home/laura/project/case/cancer1_case0002.zip' );

/* 2 images x case*/
insert into image(id_case, image_name, image_type, link, bits_pixel, resolution, left_cc_lines, pixels_per_line, total_abnormality, abnormality) values ( 1, 'A_0002_1.LEFT_CC.LJPEG',1,'/home/laura/Arbeitsfläche/Project/case/normal1_case0001/A_0002_1.LEFT_CC.LJPEG',16,42,4349, 1979, 234, 1);
insert into image(id_case, image_name, image_type, link, bits_pixel, resolution, left_cc_lines, pixels_per_line, total_abnormality, abnormality) values ( 1, 'A_0002_1.RIGHT_CC.LJPEG',2,'/home/laura/Arbeitsfläche/Project/case/normal1_case0001/A_0002_1.RIGHT_CC.LJPEG',12,32,4229, 1959, 214, 2);
insert into image(id_case, image_name, image_type, link, bits_pixel, resolution, left_cc_lines, pixels_per_line, total_abnormality, abnormality) values ( 2, 'A_0003_1.LEFT_CC.LJPEG',1,'/home/laura/Arbeitsfläche/Project/case/normal1_case0002/A_0003_1.LEFT_CC.LJPEG',24,62,2359, 1629, 267, 1);

insert into image(id_case, image_name, image_type, link, bits_pixel, resolution, left_cc_lines, pixels_per_line, total_abnormality, abnormality) values ( 2, 'A_0003_1.RIGHT_CC.LJPEG',2,'/home/laura/Arbeitsfläche/Project/case/normal1_case0002/A_0003_1.RIGHT_CC.LJPEG',16,42,4349, 1979, 234, 1);
insert into image(id_case, image_name, image_type, link, bits_pixel, resolution, left_cc_lines, pixels_per_line, total_abnormality, abnormality) values ( 3, 'C_0001_1.LEFT_MLO.LJPEG',3,'/home/laura/Arbeitsfläche/Project/case/cancer1_case0001/C_0001_1.LEFT_MLO.LJPEG',24,46,3649, 2979, 734, 5);
insert into image(id_case, image_name, image_type, link, bits_pixel, resolution, left_cc_lines, pixels_per_line, total_abnormality, abnormality) values ( 3, 'C_0001_1.RIGHT_MLO.LJPEG',4,'/home/laura/Arbeitsfläche/Project/case/cancer1_case0001/C_0001_1.RIGHT_MLO.LJPEG',32,47,7349, 1363, 734, 1);

insert into image(id_case, image_name, image_type, link, bits_pixel, resolution, left_cc_lines, pixels_per_line, total_abnormality, abnormality) values ( 4, 'C_0001_2.LEFT_MLO.LJPEG',3,'/home/laura/Arbeitsfläche/Project/case/cancer1_case0002/C_0002_1.LEFT_CC.LJPEG',32,92,3549, 3779, 374, 1);
insert into image(id_case, image_name, image_type, link, bits_pixel, resolution, left_cc_lines, pixels_per_line, total_abnormality, abnormality) values ( 4, 'A_0001_2.LEFT_CC.LJPEG',4,'/home/laura/Arbeitsfläche/Project/case/cancer1_case0002/C_0002_1.RIGHT_CC.LJPEG',16,42,4349, 1979, 234, 1);

————————————————————————-

Then I’ve considered adding columns:

ALTER TABLE volume ADD COLUMN total_size VARCHAR(10);
ALTER TABLE case_archive ADD COLUMN size_zip_MB FLOAT NOT NULL (10);

And populate them:
UPDATE case_archive SET size_zip_MB=200.1 where id_case=1;
UPDATE case_archive SET size_zip_MB=460.2 where id_case=2;
UPDATE case_archive SET size_zip_MB=2154.5 where id_case=3;
UPDATE case_archive SET size_zip_MB=225.3 where id_case=4;

To calculate the sum of the zip files’ size of the cases for each row of the volume table  I’ve made the following procedure:

DELIMITER //
CREATE PROCEDURE volume_total_size()
BEGIN
DECLARE i int(10);
DECLARE l int(10);
SET i=0;
set l= (SELECT COUNT(*) from volume);

WHILE i<l  DO
SET i=i+1;
UPDATE volume SET total_size= (select IF(sum(case_archive.size_zip_MB)>1024.0, CONCAT(TRUNCATE(sum(case_archive.size_zip_MB)/1024,1),'GB' ),
CONCAT(sum(case_archive.size_zip_MB),'MB')) as total_size
from case_archive
where id_volume=i)
where id_volume=i;


SELECT * FROM volume;


END;

To invoke procedure type in the console:
MySQL> call volume_total_size();

You can also copy the command in a new *.sql file and launch the script.

I’ve tested the whole “project” with MySQL 5.5.

I have decided to share this because I have spent several hours trying to understand how to update the volume table with the sum of the file size.
Notice that in the ‘case_archive‘ table the column ‘size_zip_MB‘ type is INT(10) and you have to insert the size in MB, while in ‘volume‘ the ‘total_size‘ column type is VARCHAR(10). MySQL 5.5 casts the column type automatically 🙂

Backing up the Master Boot Record in Ubuntu 11.10

The Master Boot Record (MBR) is a space of 512 bytes that holds the partition table as well as the stage 1 of the boot loader.

Making a backup of the MBR might be useful in case of damage, as the operative system wouldn’t boot.

Therefore, you can make a copy in your home directory typing:

sudo dd if=/dev/sda of=~/mbr.txt count=1 bs=512

If you type:

sudo cat /dev/sda

you can see that /dev/sda is a binary file. However you can see that the backup is a file called “mbr.txt“.

If you need to restore the MBR you can use the following command:

sudo dd if=~/mbr.txt of=/dev/sda count=1 bs=512

 

We use cookies to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners.
Cookies settings
Accept
Privacy & Cookie policy
Privacy & Cookies policy
Cookie name Active

Privacy Policy

What information do we collect?

We collect information from you when you register on our site or place an order. When ordering or registering on our site, as appropriate, you may be asked to enter your: name, e-mail address or mailing address.

What do we use your information for?

Any of the information we collect from you may be used in one of the following ways: To personalize your experience (your information helps us to better respond to your individual needs) To improve our website (we continually strive to improve our website offerings based on the information and feedback we receive from you) To improve customer service (your information helps us to more effectively respond to your customer service requests and support needs) To process transactions Your information, whether public or private, will not be sold, exchanged, transferred, or given to any other company for any reason whatsoever, without your consent, other than for the express purpose of delivering the purchased product or service requested. To administer a contest, promotion, survey or other site feature To send periodic emails The email address you provide for order processing, will only be used to send you information and updates pertaining to your order.

How do we protect your information?

We implement a variety of security measures to maintain the safety of your personal information when you place an order or enter, submit, or access your personal information. We offer the use of a secure server. All supplied sensitive/credit information is transmitted via Secure Socket Layer (SSL) technology and then encrypted into our Payment gateway providers database only to be accessible by those authorized with special access rights to such systems, and are required to?keep the information confidential. After a transaction, your private information (credit cards, social security numbers, financials, etc.) will not be kept on file for more than 60 days.

Do we use cookies?

Yes (Cookies are small files that a site or its service provider transfers to your computers hard drive through your Web browser (if you allow) that enables the sites or service providers systems to recognize your browser and capture and remember certain information We use cookies to help us remember and process the items in your shopping cart, understand and save your preferences for future visits, keep track of advertisements and compile aggregate data about site traffic and site interaction so that we can offer better site experiences and tools in the future. We may contract with third-party service providers to assist us in better understanding our site visitors. These service providers are not permitted to use the information collected on our behalf except to help us conduct and improve our business. If you prefer, you can choose to have your computer warn you each time a cookie is being sent, or you can choose to turn off all cookies via your browser settings. Like most websites, if you turn your cookies off, some of our services may not function properly. However, you can still place orders by contacting customer service. Google Analytics We use Google Analytics on our sites for anonymous reporting of site usage and for advertising on the site. If you would like to opt-out of Google Analytics monitoring your behaviour on our sites please use this link (https://tools.google.com/dlpage/gaoptout/)

Do we disclose any information to outside parties?

We do not sell, trade, or otherwise transfer to outside parties your personally identifiable information. This does not include trusted third parties who assist us in operating our website, conducting our business, or servicing you, so long as those parties agree to keep this information confidential. We may also release your information when we believe release is appropriate to comply with the law, enforce our site policies, or protect ours or others rights, property, or safety. However, non-personally identifiable visitor information may be provided to other parties for marketing, advertising, or other uses.

Registration

The minimum information we need to register you is your name, email address and a password. We will ask you more questions for different services, including sales promotions. Unless we say otherwise, you have to answer all the registration questions. We may also ask some other, voluntary questions during registration for certain services (for example, professional networks) so we can gain a clearer understanding of who you are. This also allows us to personalise services for you. To assist us in our marketing, in addition to the data that you provide to us if you register, we may also obtain data from trusted third parties to help us understand what you might be interested in. This ‘profiling’ information is produced from a variety of sources, including publicly available data (such as the electoral roll) or from sources such as surveys and polls where you have given your permission for your data to be shared. You can choose not to have such data shared with the Guardian from these sources by logging into your account and changing the settings in the privacy section. After you have registered, and with your permission, we may send you emails we think may interest you. Newsletters may be personalised based on what you have been reading on theguardian.com. At any time you can decide not to receive these emails and will be able to ‘unsubscribe’. Logging in using social networking credentials If you log-in to our sites using a Facebook log-in, you are granting permission to Facebook to share your user details with us. This will include your name, email address, date of birth and location which will then be used to form a Guardian identity. You can also use your picture from Facebook as part of your profile. This will also allow us and Facebook to share your, networks, user ID and any other information you choose to share according to your Facebook account settings. If you remove the Guardian app from your Facebook settings, we will no longer have access to this information. If you log-in to our sites using a Google log-in, you grant permission to Google to share your user details with us. This will include your name, email address, date of birth, sex and location which we will then use to form a Guardian identity. You may use your picture from Google as part of your profile. This also allows us to share your networks, user ID and any other information you choose to share according to your Google account settings. If you remove the Guardian from your Google settings, we will no longer have access to this information. If you log-in to our sites using a twitter log-in, we receive your avatar (the small picture that appears next to your tweets) and twitter username.

Children’s Online Privacy Protection Act Compliance

We are in compliance with the requirements of COPPA (Childrens Online Privacy Protection Act), we do not collect any information from anyone under 13 years of age. Our website, products and services are all directed to people who are at least 13 years old or older.

Updating your personal information

We offer a ‘My details’ page (also known as Dashboard), where you can update your personal information at any time, and change your marketing preferences. You can get to this page from most pages on the site – simply click on the ‘My details’ link at the top of the screen when you are signed in.

Online Privacy Policy Only

This online privacy policy applies only to information collected through our website and not to information collected offline.

Your Consent

By using our site, you consent to our privacy policy.

Changes to our Privacy Policy

If we decide to change our privacy policy, we will post those changes on this page.
Save settings
Cookies settings