128
128
import org .springframework .web .multipart .MultipartFile ;
129
129
import org .springframework .web .servlet .support .ServletUriComponentsBuilder ;
130
130
import org .eclipse .sw360 .datahandler .thrift .users .RequestedAction ;
131
+ import org .eclipse .sw360 .datahandler .thrift .attachments .LicenseInfoUsage ;
132
+ import org .eclipse .sw360 .datahandler .thrift .attachments .SourcePackageUsage ;
131
133
132
134
import jakarta .servlet .http .HttpServletRequest ;
133
135
import jakarta .servlet .http .HttpServletResponse ;
136
138
import java .net .URI ;
137
139
import java .net .URISyntaxException ;
138
140
import java .time .format .DateTimeFormatter ;
139
- import java .util .ArrayList ;
140
- import java .util .Arrays ;
141
- import java .util .Collections ;
142
- import java .util .HashMap ;
143
- import java .util .HashSet ;
144
- import java .util .InvalidPropertiesFormatException ;
145
- import java .util .LinkedHashMap ;
146
- import java .util .List ;
147
- import java .util .Map ;
141
+ import java .util .*;
148
142
import java .util .Map .Entry ;
149
- import java .util .NoSuchElementException ;
150
- import java .util .Objects ;
151
- import java .util .Optional ;
152
- import java .util .Set ;
153
143
import java .util .function .Consumer ;
154
144
import java .util .function .Function ;
155
145
import java .util .function .Predicate ;
@@ -1895,6 +1885,24 @@ public ResponseEntity<?> saveAttachmentUsages(
1895
1885
}
1896
1886
}
1897
1887
1888
+ public Map <String , Integer > countMap (Collection <AttachmentType > attachmentTypes , UsageData filter , Project project , User sw360User , String id ) throws TException {
1889
+ boolean projectWithSubProjects = !project .getLinkedProjects ().isEmpty ();
1890
+ List <ProjectLink > mappedProjectLinks =
1891
+ (!SW360Constants .ENABLE_FLEXIBLE_PROJECT_RELEASE_RELATIONSHIP )
1892
+ ? projectService .createLinkedProjects (project ,
1893
+ projectService .filterAndSortAttachments (attachmentTypes ), true , sw360User )
1894
+ : projectService .createLinkedProjectsWithAllReleases (project ,
1895
+ projectService .filterAndSortAttachments (attachmentTypes ), true , sw360User );
1896
+
1897
+ if (!projectWithSubProjects ) {
1898
+ mappedProjectLinks = mappedProjectLinks .stream ()
1899
+ .filter (projectLink -> projectLink .getId ().equals (id )).collect (Collectors .toList ());
1900
+ }
1901
+
1902
+ Map <String , Integer > countMap = projectService .storeAttachmentUsageCount (mappedProjectLinks , filter );
1903
+ return countMap ;
1904
+ }
1905
+
1898
1906
@ Operation (
1899
1907
description = "Get all attachmentUsages of the projects." ,
1900
1908
tags = {"Projects" }
@@ -1962,12 +1970,27 @@ public ResponseEntity attachmentUsages(
1962
1970
}
1963
1971
}
1964
1972
1965
- List <Map <String , Object >> releaseObjMap = getReleaseObjectMapper (releaseList );
1973
+ Collection <AttachmentType > attachmentTypes ;
1974
+ UsageData type ;
1975
+ List <Map <String , Object >> releaseObjMap = new ArrayList <>();
1976
+ if ("withCliAttachment" .equalsIgnoreCase (filter )) {
1977
+ attachmentTypes = SW360Constants .LICENSE_INFO_ATTACHMENT_TYPES ;
1978
+ type = UsageData .licenseInfo (new LicenseInfoUsage (Sets .newHashSet ()));
1979
+ Map <String , Integer > count = countMap (attachmentTypes , type , sw360Project , sw360User , id );
1980
+ releaseObjMap = getReleaseObjectMapper (releaseList , count );
1981
+ } else if ("withSourceAttachment" .equalsIgnoreCase (filter )) {
1982
+ attachmentTypes = SW360Constants .SOURCE_CODE_ATTACHMENT_TYPES ;
1983
+ type = UsageData .sourcePackage (new SourcePackageUsage ());
1984
+ Map <String , Integer > count = countMap (attachmentTypes , type , sw360Project , sw360User , id );
1985
+ releaseObjMap = getReleaseObjectMapper (releaseList , count );
1986
+ } else {
1987
+ releaseObjMap = getReleaseObjectMapper (releaseList , null );
1988
+ }
1966
1989
HalResource userHalResource = attachmentUsageReleases (sw360Project , releaseObjMap , listOfAttachmentUsages );
1967
1990
return new ResponseEntity <>(userHalResource , HttpStatus .OK );
1968
1991
}
1969
1992
1970
- private List <Map <String , Object >> getReleaseObjectMapper (List <EntityModel <Release >> releaseList ) {
1993
+ private List <Map <String , Object >> getReleaseObjectMapper (List <EntityModel <Release >> releaseList , Map < String , Integer > count ) {
1971
1994
ObjectMapper oMapper = new ObjectMapper ();
1972
1995
List <Map <String , Object >> modifiedList = new ArrayList <>();
1973
1996
for (EntityModel <Release > rel : releaseList ) {
@@ -1983,6 +2006,7 @@ private List<Map<String, Object>> getReleaseObjectMapper(List<EntityModel<Releas
1983
2006
final ImmutableSet <String > fieldsToKeep = ImmutableSet .of ("name" , "version" , "componentType" , "clearingState" , ATTACHMENTS );
1984
2007
Map <String , Object > valueToKeep = new LinkedHashMap <>();
1985
2008
Link releaseLink = null ;
2009
+ Integer attachmentCount = 0 ;
1986
2010
if (relMap != null ) {
1987
2011
for (Map .Entry <String , Object > entry : relMap .entrySet ()) {
1988
2012
if (entry != null && entry .getKey ().equals ("id" )) {
@@ -2006,6 +2030,16 @@ private List<Map<String, Object>> getReleaseObjectMapper(List<EntityModel<Releas
2006
2030
map .put ("checkedTeam" , att .get ("checkedTeam" ));
2007
2031
map .put ("checkedComment" , att .get ("checkedComment" ));
2008
2032
map .put ("checkedOn" , att .get ("checkedOn" ));
2033
+ if (count != null ) {
2034
+ for (Map .Entry <String , Integer > entryMap : count .entrySet ()) {
2035
+ String key = entryMap .getKey ();
2036
+ if (key .contains ((CharSequence ) att .get ("attachmentContentId" ))) {
2037
+ attachmentCount = entryMap .getValue ();
2038
+ break ;
2039
+ }
2040
+ }
2041
+ map .put ("attachmentUsageCount" ,attachmentCount );
2042
+ }
2009
2043
attList .add (map );
2010
2044
}
2011
2045
valueToKeep .put (entry .getKey (), attList );
@@ -2078,7 +2112,7 @@ public List<Release> filterReleases(User sw360User, String filter, Set<String> r
2078
2112
final Release sw360Release = releaseService .getReleaseForUserById (relId , sw360User );
2079
2113
releaseService .setComponentDependentFieldsInRelease (sw360Release , sw360User );
2080
2114
List <Attachment > cliAttachments = sw360Release .getAttachments ().stream ()
2081
- .filter (attachment -> attachment .getAttachmentType () == AttachmentType .COMPONENT_LICENSE_INFO_XML )
2115
+ .filter (attachment -> attachment .getAttachmentType () == AttachmentType .COMPONENT_LICENSE_INFO_XML || attachment . getAttachmentType () == AttachmentType . COMPONENT_LICENSE_INFO_COMBINED )
2082
2116
.collect (Collectors .toList ());
2083
2117
Set <Attachment > cliAttachmentsSet = new HashSet <>(cliAttachments );
2084
2118
sw360Release .setAttachments (cliAttachmentsSet );
0 commit comments