Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ArtifactsByChecksumConstraint |
|
| 1.75;1.75 |
1 | package org.apache.maven.archiva.database.constraints; | |
2 | ||
3 | /* | |
4 | * Licensed to the Apache Software Foundation (ASF) under one | |
5 | * or more contributor license agreements. See the NOTICE file | |
6 | * distributed with this work for additional information | |
7 | * regarding copyright ownership. The ASF licenses this file | |
8 | * to you under the Apache License, Version 2.0 (the | |
9 | * "License"); you may not use this file except in compliance | |
10 | * with the License. You may obtain a copy of the License at | |
11 | * | |
12 | * http://www.apache.org/licenses/LICENSE-2.0 | |
13 | * | |
14 | * Unless required by applicable law or agreed to in writing, | |
15 | * software distributed under the License is distributed on an | |
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
17 | * KIND, either express or implied. See the License for the | |
18 | * specific language governing permissions and limitations | |
19 | * under the License. | |
20 | */ | |
21 | ||
22 | import org.apache.commons.lang.StringUtils; | |
23 | import org.apache.maven.archiva.database.Constraint; | |
24 | ||
25 | /** | |
26 | * Constraint for retrieving artifacts whose sha1 or md5 checksum matches the | |
27 | * specified value. | |
28 | * | |
29 | */ | |
30 | public class ArtifactsByChecksumConstraint | |
31 | extends AbstractDeclarativeConstraint | |
32 | implements Constraint | |
33 | { | |
34 | private String whereClause; | |
35 | ||
36 | public static final String SHA1 = "SHA1"; | |
37 | ||
38 | public static final String MD5 = "MD5"; | |
39 | ||
40 | /** | |
41 | * Create constraint for checksum (without providing type) | |
42 | * | |
43 | * @param desiredChecksum the checksum (either SHA1 or MD5) | |
44 | */ | |
45 | public ArtifactsByChecksumConstraint( String desiredChecksum ) | |
46 | { | |
47 | 0 | this( desiredChecksum, null ); |
48 | 0 | } |
49 | ||
50 | /** | |
51 | * Create constraint for specific checksum. | |
52 | * | |
53 | * @param desiredChecksum the checksum (either SHA1 or MD5) | |
54 | * @param type the type of checksum (either {@link #SHA1} or {@link #MD5}) | |
55 | */ | |
56 | public ArtifactsByChecksumConstraint( String desiredChecksum, String type ) | |
57 | 0 | { |
58 | 0 | if ( StringUtils.isEmpty( type ) ) |
59 | { | |
60 | // default for no specified type. | |
61 | 0 | whereClause = "this.checksumSHA1 == desiredChecksum || this.checksumMD5 == desiredChecksum"; |
62 | } | |
63 | 0 | else if ( !type.equals( SHA1 ) && !type.equals( MD5 ) ) |
64 | { | |
65 | // default for type that isn't recognized. | |
66 | 0 | whereClause = "this.checksumSHA1 == desiredChecksum || this.checksumMD5 == desiredChecksum"; |
67 | } | |
68 | 0 | else if ( type.equals( SHA1 ) || type.equals( MD5 ) ) |
69 | { | |
70 | // specific type. | |
71 | 0 | whereClause = "this.checksum" + type.trim() + " == desiredChecksum"; |
72 | } | |
73 | ||
74 | 0 | declParams = new String[]{"String desiredChecksum"}; |
75 | 0 | params = new Object[]{desiredChecksum.toLowerCase()}; |
76 | 0 | } |
77 | ||
78 | public String getSortColumn() | |
79 | { | |
80 | 0 | return "groupId"; |
81 | } | |
82 | ||
83 | public String getWhereCondition() | |
84 | { | |
85 | 0 | return whereClause; |
86 | } | |
87 | } |