Frankly, it's a lot of work so be patient. You also can't do everything at the same time and you will make mistakes and change your mind from time to time.
So more reason to be patient while you work on things. Just look back from time to time and observe the improvements.
Thank your for your reply.
What do you mean by abstracting json?
How can one abstract json?
I thought json was a simple plain data to move back and forward?
And how can you abstract APIs like Google drive? And should I be worried about it?
library.findAlbumByName("holidays").attachDocument(attachment);
interface PhotoAlbumLibrary {
PhotoAlbum findAlbumByName(String name);
}
// This holds businessy stuff but attachDocument remains abstracts because you'd implement it with Google Drive below.
abstract class PhotoAlbum {
abstract void attachDocument(InputStream attachment);
}
// The code below would exist in a different module which you'd link dynamically at runtime.
class GoogleDrivePhotoAlbum extends PhotoAlbum {
void attachDocument(InputStream attachment) {
// use google drive API to stream the attachment into the right place
}
}
public static File createFile(Photo photo, DocumentTypes documentType) { System.out.println("CREATING FILE"); try {
File body = new File(); body.setTitle("Document for " + photo.getPerson_name() + " - PersonID " + photo.getPerson_id() + " - " + ".docx");
body.setMimeType(GOOGLE_DOCOCUMENT_MIME_TYPE); body.setEditable(true);
Permission owsership = getOwnerShipPermission(); Permission unlockedFile = getUnlockedFilePermission(); java.io.File fileContent = null; switch (reportType) { case DOCUMENT_type1: //create document break; case DOCUMENT_type2://create document
break;
}
FileContent mediaContent = new FileContent(MS_WORD_DOCOCUMENT_MIME_TYPE, fileContent); File file = driveservice.files().insert(body, mediaContent).execute(); String fildid = file.getId(); //driveservice.permissions().insert(fildid, owsership).execute(); driveservice.permissions().insert(fildid, unlockedFile).execute(); fileContent.delete(); return file;
} catch (IOException ex) { ex.printStackTrace(); return null; } }