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

com.github.saphyra.randwo.label.service.view.LabelViewConverter Maven / Gradle / Ivy

There is a newer version: 1.1.0
Show newest version
package com.github.saphyra.randwo.label.service.view;

import org.springframework.stereotype.Component;

import com.github.saphyra.randwo.label.domain.Label;
import com.github.saphyra.randwo.label.domain.LabelView;
import com.github.saphyra.randwo.mapping.itemlabel.repository.ItemLabelMappingDao;
import lombok.RequiredArgsConstructor;

@Component
@RequiredArgsConstructor
class LabelViewConverter {
    private final ItemLabelMappingDao itemLabelMappingDao;

    LabelView convert(Label label) {
        return LabelView.builder()
            .labelId(label.getLabelId())
            .labelValue(label.getLabelValue())
            .items(itemLabelMappingDao.getByLabelId(label.getLabelId()).size())
            .deletable(isDeletable(label))
            .build();
    }

    private boolean isDeletable(Label label) {
        return itemLabelMappingDao.getByLabelId(label.getLabelId()).stream()
            .noneMatch(itemLabelMapping -> itemLabelMappingDao.getByItemId(itemLabelMapping.getItemId()).size() == 1);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy