Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#192 - Add multiple BusinessHours for a Resource #193

Merged
merged 4 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import lombok.EqualsAndHashCode;
import lombok.Getter;

import org.vaadin.stefan.fullcalendar.NotNull;
import java.util.*;

/**
Expand All @@ -35,32 +34,32 @@ public class Resource {

/**
* The id of this resource.
*
* Uniquely identifies this resource.
*
* Uniquely identifies this resource.
*/
private final String id;

/**
* The title/name of this resource.
*
*
* Text that will be displayed on the resource when it is rendered.
*/
private final String title;

/**
* The color of this resource.
*
* Events associated with this resources will have their backgrounds and borders colored.
*
* Events associated with this resources will have their backgrounds and borders colored.
*/
private final String color;

/**
* The BusinessHours of this resource.
*
* A businessHours declaration that will only apply to this resource.
* The BusinessHours array of this resource.
*
* A businessHours[] declaration that will only apply to this resource.
*/
private final BusinessHours businessHours;
private final BusinessHours[] businessHoursArray;

/**
* The childern's of the resource
*/
Expand All @@ -69,7 +68,7 @@ public class Resource {
* The parent of the current resource
*/
private Resource parent;

/**
* The custom property list
*/
Expand All @@ -93,20 +92,6 @@ public Resource(String id, String title, String color) {
this(id, title, color, null);
}

/**
* New instance. Awaits id and title. If no id is provided, one will be generated.
* <br><br>
* Adds the given resources as children using {@link #addChildren(Collection)} if a value != null is passed.
*
* @param id id
* @param title title
* @param color color (optional)
* @param children children (optional)
*/
public Resource(String id, String title, String color, Collection<Resource> children) {
this(id, title, color, children, null);
}

/**
* New instance. Awaits id and title. If no id is provided, one will be generated.
* <br><br>
Expand All @@ -118,11 +103,11 @@ public Resource(String id, String title, String color, Collection<Resource> chil
* @param children children (optional)
* @param businessHours businessHours (optional)
*/
public Resource(String id, String title, String color, Collection<Resource> children, BusinessHours businessHours) {
public Resource(String id, String title, String color, Collection<Resource> children, BusinessHours... businessHours) {
spalyukh-flex marked this conversation as resolved.
Show resolved Hide resolved
this.id = id != null ? id : UUID.randomUUID().toString();
this.title = title;
this.color = color;
this.businessHours = businessHours;
this.businessHoursArray = (businessHours != null && businessHours.length == 0) ? null : businessHours;

if (children != null) {
addChildren(children);
Expand Down Expand Up @@ -236,7 +221,7 @@ public void removeChildren(@NotNull Collection<Resource> children) {

this.children.removeAll(children);
}

/**
* Add custom element to the extendedProp HashMap. This allow to set custom property to the resource.
*
Expand All @@ -246,7 +231,7 @@ public void removeChildren(@NotNull Collection<Resource> children) {
public void addExtendedProps(@NotNull String key, @NotNull Object value) {
extendedProps.put(key, value);
}

/**
* Remove the custom property based on the name.
*
Expand All @@ -255,7 +240,7 @@ public void addExtendedProps(@NotNull String key, @NotNull Object value) {
public void removeExtendedProps(@NotNull String key) {
extendedProps.remove(key);
}

/**
* remove specific custom property where the name and value match.
*
Expand All @@ -278,10 +263,15 @@ protected JsonObject toJson() {
jsonObject.put("id", getId());
jsonObject.put("title", JsonUtils.toJsonValue(getTitle()));
jsonObject.put("eventColor", JsonUtils.toJsonValue(getColor()));

if(getBusinessHours() != null)
jsonObject.put("businessHours", getBusinessHours().toJson());


if(getBusinessHoursArray() != null && getBusinessHoursArray().length > 0) {
JsonArray businessHoursJsonArray = Json.createArray();
for(int i = 0; i < getBusinessHoursArray().length; i++) {
businessHoursJsonArray.set(i, getBusinessHoursArray()[i].toJson());
}
jsonObject.put("businessHours", businessHoursJsonArray);
}

getParent().ifPresent(parent -> jsonObject.put("parentId", parent.getId()));

Set<Resource> children = getChildren();
Expand All @@ -294,7 +284,7 @@ protected JsonObject toJson() {

jsonObject.put("children", jsonArray);
}

HashMap<String, Object> extendedProps = getExtendedProps();
if (!extendedProps.isEmpty()) {
for (Map.Entry<String, Object> prop : extendedProps.entrySet()) {
Expand Down Expand Up @@ -323,6 +313,16 @@ private void setParent(Resource parent) {
this.parent = parent;
}

/**
* Returns the first item from businessHoursArray or null if array is empty
*
* @return BusinessHours or null
*/
public BusinessHours getBusinessHours() {
if(businessHoursArray == null || businessHoursArray.length == 0) return null;

return businessHoursArray[0];
}

@Override
public String toString() {
Expand Down
1 change: 1 addition & 0 deletions demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<optional>true</optional>
<scope>provided</scope>
</dependency>
Expand Down
Loading