Skip to content

Commit

Permalink
data layer done and functional [test inside the Files.java]. Handle e…
Browse files Browse the repository at this point in the history
…xceptions and NULL values. Refactoring needed.
  • Loading branch information
mandros1 committed Apr 15, 2018
1 parent d83b6df commit 5ff715a
Show file tree
Hide file tree
Showing 8 changed files with 467 additions and 107 deletions.
134 changes: 72 additions & 62 deletions Ps3Preservation/src/ps3preservation/data/Files.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* and open the template in the editor.
*/
package ps3preservation.data;

import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.ArrayList;

/**
*
Expand All @@ -19,42 +19,68 @@ public class Files extends GenericDataClass {
private byte[] hash; //not null
private int sector_offset; //default null
private int size; //not null
private static final String[] COLUMN_NAMES = { "file_id", "hash", "id", "sector_offset", "size"};
private static final String[] COLUMN_NAMES = {"file_id", "hash", "id", "sector_offset", "size"};

public static void main(String[] args) {

Files ff = new Files(3, "123", "342".getBytes(), 3);
ff.populateAttributeList();
ArrayList<String> attrList = ff.attributeListGetter();
String[] attNames = ff.attributeNamesGetter();
for(int i=0; i<attrList.size(); i++){
for (int i = 0; i < attrList.size(); i++) {
System.out.println(attNames[i] + ": " + attrList.get(i));
}

System.out.println();

Licenses lic = new Licenses(3, "newLicense", "344".getBytes(), 45);
attrList = lic.attributeListGetter();
attNames = lic.attributeNamesGetter();
attrList = lic.attributeListGetter();
attNames = lic.attributeNamesGetter();
for (int i = 0; i < attrList.size(); i++) {
System.out.println(attNames[i] + ": " + attrList.get(i));
}

System.out.println();
PackageFileXref gg = new PackageFileXref(14, 155, 42);
attrList = gg.attributeListGetter();
attNames = gg.attributeNamesGetter();
for (int i = 0; i < attrList.size(); i++) {
System.out.println(attNames[i] + ": " + attrList.get(i));
}

System.out.println();
ReleasePackageXref gg1 = new ReleasePackageXref(412, 333, 3232);
attrList = gg1.attributeListGetter();
attNames = gg1.attributeNamesGetter();
for (int i = 0; i < attrList.size(); i++) {
System.out.println(attNames[i] + ": " + attrList.get(i));
}

System.out.println();
Software gg2 = new Software(412, "Edin Dzeko");
attrList = gg2.attributeListGetter();
attNames = gg2.attributeNamesGetter();
for(int i=0; i<attrList.size(); i++){
System.out.println(attNames[i] + ": " + attrList.get(i));
}

System.out.println();
PackageFileXref gg = new PackageFileXref(14, 155, 42);
attrList = gg.attributeListGetter();
attNames = gg.attributeNamesGetter();
Releases gg3 = new Releases("1211", 556, "alive");
attrList = gg3.attributeListGetter();
attNames = gg3.attributeNamesGetter();
for(int i=0; i<attrList.size(); i++){
System.out.println(attNames[i] + ": " + attrList.get(i));
}

System.out.println();
PackageLicenseXref gg1 = new PackageLicenseXref();
attrList = gg1.attributeListGetter();
attNames = gg1.attributeNamesGetter();
byte bb = Byte.valueOf(""+ 2);
Packages gg4 = new Packages(9, "Name", "FileName", "URL", "ISO", "DEBUG", "UPDATE", 5.2, 4.3, 4, "324".getBytes(), 33, bb);
attrList = gg4.attributeListGetter();
attNames = gg4.attributeNamesGetter();
for(int i=0; i<attrList.size(); i++){
System.out.println(attNames[i] + ": " + attrList.get(i));
}

}

/**
Expand Down Expand Up @@ -91,9 +117,8 @@ public Files(int id, String file_id, byte[] hash, int size) {
this.size = size;
super.populateAttributeList();
}


@Override
@Override
public String[] attributeNamesGetter() {
return COLUMN_NAMES;
}
Expand All @@ -105,26 +130,10 @@ public String tableNameGetter() {

@Override
public void setAllTheAttributes(ArrayList<ArrayList<String>> array) {
try {
for (int i = 0; i <= array.get(0).size(); i++) {
switch (i) {
case 0:
setFile_id(array.get(0).get(i));
break;
case 1:
setHash((array.get(0).get(i)).getBytes(Charset.forName("UTF-8")));
break;
case 3:
setSector_offset(Integer.getInteger(array.get(0).get(i)));
break;
case 4:
setSize(Integer.getInteger(array.get(0).get(i)));
break;
}
}
} catch (NullPointerException npe) {
npe.printStackTrace();
}
setFile_id(array.get(0).get(0));
setHash((array.get(0).get(1)).getBytes(Charset.forName("UTF-8")));
setSector_offset(Integer.getInteger(array.get(0).get(3)));
setSize(Integer.getInteger(array.get(0).get(4)));
}

@Override
Expand All @@ -139,79 +148,80 @@ public String primaryKeyValueGetter() {

/**
* Returns the id of the Files object in the form of the integer
*
* @return integer value of the id
*/
public int getId() {
return id;
}

/**
*
* @return
*
* @return
*/
public String getFile_id() {
return file_id;
}

/**
*
* @return
*
* @return
*/
public byte[] getHash() {
return hash;
}

/**
*
* @return
*
* @return
*/
public int getSector_offset() {
return sector_offset;
}

/**
*
* @return
*
* @return
*/
public int getSize() {
return size;
}

/**
*
* @param id
*
* @param id
*/
public void setId(int id) {
this.id = id;
}

/**
*
* @param file_id
*
* @param file_id
*/
public void setFile_id(String file_id) {
this.file_id = file_id;
}

/**
*
* @param hash
*
* @param hash
*/
public void setHash(byte[] hash) {
this.hash = hash;
}

/**
*
* @param sector_offset
*
* @param sector_offset
*/
public void setSector_offset(int sector_offset) {
this.sector_offset = sector_offset;
}

/**
*
* @param size
*
* @param size
*/
public void setSize(int size) {
this.size = size;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,12 @@ public void populateAttributeList(){
for(PropertyDescriptor propertyDescriptor :
Introspector.getBeanInfo(this.getClass()).getPropertyDescriptors()){
if( propertyDescriptor.getReadMethod() != null && !propertyDescriptor.getName().equals("class")){
Object obj = propertyDescriptor.getReadMethod().invoke(this); // calls the getMethod (whichever)
Object obj = propertyDescriptor.getReadMethod().invoke(this); // calls the getMethod (whichever)
// depending on the return type it is casted to String and added to the ArrayList<String> attributeList
if( obj instanceof Integer ){
attributeList.add(Integer.toString((Integer)obj));
}else if( obj instanceof Byte ){
attributeList.add(""+obj);
}else if( obj instanceof Double ){
attributeList.add(Double.toString((Double)obj));
}else if( obj instanceof byte[] ){
Expand Down
31 changes: 8 additions & 23 deletions Ps3Preservation/src/ps3preservation/data/Licenses.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

/**
*
* @author Marin Andros, Paolo Stojic, Roberto Anic Banic, Matea Cvijanovic, Donat Avdijaj
* @author Marin Andros, Paolo Stojic, Roberto Anic Banic, Matea Cvijanovic,
* Donat Avdijaj
*/
public class Licenses extends GenericDataClass {

Expand Down Expand Up @@ -38,27 +39,11 @@ public Licenses(int id, String name, byte[] data, int user_id) {

@Override
public void setAllTheAttributes(ArrayList<ArrayList<String>> array) {
try {
for (int i = 0; i <= array.get(0).size(); i++) {
switch (i) {
case 0:
setData((array.get(0).get(i)).getBytes(Charset.forName("UTF-8")));
break;
case 1:
setId(Integer.parseInt((array.get(0).get(i))));
break;
case 3:
setName((array.get(0).get(i)));
break;
case 4:
setUser_id(Integer.parseInt((array.get(0).get(i))));
break;
}
}
} catch (NullPointerException npe) {
//TODO: implement proper exception catching block
npe.printStackTrace();
}
setData((array.get(0).get(0)).getBytes(Charset.forName("UTF-8")));
setId(Integer.parseInt((array.get(0).get(1))));
setName((array.get(0).get(3)));
setUser_id(Integer.parseInt((array.get(0).get(4))));

}

@Override
Expand All @@ -84,7 +69,7 @@ public String tableNameGetter() {
public int getId() {
return id;
}

public String getName() {
return name;
}
Expand Down
Loading

0 comments on commit 5ff715a

Please sign in to comment.