Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Could you please check it if it is correct or no? I have all my code as **************************************** package com.algonquin.loggy; public interface Attachable { public

Could you please check it if it is correct or no?

I have all my code as 

****************************************

package com.algonquin.loggy;

public interface Attachable {

public void attachFile(File file) throws Exception;

public boolean isValidContentType(String contentType);

void attachFile(String name, String type, String content, Long size) throws Exception;

}

************************************

package com.algonquin.loggy;

public class AudioFile extends File {

/**

*

*/

public AudioFile(String name, String type, String content, Long size) {

super(name, type, content, size);

}

/**

*

*/

@Override

public void postProcess() {

super.postProcess();

System.out.println("This audio file is going to be transcoded and then closed captioned");

}

}

*************************************

package com.algonquin.loggy;

 

import java.util.Arrays;

import java.util.Date;

import java.util.List;

 

public abstract class AudioLog extends Log {

 

    public static final List contentTypes = Arrays.asList("MP3", "WAV", "AAC");

 

    public AudioLog() {

    }

 

    public AudioLog(String name, String description) {

        super(name, description);

    }

 

    public AudioLog(String name, String description, Date date) {

        super(name, description, date);

    }

 

    @Override

    public boolean isValidContentType(String type) {

        return AudioLog.contentTypes.contains(type);

    }

 

    @Override

    public void attachFile(String name, String type, String content, Long size) throws Exception {

       System.out.println("Attaching " + name + " to " + this.getName());

        File attachment = FileFactory.createFile(type, name, content, size);

       this.setAttachment(attachment);

       attachment.postProcess();

    }

}

*********************************************

package com.algonquin.loggy;

import java.util.Date;

public class Builder {

public Builder() {}

public Builder withName(String name) {

return this;

}

public Builder withDescription(String description) {

return this;

}

public Builder withDate(Date date) {

return this;

}

Log log = Log.builder()

.withName("Log Name")

.withDescription("Log Description")

.build();

public static Builder builder() {

return new Builder();

}

private Log build() {

return null;

}

}

****************************

package com.algonquin.loggy;

public class File implements Processable {

private String name;

private String type;

private String content;

private Long size;

public File() {

}

public File(String name, String type, String content, Long size) {

this.name = name;

this.type = type;

this.content = content;

this.size = size;

}

public String getContent() {

return content;

}

public void setContent(String content) {

this.content = content;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public String getType() {

return type;

}

public void setType(String type) {

this.type = type;

}

public Long getSize() {

return size;

}

public void setSize(Long size) {

this.size = size;

}

@Override

public void postProcess() {

System.out.println("Default post processing");

}

}

************************************

package com.algonquin.loggy;

public class FileFactory {

public static File createFile(String type, String name, String content, Long size) {

if (type.equals("MP3") || type.equals("WAV") || type.equals("AAC")) {

return new AudioFile(name, type, content, size);

} elseif (type.equals("PNG") || type.equals("JPG") || type.equals("GIF") || type.equals("SVG")) {

return new ImageFile(name, type, content, size);

} else {

return new TextFile(name, type, content, size);

}

}

}

************************************

package com.algonquin.loggy;

/**

* @author jesus

*

*/

public class ImageFile extends File {

/**

* @param name

* @param type

* @param content

* @param size

*/

public ImageFile(String name, String type, String content, Long size) {

super(name, type, content, size);

}

/**

*

*/

@Override

public void postProcess() {

super.postProcess();

System.out.println("This image file is going to be described");

}

}

*********************************************

package com.algonquin.loggy;

 

import java.util.Arrays;

import java.util.List;

 

public class ImageLog extends Log {

 

    public static final List contentTypes = Arrays.asList("PNG", "JPG", "GIF", "SVG");

 

    public ImageLog() {

    }

 

    public ImageLog(String name, String description) {

        super(name, description);

    }

 

    @Override

    public boolean isValidContentType(String type) {

        return ImageLog.contentTypes.contains(type);

    }

 

                @Override

                public void attachFile(String name2, String type, String content, Long size) throws Exception {

                                // TODO Auto-generated method stub

                                

                }

}

********************************************

package com.algonquin.loggy;

 

import java.util.Date;

import java.util.Random;

import java.util.UUID;

 

public abstract class Log implements Attachable {

 

    private String name;

    private String description;

    private Date date;

    private UUID uuid;

    private String code;

    private File attachment;

 

    public File getAttachment() {

        return attachment;

    }

 

    public void setAttachment(File attachment) {

       this.attachment = attachment;

    }

 

    public void create() {

       System.out.println("Log record for " + uuid + " has been created");

    }

 

    public void read() {

       System.out.println("Log " + uuid + " name:" + name + ", description: " + description + " created on " + date);

    }

 

    public void update(String name, String description) {

       System.out.println("Log record for " + uuid + " has been updated");

        this.name = name;

       this.description = description;

    }

 

    public void delete() {

       System.out.println("Log record for " + uuid + " has been deleted");

    }

 

    public String getName() {

        return name;

    }

 

    public void setName(String name) {

        this.name = name;

    }

 

    public String getDescription() {

        return description;

    }

 

    public void setDescription(String description) {

       this.description = description;

    }

 

    public UUID getUuid() {

        return uuid;

    }

 

    public void setUuid(UUID uuid) {

        this.uuid = uuid;

    }

 

    public Date getDate() {

        return date;

    }

 

    public void setDate(Date date) {

        this.date = date;

    }

 

    public Log() {

        this.name = null;

       this.description = null;

        this.date = null;

        this.uuid = null;

        this.code = null;

    }

 

    public Log(String name) {

        this(name, "");

    }

 

    public Log(String name, String description) {

        this(name, description, new Date());

    }

 

    public Log(String name, String description, Date date) {

        this.name = name;

       this.description = description;

        this.date = date;

        this.uuid = UUID.randomUUID();

        this.code = shortCode();

    }

 

    public String toString() {

        String out = code + ":" + name + ":" + description + ":" + date;

        if (this.attachment != null) {

            out += " with attachment " + this.attachment.getName();

        }

        return out;

    }

 

    @Override

    public void attachFile(File file) throws Exception {

        if (isValidContentType(file.getType())) {

           this.attachment = file;

           System.out.println("Attaching " + file.getName() + " to " + this.getName());

            if (this.attachment instanceof Processable) {

               ((Processable) this.attachment).postProcess();

            }

        } else {

            throw new Exception("Invalid content type " + file.getType() + " for " + this.getClass().getSimpleName());

        }

    }

 

 

    @Override

    public boolean isValidContentType(String type) {

        return false;

    }

 

    private String shortCode() {

        return randomChars(3) + "-" + randomChars(3) + "-" + randomChars(3);

    }

 

    private String randomChars(int n) {

        String randomchars = "";

        String chars = "abcdefghijklmnopqrstuvwxyz1234567890";

        Random rnd = new Random();

        for (int i = 0; i < n; i++) {

           randomchars += chars.charAt(rnd.nextInt(chars.length()));

        }

        return randomchars;

    }

 

                protected static Builder builder1() {

                                // TODO Auto-generated method stub

                                return null;

                }

 

                protected static Builder builder() {

                                // TODO Auto-generated method stub

                                return null;

                }

 

                public void attachFile1(String name, String type, String content, Long size) throws Exception {

                                // TODO Auto-generated method stub

                                

                }

 

                public abstract void attachFile(String name2, String type, String content, Long size) throws Exception;

}

************************************************

package com.algonquin.loggy;

public class Main {

public static void main(String[] args) {

try {

// Mock-up logs with non-supported content type

mockLog(new ImageLog("first log", "Monday May 3, I had to wake up early"), new ImageFile("image.tif", "TIF", "******", Long.valueOf(1024)));

} catch (Exception e) {

System.out.println("Exception: " + e.getMessage() + "\n\n");

// e.printStackTrace();

}

try {

// Mock-up logs with incorrect attachment

mockLog(new TextLog("fourth log", "And even later, I need to have lunch"), new TextFile("eating.png", "PNG", "******", Long.valueOf(1024)));

} catch (Exception e) {

System.out.println("Exception: " + e.getMessage() + "\n\n");

// e.printStackTrace();

}

try {

// Mock-up logs with correct attachment

mockLog(new ImageLog("first log", "Monday May 4, I had to wake up early"), new ImageFile("image.png", "PNG", "******", Long.valueOf(1024)));

mockLog(new ImageLog("second log", "Few minutes later, I had my first cup of coffee"), new ImageFile("coffee.png", "PNG", "******", Long.valueOf(1024)));

mockLog(new VideoLog("third log", "Few minutes later, I am going for a ride"), new VideoFile("biking1.mp4", "MP4", "******", Long.valueOf(1024)));

mockLog(new TextLog("fourth log", "And even later, I need to have lunch"), new TextFile("recipie.txt", "TXT", "******", Long.valueOf(1024)));

} catch (Exception e) {

System.out.println("Exception: " + e.getMessage() + "\n\n");

// e.printStackTrace();

}

}

private static void mockLog(Log log, File file) throws Exception {

System.out.println(">>> New log (" + log.toString() + ")");

log.attachFile(file);

log.create();

System.out.println("\n");

}

}

*********************************************

package com.algonquin.loggy;

/**

* @author jesus

*

*/

public interface Processable {

public void postProcess();

}

**********************************

package com.algonquin.loggy;

public class ShortCodeGenerator {

private static ShortCodeGenerator instance = null;

private ShortCodeGenerator() {}

public static synchronized ShortCodeGenerator getInstance() {

if (instance == null) {

instance = new ShortCodeGenerator();

}

return instance;

}

public String generateShortCode() {

return null;

// generate a unique shortcode

}

}

**************************************

package com.algonquin.loggy;

/**

* @author jesus

*

*/

public class TextFile extends File {

/**

*

*/

public TextFile() {

}

/**

* @param name

* @param type

* @param content

* @param size

*/

public TextFile(String name, String type, String content, Long size) {

super(name, type, content, size);

}

/**

*

*/

@Override

public void postProcess() {

super.postProcess();

// trigger translation

System.out.println("This text file is going to be translated");

}

}

**************************************

package com.algonquin.loggy;

 

import java.util.Arrays;

import java.util.Date;

import java.util.List;

 

/**

 * @author jesus

 *

 */

public class TextLog extends Log {

 

    public static final List contentTypes = Arrays.asList("DOC", "TXT", "PDF");

 

    /**

     *

     */

    public TextLog() {

    }

 

    /**

     * @param name

     * @param description

     */

    public TextLog(String name, String description) {

        super(name, description);

    }

 

    /**

     * @param name

     * @param description

     * @param date

     */

    public TextLog(String name, String description, Date date) {

        super(name, description, date);

    }

 

    /**

     *

     */

    @Override

    public boolean isValidContentType(String type) {

        return TextLog.contentTypes.contains(type);

    }

 

                @Override

                public void attachFile(String name2, String type, String content, Long size) throws Exception {

                                // TODO Auto-generated method stub

                                

                }

 

    /**

     * @throws Exception

     *

     */

}

******************************************************

package com.algonquin.loggy;

/**

* @author jesus

*

*/

public class VideoFile extends File {

/**

* @param name

* @param type

* @param content

* @param size

*/

public VideoFile(String name, String type, String content, Long size) {

super(name, type, content, size);

}

/**

*

*/

@Override

public void postProcess() {

super.postProcess();

System.out.println("This video file is going to be closed captioned");

}

}

***************************************************

package com.algonquin.loggy;

 

import java.util.Arrays;

import java.util.Date;

import java.util.List;

 

public class VideoLog extends Log {

 

    public static final List contentTypes = Arrays.asList("MP4", "MPG", "MPEG", "M4V");

 

    /**

     *

     */

    public VideoLog() {

    }

 

    /**

     *

     */

    public VideoLog(String name, String description) {

        super(name, description);

    }

 

    /**

     *

     */

    public VideoLog(String name, String description, Date date) {

        super(name, description, date);

    }

 

    /**

     *

     */

    @Override

    public boolean isValidContentType(String type) {

        return VideoLog.contentTypes.contains(type);

    }

 

                @Override

                public void attachFile(String name2, String type, String content, Long size) throws Exception {

                                // TODO Auto-generated method stub

                                

                }

 

    /**

     * @throws Exception

     *

     */

   

}

***************************************

Step by Step Solution

There are 3 Steps involved in it

Step: 1

Your provided code is a comprehensive project with multiple classes and interfaces After thoroughly reading through it here are some corrections and observations 1 Typo in elseif The correct keyword s... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Foundations of Financial Management

Authors: Stanley Block, Geoffrey Hirt, Bartley Danielsen, Doug Short, Michael Perretta

10th Canadian edition

1259261018, 1259261015, 978-1259024979

More Books

Students also viewed these Databases questions