Skip to content

Commit

Permalink
feedback requested (#26493)
Browse files Browse the repository at this point in the history
* feedback requested

* #26380 fixing bug

* #26380 remove commented attributes no longer used

* #26380 changing classes to immutables

* #26380 these attribute will be moved later

* #26380 renaming the new classes
  • Loading branch information
fabrizzio-dotCMS authored and dsolistorres committed Nov 6, 2023
1 parent 2fe0e2a commit 73b1578
Show file tree
Hide file tree
Showing 23 changed files with 630 additions and 555 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.dotcms.common;

import com.dotcms.model.annotation.ValueType;
import java.io.File;
import java.nio.file.Path;
import javax.annotation.Nullable;
import org.immutables.value.Value;
import org.immutables.value.Value.Default;
import org.immutables.value.Value.Derived;

/**
* Represents the structure of a local file or directory path within the workspace.
*/
@ValueType
@Value.Immutable
public interface AbstractLocalPathStructure {
boolean isDirectory();
String status();
String language();
String site();
@Nullable
String fileName();
String folderPath();
Path filePath();
@Default
default boolean languageExists() {return false;}

@Derived
default String folderName() {

final int nameCount = filePath().getNameCount();

String folderName = File.separator;

if (nameCount > 1) {
folderName = filePath().subpath(nameCount - 1, nameCount).toString();
} else if (nameCount == 1) {
folderName = filePath().subpath(0, nameCount).toString();
}

if (folderName.equalsIgnoreCase(this.site())) {
folderName = File.separator;
}

return folderName;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.dotcms.common;

import com.dotcms.model.annotation.ValueType;
import java.nio.file.Path;
import javax.annotation.Nullable;
import org.immutables.value.Value;
import org.immutables.value.Value.Derived;

/**
* Represents the site, folder path and file name components of the parsed remote path.
*/
@ValueType
@Value.Immutable
public interface AbstractRemotePathStructure {

/**
* The site component of the parsed path.
*/
String site();

/**
* The folder path component of the parsed path.
*/
Path folderPath();

/**
* The file name component of the parsed path.
*/
@Nullable
String fileName();

@Derived
default String folderName() {

int nameCount = folderPath().getNameCount();

String folderName = "/";

if (nameCount > 1) {
folderName = folderPath().subpath(nameCount - 1, nameCount).toString();
} else if (nameCount == 1) {
folderName = folderPath().subpath(0, nameCount).toString();
}

return folderName;
}


class Builder extends RemotePathStructure.Builder {
public Builder folder(Path path) {
super.fileName(null);
super.folderPath(path);
return this;
}

public Builder asset(Path path) {
super.fileName(path.getFileName().toString());
super.folderPath(path.getParent());
return this;
}

}

static Builder builder() {
return new Builder();
}

}
Loading

0 comments on commit 73b1578

Please sign in to comment.