Skip to content

Commit

Permalink
fix: resolved merge conflict and refactored DBRepository
Browse files Browse the repository at this point in the history
  • Loading branch information
MatheaGjerde committed Mar 5, 2026
2 parents 632e8fa + ba2d6ad commit e15478f
Show file tree
Hide file tree
Showing 29 changed files with 734 additions and 62 deletions.
24 changes: 2 additions & 22 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- release/*
workflow_dispatch: # Allows manual triggering of the workflow


Expand Down Expand Up @@ -33,16 +34,6 @@ jobs:
java-version: '25'
- name: Run Tests
run: mvn clean test
- name: Upload Test Results
uses: actions/upload-artifact@v3
with:
name: surefire-reports
path: target/surefire-reports/
- name: Upload Coverage Report
uses: actions/upload-artifact@v3
with:
name: jacoco-report
path: target/jacoco/coverage-reports/jacoco.xml

package:
name: Package
Expand All @@ -62,15 +53,4 @@ jobs:
name: packaged-app
path: target/Help-Me-Help-1.0-SNAPSHOT-jar-with-dependencies.jar

deployPages:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: self-hosted
steps:
- uses: actions/checkout@v3
- name: Set up JDK
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '25'

13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*.war
*.ear
*.nar
target/

##############################
## Maven
Expand Down Expand Up @@ -37,3 +38,15 @@ out/
##############################
*.db
*.DS_Store

##############################
## VSCode
##############################
.vscode/

##############################
## Misc
##############################
.settings/*
.project
.classpath
3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

41 changes: 41 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,25 @@
<artifactId>javafx-controls</artifactId>
<version>${javafx.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-crypto -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-crypto</artifactId>
<version>7.0.2</version>
</dependency>
<!-- Source: https://mvnrepository.com/artifact/tools.jackson.core/jackson-databind -->
<dependency>
<groupId>tools.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>3.1.0</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.3.5</version>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -80,6 +99,28 @@
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.12.0</version>
</plugin>

<!-- Fat JAR plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.6.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>edu.group5.app.App</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
20 changes: 17 additions & 3 deletions src/main/java/edu/group5/app/App.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
package edu.group5.app;

import java.util.HashMap;

import edu.group5.app.control.OrgAPIWrapper;
import tools.jackson.core.type.TypeReference;
import tools.jackson.databind.ObjectMapper;

/**
* Hello world!
*/
public class App {
public static void main(String[] args) {
System.out.println("Hello World!");
}
public static void main(String[] args) throws InterruptedException {
OrgAPIWrapper orgWrap = new OrgAPIWrapper("https://app.innsamlingskontrollen.no/api/public/v1/all");
System.out.println();
System.out.println();
orgWrap.importData();
Object[] imports = orgWrap.getData();
ObjectMapper objectMapper = new ObjectMapper();
HashMap<String, Object> map = objectMapper.convertValue(imports[0], new TypeReference<HashMap<String, Object>>() {
});
System.out.println(map.get("org_number"));
}
}
54 changes: 54 additions & 0 deletions src/main/java/edu/group5/app/control/OrgAPIWrapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package edu.group5.app.control;

import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

import tools.jackson.core.exc.StreamReadException;
import tools.jackson.databind.ObjectMapper;

public class OrgAPIWrapper extends Wrapper {
private Object[] data;
private HttpClient client;
private HttpRequest request;

public OrgAPIWrapper(String urlString) {
if (urlString == null) {
throw new IllegalArgumentException("url can't be null");
} else if (urlString.isBlank()) {
throw new IllegalArgumentException("url can't be blank");
}
try {
URI uri = URI.create(urlString);
this.client = HttpClient.newHttpClient();
this.request = HttpRequest.newBuilder()
.uri(uri)
.GET()
.build();
} catch (IllegalArgumentException IAe) {
throw new IllegalArgumentException("url has to be valid");
}

}

@Override
public boolean importData() throws InterruptedException {
try {
HttpResponse<String> response = this.client.send(
this.request, HttpResponse.BodyHandlers.ofString());
this.data = new ObjectMapper().readValue(response.body(), Object[].class);
return true;
} catch (IOException IOe) {
return false;
} catch (StreamReadException e) {
throw new StreamReadException("The URL leads to a website that can't be parsed");
}
}

@Override
public Object[] getData() {
return this.data;
}
}
10 changes: 8 additions & 2 deletions src/main/java/edu/group5/app/control/Wrapper.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package edu.group5.app.control;

public class Wrapper {

abstract class Wrapper {

protected Wrapper() {
}

public abstract boolean importData() throws InterruptedException;

public abstract Object getData();
}
23 changes: 4 additions & 19 deletions src/main/java/edu/group5/app/model/DBRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,24 @@


import java.util.HashMap;
import java.util.Map;

/**
* Abstract base class for repositories that store their data
* in a database-related structure.
*
* <p>
* Extends {@link Repository} and specifies that the content
* is stored as a {@link HashMap}.
* is stored as a {@link Map}.
* </p>
*/
public abstract class DBRepository<K, V> extends Repository {
/**
* The underlying data structure containing the repository entities.
*/
protected HashMap<K, V> content;

public abstract class DBRepository<K, V> extends Repository<K, V> {
/**
* Constructs a DBRepository with the given content.
*
* @param content the HashMap used to store repository entities
*/
protected DBRepository(HashMap<K, V> content) {
protected DBRepository(Map<K, V> content) {
super(content);
this.content = content;
}

/**
* Returns the underlying HashMap containing the repository entities.
*
* @return the repository content as a HashMap
*/
@Override
public HashMap<K, V> getContent() {
return content;
}
}
17 changes: 9 additions & 8 deletions src/main/java/edu/group5/app/model/Repository.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
package edu.group5.app.model;

import java.util.Map;

/**
* Represents a repository.
*/
public abstract class Repository {
/**
* The underlying data structure that holds the repository's content.
*/
protected Object content;

public abstract class Repository<K, V> {
protected final Map<K, V> content;
/**
* Constructs a new Repository with the specified content.
*
* @param content the underlying data structure used to store entities
*/
protected Repository(Object content) {
public Repository(Map<K, V> content) {
this.content = content;
}

/**
* Gets the content of the repo
* @return content of the repo
*/
public abstract Object getContent();
public Map<K, V> getContent() {
return content;
}
}
60 changes: 58 additions & 2 deletions src/main/java/edu/group5/app/model/organization/Organization.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,61 @@
package edu.group5.app.model.organization;

public class Organization {

import java.util.Objects;

/**
* Represents an organization.
*
* <p>
* An organization is identified by an organization number, a name,
* trust status, website URL, pre-approval status, and a textual description.
*
* <p>
* Instances are validated on creation:
* <ul>
* <li>orgNumber must be non-negative</li>
* <li>name and websiteURL must not be null or blank</li>
* <li>description must not be null</li>
* </ul>
*/
public record Organization(
int orgNumber,
String name,
boolean trusted,
String websiteURL,
boolean isPreApproved,
String description) {
/**
* Creates a new organization.
*
* @param orgNumber the organization number; must be non-negative
* @param name the organization name; must not be null or blank
* @param trusted whether the organization is trusted
* @param websiteURL the organization's website URL; must not be null or
* blank
* @param isPreApproved whether the organization is pre-approved
* @param description a textual description of the organization; must not be
* null
* @throws NullPointerException if name, websiteURL or description is null
* @throws IllegalArgumentException if orgNumber is negative, or if name or
* websiteURL is blank
*/
public Organization(int orgNumber, String name, boolean trusted, String websiteURL, boolean isPreApproved,
String description) {
if (orgNumber < 0) {
throw new IllegalArgumentException("orgNumber cannot be negative");
}
this.orgNumber = orgNumber;
this.name = Objects.requireNonNull(name, "name cannot be null");
this.trusted = trusted;
this.websiteURL = Objects.requireNonNull(websiteURL, "websiteURL cannot be null");
this.isPreApproved = isPreApproved;
this.description = Objects.requireNonNull(description, "description cannot be null");

if (name.isBlank()) {
throw new IllegalArgumentException("name cannot be blank");
}
if (websiteURL.isBlank()) {
throw new IllegalArgumentException("websiteURL cannot be blank");
}
}
}
Loading

0 comments on commit e15478f

Please sign in to comment.