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