All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sippnex.fileblade.entities.FilebladeItem Maven / Gradle / Ivy

There is a newer version: 1.0.0
Show newest version
package com.sippnex.fileblade.entities;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

@Entity
public abstract class FilebladeItem {

    @Id
    @GeneratedValue
    private Long id;

    private String name;

    @ManyToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "parent_directory_id")
    private Directory parentDirectory;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Directory getParentDirectory() {
        return parentDirectory;
    }

    public void setParentDirectory(Directory parentDirectory) {
        this.parentDirectory = parentDirectory;
    }

    public String getPath() {
        List pathElements = new ArrayList<>();
        pathElements.add(this.getName());
        Directory nextParentDirectory = this.getParentDirectory();
        while(nextParentDirectory != null) {
            pathElements.add(nextParentDirectory.getName());
            nextParentDirectory = nextParentDirectory.getParentDirectory();
        }
        String path = "";
        for(int i=pathElements.size() - 1; i>=0; i--) {
            path += "/" + pathElements.get(i);
        }
        return path;
    }

    public FilebladeItem(String name, Directory parentDirectory) {
        this.name = name;
        this.parentDirectory = parentDirectory;
    }

    public FilebladeItem(String name) {
        this.name = name;
    }

    public FilebladeItem() {

    }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy